0% found this document useful (0 votes)
53 views20 pages

Contest Problems Mock ICPC 2025 IIITU

The document outlines various programming challenges faced by students at IIIT Una, including tracking student betting balances, forming coding teams with specific GCD requirements, calculating synergy using bitwise operations, and reducing arrays to a single value through MEX operations. Each challenge presents specific input and output formats, constraints, and examples to illustrate the requirements. The tasks range from mathematical computations to algorithmic problem-solving, emphasizing the need for efficient solutions.

Uploaded by

tanwaramit295
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views20 pages

Contest Problems Mock ICPC 2025 IIITU

The document outlines various programming challenges faced by students at IIIT Una, including tracking student betting balances, forming coding teams with specific GCD requirements, calculating synergy using bitwise operations, and reducing arrays to a single value through MEX operations. Each challenge presents specific input and output formats, constraints, and examples to illustrate the requirements. The tasks range from mathematical computations to algorithmic problem-solving, emphasizing the need for efficient solutions.

Uploaded by

tanwaramit295
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

A.

Stake Survivors

Background
At IIIT Una, students have discovered a “revolutionary” way to become financially independent:
flipping bets on Stake. Between lectures and midnight Maggi breaks, the grind never stops.
There are n students, and each student has an account with some initial amount of money. The
balances are stored in an array a[1..n].
Now, these students often wager an amount x on Stake. Depending on their luck, their account
balance increases or decreases by x.
But this consistent streak of winners has caught Stake’s eye. Stake has now hired you to design
a tracking system to monitor the accounts.

Your Task
You need to support two types of queries:

ˆ 1 id x — The student with index id wagers amount x. You must update their balance to
either a[id] + x or a[id] − x.

ˆ 2 l r — Report the index of the student in the range [l, r] (1-based) who currently has the
highest balance. If multiple students have the same balance, return the smallest index among
them.

Input Format
ˆ First line: Integer n — number of students (1 ≤ n ≤ 105 )

ˆ Second line: n space-separated integers a1 , a2 , . . . , an — initial balances (−109 ≤ ai ≤ 109 )

ˆ Third line: Integer q — number of queries (1 ≤ q ≤ 105 )

ˆ Next q lines: Each line is either:

– 1 id x — Wager event (1 ≤ id ≤ n, −109 ≤ x ≤ 109 )


– 2 l r — Query for maximum balance in range (1 ≤ l ≤ r ≤ n)

1
Output Format
For each query of type 2 l r, print one line containing the 1-based index of the student with the
highest balance in that range.

Sample Input
5
5 1 3 7 4
6
2 1 5
1 3 4
2 1 5
1 5 -10
2 4 5
2 1 3

Sample Output
4
3
4
3

Notes
ˆ After query 2 1 5, the max balance is 7 at index 4.

ˆ After query 1 3 4, student 3’s balance becomes 7.

ˆ Now both index 3 and 4 have 7; smallest index is 3.

ˆ Query 1 5 -10 reduces student 5’s balance from 4 to -6.

ˆ Final query checks index 1 to 3; max is 7 at index 3 (since student 4 is outside the range).

Track the balances. Outsmart Stake. Secure the bag.

2
B. ICPC Team Selection

Synchronized Champions
In preparation for the upcoming ICPC, the college director is forming elite coding teams. Each
student has a coding rating — a positive integer representing their skill level.
To ensure perfect team synchronization, there’s a strict rule:
The GCD of the three selected students’ ratings must be exactly equal to x.
Your task is to help the director calculate how many distinct teams of three can be formed such
that this condition holds.

Input Format
ˆ First line: Integer t — number of test cases (1 ≤ t ≤ 104 )

ˆ For each test case:

– Line 1: Two integers n and x — number of students and required GCD (3 ≤ n ≤ 105 ,
1 ≤ x ≤ 105 )
– Line 2: n integers a1 , a2 , ..., an — ratings of the students (1 ≤ ai ≤ 105 )

Guarantee: The total sum of all n across test cases does not exceed 105 .

Output Format
ˆ For each test case, output a single integer — the number of valid triplets (i, j, k) such that
i < j < k and gcd(ai , aj , ak ) = x.

Example

Explanation
ˆ Test Case 1: All ratings are divisible by 2. So, every combination of 3 students satisfies the
GCD requirement. There are 53 = 10 valid triplets.


ˆ Test Case 2: Only 4 students (3, 6, 9, 12) are divisible by 3. Hence, 43 = 4 valid teams.


