Contest Problems Mock ICPC 2025 IIITU
Contest Problems Mock ICPC 2025 IIITU
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 )
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.
Final query checks index 1 to 3; max is 7 at index 3 (since student 4 is outside the range).
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 )
– 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.
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
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
Input Format
The first line contains an integer T (1 ≤ T ≤ 104 ) — the number of test cases.
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
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 ]).
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:
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
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.
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
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.
12
G. Gene Sequence Editing
”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
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
Allowed Operations
You may start from scratch and perform only the following two operations. Each operation adds
one new 1 resistor to the setup:
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.
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.
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
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!
18
J. Odd Hostel Bond
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 ).
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
20