Comments

Yes, it is a possible to solve this using KMP:

Link to code: https://cses.fi/paste/91785ee2b5f0dd262517f4/

HINT:

Spoiler

For 1385F - Removing Leaves, there exists a O(n) solution based on rerooting of trees concept.

Check this out : 87161106

I know, I haven't used that.

Apparently,the mistake is overflowing of the product.

Thanks anyway.

What is wrong in this :

Try to take even number of negative numbers starting from descending order and multiply with even numbers left , again in descending order.

If the above is not possible, then check if a zero exists.

If a zero exists, ans is zero else answer has to be negative.

SO, try to take odd number of negative numbers in ascending order and choose remaining numbers as even, again in ascending order ?

https://atcoder.jp/contests/abc173/submissions/15018728

while (j->second < g.size())
                j++;

In code of part 2, it says

mask ^= basis[i]; // Otherwise subtract the basis vector from this vector

Can someone explain how subtracting is synonymous to XOR here ? Is this an error ?

We can use sparse table and concept of NEXT GREATER ELEMENT.\

CHECKOUT :

81811299

Thanks for pointing it out galen_colin

I have fixed it but still gives wrong answer. Any ideas ??

https://atcoder.jp/contests/abc168/submissions/13358103

Can someone help me to figure out what is wrong with my solution for E ?

https://atcoder.jp/contests/abc168/submissions/13345624

My logic is almost similar to the one given by galen_colin but is failing from test cases 11 to 19 .

I am dividing coordinates (a,b after dividing by gcd) to 3 cases:

1)Origin(0,0)

2)either on x-axis or on y-axis but not origin

3)Neither of the above

0

Yeah, you are right. I overlooked the directed part. Any efficient algorithm for answering queries then ?

0

So, if there are several queries, you can add the inputted edge between two vertices only if they are of same colour. By this way, your graph should break into several connected components and for each query, you just need to check if the two vertices 'u' and 'v' are connected to at least one common connected component in the original graph.

Bit of an overkill but problem 1 of this blog may be helpful

https://mirror.codeforces.com/blog/entry/20935

Intuition is incorrect,

For n=4,

{1000,1,2,2000},

your algorithm will fail.

0

For question D:https://mirror.codeforces.com/contest/706/problem/D

Can someone explain logic behind this submission https://mirror.codeforces.com/contest/706/submission/19826426 ? It seems extremely simplistic and doesn't seem to use tries.

What is subcase 136 in pretest 2 ?