Students with ratings 5 and 7 are excluded.

3
Input Output
2 10
52
2 4 6 8 10
63 4
3 6 9 12 7 5

Technical Constraints
ˆ Time Limit: 2 seconds

ˆ Memory Limit: 256 megabytes

Only perfectly synchronized teams will lead us to ICPC glory!

4
C. Math Again

Problem Statement
At IIIT Una, students are obsessed with bitwise operations. One day, during a late-night coding
jam in the hostel lounge, Ashwini Malviya Sir posed an interesting problem to the Competitive
Programming Club:

“Given a list of bitwise warriors and their strengths, calculate the overall synergy between
every pair of them using only the power of bitwise OR!”

The synergy between two students with strengths X and Y is defined as:
 
X +Y
f (X, Y ) =
X|Y

where X | Y denotes the bitwise OR of X and Y .


Given an array A of N students, compute the total synergy across all pairs (i, j) such that
1 ≤ i < j ≤ N:
N X
X N
f (Ai , Aj )
i=1 j=i+1

Input Format
ˆ The first line contains an integer T (1 ≤ T ≤ 104 ) — the number of test cases.

ˆ Each test case contains:

– An integer N (2 ≤ N ≤ 2 · 105 ) — the number of students.


– A line with N integers A1 , A2 , . . . , AN (1 ≤ Ai < 230 ), each having at most 4 bits set in
their binary representation.

Output Format
For each test case, output a single integer — the total sum of f (Ai , Aj ) over all valid pairs in the
array.

5
Constraints
ˆ Each number Ai can be expressed as 2x1 +2x2 +. . .+2xL , where L ≤ 4 and xi are non-negative
integers.

ˆ The sum of all N across all test cases does not exceed 2 · 105 .

Sample Input
2
2
1 2
3
1 1 1

Sample Output
1
6

Explanation
l m
ˆ Test Case 1: Only one pair (1, 2). f (1, 2) = 1+2
3
1|2 = 3 =1

ˆ Test Case 2: Three pairs of (1, 1), each has f (1, 1) =


2
1 = 2. Total sum = 3 × 2 = 6

6
D. Maggi ke Saath MEX Masala

Background
At IIIT Una, Satendra Sir is running a weird experiment in the physics lab. He wants to test a
new concept of “MEX particles,” and has asked the hostel students to participate.
Each student is given a strip of energy particles represented by an array a of length n (n ≥ 4),
where each element is a non-negative integer. Satendra Sir defines the MEX value of a sub-strip
as the smallest non-negative integer not present in that sub-strip.
Now, the students must reduce the entire strip to just one particle, by repeatedly performing
this experiment:

Select two indices l < r, and replace the sub-strip [al , ..., ar ] with a single particle having
value mex([al , ..., ar ]).

Every time they do this, the strip shrinks by (r − l) particles.


The final goal? Make the last remaining particle equal to 0.
You’re not required to give the sequence of experiments—just tell Satendra Sir the minimum
number of operations required to end up with a single particle of value 0.

Input Format
ˆ First line: Integer t — number of test cases (1 ≤ t ≤ 1000)
ˆ For each test case:
– Line 1: Integer n (4 ≤ n ≤ 5000)
– Line 2: n space-separated integers a1 , a2 , . . . , an where 0 ≤ ai ≤ n

ˆ It is guaranteed that the total sum of n over all test cases does not exceed 5000.
Output Format
ˆ For each test case, output a single integer — the minimum number of operations to reduce
the array to a single 0.

7
Sample Input
2
5
1 0 2 3 1
6
0 1 2 3 4 5

Sample Output
2
2

Note
In the first test case, a possible sequence of operations can be:

ˆ Take subarray [1, 0, 2]  mex = 3


ˆ Take subarray [3, 3, 1]  mex = 0
Total operations: 2.

Can you help Satendra Sir complete his MEX experiment before midnight Maggi?

8
E. Relatively Friendly

Background
At IIIT Una, Shivdutt Sir is organizing a coding treasure hunt in the hostel. There are p rooms
arranged in a circle, numbered from 1 to p, and as always, p is a prime number — because Shivdutt
Sir loves primes (and algorithms).
You are currently in room p. The rule is simple: you can only talk to those people whose room
number shares no common divisors with yours — in other words, those whose room number is
coprime with p.
Shivdutt Sir now asks you:

How many rooms can you visit where the room number is coprime with p?

