[CODING] PermutationForces solution codeforces

[CODING] PermutationForces solution codeforces   You have a binary string 𝑎a of length 𝑛n consisting only of digits 00 and 11. You are given 𝑞q queries. In the 𝑖i-th query, you are given two indices 𝑙l and 𝑟r such that 1≤𝑙≤𝑟≤𝑛1≤l≤r≤n. Let 𝑠=𝑎[𝑙,𝑟]s=a[l,r]. You are allowed to do the following operation on 𝑠s: Choose two indices 𝑥x and 𝑦y such that 1≤𝑥≤𝑦≤|𝑠|1≤x≤y≤|s|. Let 𝑡t be the substring 𝑡=𝑠[𝑥,𝑦]t=s[x,y]. Then for all 1≤𝑖≤|𝑡|−11≤i≤|t|−1, the condition 𝑡𝑖≠𝑡𝑖+1ti≠ti+1 has to hold. Note that 𝑥=𝑦x=y is always a … Read more

ASeDatAb solution codejam

ASeDatAb solution codejam   Problem A research consortium has been looking for the best possible database for three years, but they are still having problems. The database stores values as records that hold 88-bit binary strings. Unfortunately, their implementation of the function to set the value of a record is flawed. Each record of the database … Read more

Controlled Inflation solution codejam

Controlled Inflation solution codejam   Problem Pancakes are normally served in stacks, but the Infinite House of Pancakes embraces change! The restaurant’s new advertising hook is to serve the pancakes from a deque, or double-ended queue. You are a server at the restaurant, and your job is to serve every pancake in the deque. Customers … Read more

Pancake Deque solution codejam

  Problem Pancake Deque solution codejam The lines at the air pump at your gas station are getting too long! You want to optimize the process to help customers more quickly inflate their tires, sports balls, giant parade balloon animals, and other products. The pump is automatic: you set the pressure to a specific number … Read more

PermutationForces solution codeforces

PermutationForces solution codeforces   You have a permutation pp of integers from 11 to nn. You have a strength of ss and will perform the following operation some times: Choose an index ii such that 1≤i≤|p|1≤i≤|p| and |i−pi|≤s|i−pi|≤s. For all jj such that 1≤j≤|p|1≤j≤|p| and pi<pjpi<pj, update pjpj to pj−1pj−1. Delete the ii-th element from pp. Formally, update pp to [p1,…,pi−1,pi+1,…,pn][p1,…,pi−1,pi+1,…,pn]. It can be shown that no matter what ii you have chosen, pp will be a permutation of integers from 11 to |p||p| after all operations. You … Read more

Cross Xor solution codeforces

Cross Xor solution codeforces   There is a grid with rr rows and cc columns, where the square on the ii-th row and jj-th column has an integer ai,jai,j written on it. Initially, all elements are set to 00. We are allowed to do the following operation: Choose indices 1≤i≤r1≤i≤r and 1≤j≤c1≤j≤c, then replace all values on the same row or column as (i,j)(i,j) with the value xor 11. In … Read more

Checker for Array Shuffling solution codeforces

Checker for Array Shuffling solution codeforces   oolimry has an array aa of length nn which he really likes. Today, you have changed his array to bb, a permutation of aa, to make him sad. Because oolimry is only a duck, he can only perform the following operation to restore his array: Choose two integers i,ji,j such that 1≤i,j≤n1≤i,j≤n. Swap bibi and bjbj. The sadness of the array bb is the … Read more

Array Shuffling solution codeforces

Array Shuffling solution codeforces   oolimry has an array aa of length nn which he really likes. Today, you have changed his array to bb, a permutation of aa, to make him sad. Because oolimry is only a duck, he can only perform the following operation to restore his array: Choose two integers i,ji,j such that 1≤i,j≤n1≤i,j≤n. Swap bibi and bjbj. The sadness of the array bb is the minimum number … Read more

Cyclic Rotation solution codeforces

Cyclic Rotation solution codeforces   There is an array aa of length nn. You may perform the following operation any number of times: Choose two indices ll and rr where 1≤l<r≤n1≤l<r≤n and al=aral=ar. Then, set a[l…r]=[al+1,al+2,…,ar,al]a[l…r]=[al+1,al+2,…,ar,al]. You are also given another array bb of length nn which is a permutation of aa. Determine whether it is possible to transform array aa into an array bb using the above operation some number of times. Input Each … Read more

Unequal Array solution codeforces

Unequal Array solution codeforces   You are given an array aa of length nn. We define the equality of the array as the number of indices 1≤i≤n−11≤i≤n−1 such that ai=ai+1ai=ai+1. We are allowed to do the following operation: Select two integers ii and xx such that 1≤i≤n−11≤i≤n−1 and 1≤x≤1091≤x≤109. Then, set aiai and ai+1ai+1 to be equal to xx. Find the minimum number of operations needed such that the equality of the array is less … Read more