Input Format
ˆ A single prime number p (2 ≤ p ≤ 1e18)

Output Format
ˆ Print a single integer — the number of room numbers from 1 to p − 1 that are coprime with
p.

Sample Input
7

Sample Output
6

Stay relatively friendly. Stay relatively prime.

9
F. Only Fence

Problem Description
Priyanka Ares has a string s of length N , representing the colors of a fence, in which each character
represents a color, either red (represented by R) or blue (represented by B).

She also has an array D of length N , where each element is a non-negative integer.

In one move, Priyanka can select an index i between 1 and N and spill the color s[i] from index
i + 1 to i + D[i] (both inclusive). That is, the characters at indices i + 1, i + 2, ...i + D[i] are all set
to s[i] if D[i] > 0

Priyanka wants to make the entire string Red in color. That is, all characters in s should be equal
to R.

Since you are her only fan, help her find the minimum number of moves to do so. If it is impossible,
print -1.

Input Format
ˆ The first line contains an integer T (1 ≤ T ≤ 2500), the number of test cases.

ˆ Then, T lines follow,:

– The first line contains an integer N (1 ≤ N ≤ 1000000)


– The second line contains string s, containing N characters.
– The third line contains N space-separated integers, D[1], D[2], D[3], ...D[N ]. (0 ≤ D[i] ≤
N − i, for all 1 ≤ i ≤ N )

Output Format
For each test case, output a single integer — the minimum number of moves required to make the
entire string Red in color. If it is impossible , print -1.

11
Technical Constraints
ˆ Time Limit: 2 seconds

ˆ Memory Limit: 256 megabytes

Sample Testcase

Input Output
2
10 3
RRBBBRBBRB
2305321010
3 -1
BBB
210

Explanation: In the first test case, Priyanka can choose index 2 to paint indices 3, 4 and 5. Then
she can choose index 6 to paint indices 7 and 8. Then, finally she can choose index 9 to paint index
10.
In the second test case, since there are no R paint so print -1.

I love Only Fence

12
G. Gene Sequence Editing

The Great Mutation Crisis


Last monsoon season, IIIT Una’s agricultural research station observed alarming changes:

ˆ Unprecedented floods damaged 80% of experimental crops


ˆ Surviving plants showed mutations losing drought-resistance traits
ˆ Traditional ATGC gene-editing proved inadequate against rapid climate shifts
Breakthrough and Challenge
Dr. Madan Verma from the School of Basic Sciences pioneered a radical solution:

ˆ Full-alphabet gene sequences (26 letters) for complex trait encoding


ˆ New discovery: Plant shows trait X iff corresponding sequence exists as subsequence
ˆ Critical flaw: Some sequences cause catastrophic mutations (e.g., ”drought” subsequence
 total crop failure)

”We need survival traits encoded, but the ’floodvulnerable’ sequence must be excluded!”
- Dr. Madan Verma’s urgent memo to School of Computing

13
Problem Statement: Race Against Time
Help IIIT Una researchers save the harvest by finding:
ˆ A gene sequence containing all required trait subsequences
ˆ Excluding deadly mutation sequences
Input Format
ˆ Line 1: T , the total number of test cases (1 ≤ T ≤ 2 × 10 ) 4

ˆ Each of the next T test cases contains:


– An integer K — number of traits needed (1 ≤ K ≤ 2 × 105 )
– Next K lines: Trait sequences s1 , s2 , . . . , sK (each consisting of only lowercase English
letters). The total length of all si across all test cases is at most 2 × 105 .
– Last line: A string t — the deadly mutation sequence (lowercase English letters only)

Output Format
ˆ YES followed by the solution sequence, or NO if impossible
ˆ Critical: Solution length ≤ 1,000,000 to meet synthesis deadlines
Real-World Examples

Input Output
2
6 YES
droughtresist bcdprsaerlnopsiktudgiotaghlmelmrtioruaenswmnstchiest
pestimmun YES
rapidgrowth monsoonadaptheatresist
saltolerance
bank
capitalism
floodvulnerable
2
monsoonadapt
heatresist
collapse

Technical Notes
ˆ Time Limit: 2s (C++), 4s (Python) - matches gene simulation constraints
ˆ Memory Limit: 256MB - same as IIIT’s gene sequencer capacity
The future of sustainable agriculture depends on your code!

14
H. Why Physics

The Resistor Challenge


At IIIT Una, students were casually experimenting in the electronics lab when suddenly, Professor
Satendra Sir stormed in, bursting with energy and ideas.

“Students! Who needs sorcery when we have resistors?!”

He threw down the gauntlet:


“Give me any rational resistance — I’ll build it using only 1-ohm resistors with
series and parallel magic!”
Now it’s your turn to prove your mastery of circuits. Given a target resistance in the form of a
P
fraction Q , construct it using the fewest number of 1 resistors, using only the allowed operations.

Allowed Operations
You may start from scratch and perform only the following two operations. Each operation adds
one new 1 resistor to the setup:

ˆ Series: Combine a 1 resistor with an existing resistance Re in series:


R = Re + 1

ˆ Parallel: Combine a 1 resistor in parallel with an existing resistance Re :


1 1 Re
= +1 ⇒ R=
R Re Re + 1

You begin with nothing, and must build up using one 1 resistor at a time. Your goal is to construct
P
an exact resistance of Q .

Input Format
ˆ A single line with two integers P and Q — the target resistance (1 ≤ P, Q ≤ 1018 )
ˆ P and Q are coprime integers

15
Output Format
ˆ Print one integer — the minimum number of 1 resistors needed to construct the resistance
P
Q.

Examples

Input Output
23 3
53 4

Technical Notes
ˆ You may use each 1 resistor exactly once.

ˆ You can combine elements that were already built using previous combinations.

ˆ The final element should be exactly equal to P


Q ohms.

16
I. Thala for a Reason
(Author is a CSK fan)

Problem Description
IPL* is going on, and Thala is on strike and has scored x runs as of now. Knowing that CSK has
already lost, Thala decided to score as many runs as he can from there on to satisfy his fans.
Knowing that y overs and z balls of legal deliveries have already been played by CSK batsmen, you
have to tell the maximum runs Thala can score from this point onwards.
Assume that there are no extras and all deliveries are fair after this point.

*IPL is a 20-overs cricket tournament where each over has 6 balls. A player can legally hit 1, 2, 3,
4, and 6 runs on a ball. If a player hits 1 or 3 runs or the over finishes, the strike changes.

Input Format
ˆ The first line contains an integer T (1 ≤ T ≤ 100000), the number of test cases.

ˆ Then, T lines follow, each containing three space-separated integers:

– x — Thala’s current score (0 ≤ x ≤ 1000)


– y — The number of overs completed (0 ≤ y ≤ 20)
– z — The number of balls completed in the current over (0 ≤ z ≤ 5)

Note: All combinations of y and z are valid.

Output Format
For each test case, output a single integer — the maximum number of runs Thala can hit in this
inning from the current position.

Technical Constraints
ˆ Time Limit: 2 seconds

ˆ Memory Limit: 256 megabytes

17
Sample Testcase

Input Output
1 7
1 19 5

Explanation: In this case, 19 overs and 5 balls have been played and Thala has scored 1 run.
Now, on the last ball of the innings, Thala will hit a six, making his total score 7!

Thala for a reason!

18
J. Odd Hostel Bond

The Bonding Night Challenge


In College Una, every student resides in one of the three legendary hostels: Chitagni, Bhutagni,
or Jhatragni.
Each student is uniquely identified by a roll number — a positive integer. The bond strength
between two students is measured by the greatest common divisor (GCD) of their roll numbers.
For the upcoming Hostel Bonding Night, the administration has a quirky rule:

Only pairs of students with an odd bond strength (odd GCD) may be considered truly bonded.

Your mission is to help compute the total number of such eligible student pairs.

Input Format
ˆ Line 1:t no of test cases (1 ≤ t ≤ 2 · 104 ).

ˆ Line 2: Integer n — the number of students (2 ≤ n ≤ 2 · 105 )

ˆ Line 3: n space-separated integers a1 , a2 , . . . , an — roll numbers of the students (1 ≤ ai ≤ 109 )

ˆ It is guaranteed that the sum of n over all testcases is less than 2 · 105

Output Format
ˆ Output a single integer — the number of unordered pairs (i, j) with 1 ≤ i < j ≤ n such that
gcd(ai , aj ) is odd.

Example

Input Output
1 3
3
135

19
Explanation
For test case 1 we can make pairs (1, 3), (1, 5), (3, 5) with odd Gcd.

Technical Constraints
ˆ Time Limit: 2 seconds

ˆ Memory Limit: 256 megabytes

Odd bonds make the strongest hostel friendships!

20

You might also like