Misuki's blog

By Misuki, 10 hours ago, In English

Except hints/solutions, I try to add a "general idea" section discuss about some general strategy and standard ideas used to solve the problem, hope you would like it :)

2001A - Make All Equal

idea & solution: Misuki

Hint 1
Hint 2
General idea
Solution
Code

2001B - Generate Permutation

idea & solution: Misuki

Hints/General idea of solution path 1
Hints/General idea of solution path 2
Solution
Code

2001C - Guess The Tree

idea: feecle6418, solution: Kaey

Hint 1 for solution 2
Hint 2 for solution 2
Solution
Solution 2
Code
Code 2

2001D - Longest Max Min Subsequence

idea & solution: Misuki, tester's code: SorahISA

Hint 1
Hint 2
General idea
Solution
Code
Tester's code

2001E1 - Deterministic Heap (Easy Version)

idea & solution: Misuki

Hint 1
Hint 2
Further hints for solution path 1 (official solution)
Further hints for solution path 2 (alternative solution)
General idea
Solution
Code

2001E2 - Deterministic Heap (Hard Version)

idea & solution: Misuki

Hint 1
Hint 2
Hint 3
General idea
Solution
Code
  • Vote: I like it
  • +113
  • Vote: I do not like it

»
5 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Someone gotta explain C, cause solution above is unclear.

  • »
    »
    5 hours ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    we can easily find if two nodes have edges or not using a divide & conquer approach. Lets say if we have two nodes $$$ x $$$ and $$$ y $$$. querying them will give us a node $$$ m $$$ such that m is the center of the distance. then we can solve it for $$$ (x, m) $$$ and $$$ (m, x) $$$ and so on until the answer of a query is either of the nodes.

    The second big observation is that the root of tree is 1 so every node will be connected to 1 in some manner. so instead of applying divide & conquer between two random nodes, we can apply divide & conquer to 1 and any of the unvisited nodes yet.

    Submission

    • »
      »
      »
      3 hours ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      You mean (x,m) and (m,y).

  • »
    »
    4 hours ago, # ^ |
      Vote: I like it +9 Vote: I do not like it

    For C there is a simpler solution with only n log n queries.

    You can just "root" the tree in 1, and after that for each node, you'll determine is father. For each node $$$a$$$: $$$x_1$$$ = query(a,1)

    $$$x_2$$$ = query(a,$$$x_1$$$) ...

    $$$x_{l}$$$ = query(a,$$$x_{l-1}$$$)

    When $$$x_{l}=a$$$ you stop and you know that the father of $$$a$$$ is $$$x_{l-1}$$$. $$$l<\lceil log(n)\rceil$$$ because each time you divide your path by 2. So at end it'll be n log n queries.

    Hope I was clear.

    • »
      »
      »
      4 hours ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Edit: Sniped above :)

    • »
      »
      »
      4 hours ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Why can we root the tree at 1? Can't the root be any one of the nodes provided?

      • »
        »
        »
        »
        3 hours ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Since the edges are undirected, any node can become the root. Trying to draw a tree starting from any node at the zeroth level will help to understand this.

        Random example
      • »
        »
        »
        »
        3 hours ago, # ^ |
        Rev. 3   Vote: I like it 0 Vote: I do not like it

        Any vertex of the tree can be the root of a tree. So, the statement "the root can be any one of the nodes provided" is true. This means we can choose any node as the root and proceed with the process. Nodes 1, 2, ..., n are all valid choices. In this solution, we chose node 1 as the root, but selecting any other node would also be correct. (But please remember: you can only choose one node as the root in a solution. If you choose a different node, for example, node 3, then you need to consider nodes 1, 2, 4, 5, ..., n.)

  • »
    »
    3 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    consider a and b in a tree and distance between them is 7, so x would be some node in distance of 3 from a, and in distance of 4 from b, now you should change b to x (binary search) now you will give new x between a and new b, and distance between a and x is 1, distance between x and b is 2, that means you have an edge between a and x,

    continue doing this approach for all node from 2 to n, you will find what is the parent of node i, and because we have a tree (we have n — 1 edges, that's why you should loop from 2 to n and not 1 to n), it works true.

    you can see my code for better understanding,

    hope it helps.

    i couldn't accept it during the contest because my previous solution works in O(2*n*lon2(n)) and its more than 15*n.

»
5 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Thanks for the super fast tutorial

»
5 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Fast Tutorial

»
5 hours ago, # |
Rev. 2   Vote: I like it +10 Vote: I do not like it

i got ABSOLUTELY crushed. this contest made me rethink my life decisions and contemplate on quitting CP forever :(

gotta give props for the blazingly fast editorial though

»
5 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

I don't think I understood B, can someone please explain why for n == 4, 3 1 4 2 isn't valid? I thought that you could build on this for even n, making n==2 the only impossible input.

  • »
    »
    5 hours ago, # ^ |
      Vote: I like it +4 Vote: I do not like it

    Forwards takes 2 passes, backwards takes 3.

    • »
      »
      »
      4 hours ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      a = [3, 1, 4, 2]

      The typewriter 1 will go 1 and carriage return once, then go to 2 and carriage return twice and go to 3 and then to 4

      So the carriage return total of typewriter 1 is 2

      Now let's consider typewriter 2, typewriter 2 will go to 1 and carriage return then go to 2 and to 3 and carriage return twice and then go to 4

      Both of them take 2 carriage return so it should be valid rigtht?

      • »
        »
        »
        »
        4 hours ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        Typewriter 1 can go from 1 to 2 without returning in between.

      • »
        »
        »
        »
        4 hours ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        "The typewriter 1 will go 1 and carriage return once, then go to 2 and carriage return twice and go to 3 and then to 4"

        It is possible for typewriter A to collect 1 and 2 without returning. Since we are looking to minimize the carriage return operation, the optimal number would be 2.

      • »
        »
        »
        »
        4 hours ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        if we consider minimum carriage returns in your permutation typewriter1 needs 2 returns and typewriter2 needs 3.

  • »
    »
    4 hours ago, # ^ |
      Vote: I like it +6 Vote: I do not like it

    from the pointer facing at 1, to generate 3 1 4 2, you could do 1 2 in one traversal and then return and do 3 4 in 1 traversal. So 1 return in total.

    but from the pointer facing at n, to generate 3 1 4 2, you first need to get to third poositing and make it 1 then return, then traverse to make 2 and 3 and return again and then make 4 (since 4 comes before 3 that way) so you made 2 returns in that way. Minimum of 2 isnt equal.

  • »
    »
    4 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    for left typewriter it will be 1 return pass as 1 2 return 3 4, but for right typewriter it will be 2 return pass as 1 return 2 3 return 4.

»
5 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Super-fast editorial!!!

»
5 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

We can do binary search on trees ?!?!

»
5 hours ago, # |
  Vote: I like it +8 Vote: I do not like it

this contest gave me the encourage to quit CP

»
5 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Could someone tell me the prbleam about my code? ~~~~~~~~~~ //this is my code from sys import stdout def ss(x,y): if x!=y and b[x][y]==0: print('?',x,y) stdout.flush() z=int(input()) b[x][y]=z if x==z: a.append(x) a.append(y) else: if x<z: ss(x,z) else: ss(z,x) if z<y: ss(z,y) else: ss(y,z) for _ in range(int(input())): n=int(input()) a=[] b=[[0 for i in range(n+1)] for i in range(n+1)] for i in range(1,n): for j in range(i+1,n+1): if b[i][j]==0: ss(i,j) print('!',*a)
~~~~~~~~~~

  • »
    »
    4 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    this is C

    • »
      »
      »
      4 hours ago, # ^ |
        Vote: I like it +5 Vote: I do not like it

      Could you please put it in a code block for easier visualization?

      • »
        »
        »
        »
        4 hours ago, # ^ |
          Vote: I like it 0 Vote: I do not like it
        Your code here...
        from sys import stdout
        def ss(x,y):
            if x!=y and b[x][y]==0:
                print('?',x,y)
                stdout.flush()
                z=int(input())
                b[x][y]=z
                if x==z:
                    a.append(x)
                    a.append(y)
                else:
                    if x<z:
                      ss(x,z)
                    else:
                        ss(z,x)
                    if z<y:
                      ss(z,y)
                    else:
                        ss(y,z)
        for _ in range(int(input())):
          n=int(input())
          a=[]
          b=[[0 for i in range(n+1)] for i in range(n+1)]
          for i in range(1,n):
            for j in range(i+1,n+1):
              if b[i][j]==0:
                ss(i,j)
          print('!',*a)      
        
        
        • »
          »
          »
          »
          »
          3 hours ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Please use collapse/spoilers the comments are getting quite messy and lengthy.

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

E1 can be solved in a much simpler way (277414233) without any binomial coefficients or combinatorics.

»
4 hours ago, # |
Rev. 4   Vote: I like it 0 Vote: I do not like it

D can be solve in O(n).

Soultion
»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

D was pretty nice, I wish I actually knew trees, so I could attempt C as well. I think I'm gonna reach expert regardless though! very nice contest, thank you!

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

B was easy, If we can understand the problem and write some testcases

In most of such problems , I end up not understanding but today I did B

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

SUPER FAST!Thank You!

The Problem is funny.I love this round!

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

general idea is really useful.

Thanks.

Btw, problem D is nice

»
4 hours ago, # |
  Vote: I like it +28 Vote: I do not like it

Another approach to solving problem C is to assume that the tree is rooted at vertex $$$1$$$. For each vertex $$$u = 2, 3, \ldots, n$$$, the goal is to find its parent $$$p(u)$$$.

By using the function $$$\texttt{query}(u, 1)$$$, you can get the midpoint of the path from $$$u$$$ to its ancestor $$$1$$$. Keep halving the path until $$$\texttt{query}(u, x) = u$$$, which means that $$$x$$$ must be $$$p(u)$$$. This method will find $$$p(u)$$$ in no more than $$$\lceil \log_2 (n-1) \rceil$$$ queries!


Code
»
4 hours ago, # |
  Vote: I like it +8 Vote: I do not like it

I like that General idea,it really help me much!!!

  • »
    »
    4 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    glad you like it :)

    • »
      »
      »
      4 hours ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I am sorry to bother you ,but can you tell me the General idea of promlem C
      I am confused about the Solution.I cant find out the index logic.

      • »
        »
        »
        »
        3 hours ago, # ^ |
        Rev. 2   Vote: I like it +1 Vote: I do not like it

        It have less standard idea and rely on pure puzzle solving ability more in my opinion, but if you have a good perspectice about the problem it might be easier. For example, I think the problem as some kind of spanning tree problem and try to keep finding edge connect different component. (Solution2 in editorial)

  • »
    »
    4 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I cant understand problem C .How the binary work? Why use the binary search?

    • »
      »
      »
      3 hours ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Sorry, I was thinking hint for my solution when writing it but the solution part is from coordinator. I've add Soluion2 which correspond to the hint section.

»
4 hours ago, # |
Rev. 2   Vote: I like it +12 Vote: I do not like it

Maybe I'm misreading the solution to C, but I think this is simpler. The key idea is that $$$(u, v)$$$ is an edge if and only if querying ? u v returns $$$u$$$. Then, for each $$$2\le v\le n$$$, we can query ? v 1, take the result $$$x$$$ to query ? v x, etc, until we reach some node $$$u$$$ with ? v u being $$$v$$$.

In this way, you can think of this as rooting the tree at node $$$1$$$ and discovering the parent of node $$$v$$$ for each $$$v\neq 1$$$ in this rooted tree, which must by definition give $$$n - 1$$$ distinct edges.

Edit: Sniped above :)

»
4 hours ago, # |
  Vote: I like it +11 Vote: I do not like it

It seems I have an alt approach for C.

Step 1-1
Step 1-2
Step 2

277363292

Additional note
»
4 hours ago, # |
Rev. 2   Vote: I like it +3 Vote: I do not like it
Another way of doing C

Edit: seems like a few other people posted the same solution while I was typing it, lol

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

For C I did the following. Initialize a stack of pairs with all (i, j) where i < j. While the stack is empty, I pop (a, b). I check using a DSU if a and b belong to the same connected component (that has been discovered till now, and skip if they do. If they don't, then I query ? a b and push the output x to the stack if x != a. Otherwise, I push the found edge and merge the two components.

I think this should always find all edges while remaining under the query limit. But I don't understand why this WAs. Could someone explain?

277403335

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

For C, I used DFS and it seems to have worked somehow. Could someone explain it?

277409228

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Do anyone know a software that have a faster execution for interactive problem?

I use jdoodles but it not stable

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

I was unsure before submitting the code for problem C but it passed the pretests.

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Problem D is nice idea but it's hard implementation!

»
4 hours ago, # |
Rev. 2   Vote: I like it +5 Vote: I do not like it

Solution D in O(n) (attempt: 277409175)

We will store the current response in the ans array. Initially, ans is empty.

Let's build an array r, where r[x] is the maximum index i, such that c[i] = x

Let's build an array of used, where used[x] = True if the value of x is contained in ans and False otherwise. Initially, all values are False

Let's go through the c array.

Let's consider the value of c[i], if used[c[i]] = True, go ahead, otherwise we will execute the next cycle:

If ans is empty, we do nothing and exit the loop

If r[ans.back()] <= i, exit the loop

1) If ans.size() % 2 == 0, then

1.1) If c[i] < ans.back(), then delete the value of ans.back(), do not forget to put the corresponding value to the array used (used[ans.back()] = False) and return to the beginning of the cycle

1.2) Otherwise (if c[i] > ans.back()), check

1.2.1) If c[i] > ans[-2] (the penultimate element in ans), then remove the last two elements from ans, do not forget to change used, return to the beginning of the cycle

1.2.2) Otherwise (if c[i] < ans[-2]), exit the loop

2) Otherwise (if ans.size() % 2 == 1) we perform actions similar to 1), but change the signs to the opposite ones (> to <, and vice versa) After the loop, add c[i] to ans, do not forget to change used (used[c[i]] = True)

When we go through the entire c array, the ans array will be the optimal answer.

Since we add and remove each element from ans once, the asymptotics is O(n)

»
4 hours ago, # |
  Vote: I like it +12 Vote: I do not like it

Reading question B reminds me of how research papers are written ;))

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

The problems were enjoyable, but Problem B lacked clarity. In future contests, it would be great to see more emphasis on covering more cases for such problems.

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

What topics should I learn to solve problem D?

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

C does not use binary search as mentioned in the editorial, but some version of binary lifting

  • »
    »
    3 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Sorry, I've add binary search solution on it (Solution2)

»
4 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Good quality contest, thank you !

»
4 hours ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

for B we can just say if n even then not possible and if odd

we can construct like this--

for 3 -->1 3 2 for 5 -->1 3 5 4 2

for 7 -->1 3 5 7 6 4 2

and so on

»
4 hours ago, # |
  Vote: I like it +3 Vote: I do not like it

A super simple way to solve C:

int main() {
  int t; scanf("%d", &t);
  while (t --) {
    int n; scanf("%d", &n);
    auto get = [&] (int a, int b) {
      printf("? %d %d\n", a, b);
      fflush(stdout);
      int res; scanf("%d", &res);
      return res;
    };
    vector<int> fa(n + 1);
    for (int i = 2; i <= n; i ++) {
      int r = 1;
      for (int j = 0; j < 15; j ++)
        r = get(r, i);
      fa[i] = r;
    }
    printf("!");
    for (int i = 2; i <= n; i ++)
      printf(" %d %d", fa[i], i);
    puts("");
    fflush(stdout);
  }
  return 0;
}
  • »
    »
    3 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Please use collapse/spoilers the comments are getting quite messy and lengthy.

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Awesome work! Love those general ideas!

»
3 hours ago, # |
  Vote: I like it +3 Vote: I do not like it

D can be done with simple stack

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

First though of dp ,then greedy approach striked but wasnt able to implement it.

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone please help me figure out what is wrong in my soln to D link

In this:
I have a turn variable which tells us that we have to maximize or minimize the next element to be chosen.
A variable lst that keeps the last printed index.
A set st that keeps track of the elements that can be selected in future with their indices.
A map that keeps the count of elements that are left in the array and are not visited till now.

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Does anyone have test cases for D? Looks like I'm failing somewhere on Test 3.

  • »
    »
    3 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I figured some out for my submission

    Here's one that I failed on:

    1
    7
    4 1 2 4 5 2 1
    

    Answer should be:

    4
    4 1 5 2
    

    An even simpler one I failed on:

    1
    5
    4 2 4 1 2 
    

    Answer should be

    3
    4 1 2
    
»
3 hours ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

off-topic but quick question: why is my activity section different for everyone except me? i see a 15 day streak when logged in while in incognito mode i see an 11 day streak, is this normal?

  • »
    »
    3 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    i think it shows it on your local time when you're not incognito, but when you use incognito, your local time defaults to whatever incognito is set to be. so for some time zones you didn't actually keep your streak.

    • »
      »
      »
      3 hours ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      man i was trying making a 90 day streak, sad :(

      gotta start again now

      • »
        »
        »
        »
        3 hours ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        i wouldnt say you have to start again, youre bound to lose the streak on some timezones that are far from yours. good job on the streak so far though, i hope you'll reach your goal

        • »
          »
          »
          »
          »
          119 minutes ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          thanks, looks like you just turned expert too. congratulations!

»
3 hours ago, # |
  Vote: I like it +3 Vote: I do not like it

Wasn't able to completed problem D during contest but I liked it.

And the general idea section is super useful.

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone please tell me what i did wrong in the 3rd question

https://mirror.codeforces.com/contest/2001/submission/277397815

It's been 1.5 hours and i have read many other solutions and even the official one, and i do not understand where my logic went wrong.

thanks

»
3 hours ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Dear tester, Kind request, when you write program to match the contestant's output, with correct output, Please give some meaningful errors, which can help the user in debugging the issue.

wrong answer 3919th numbers differ — expected: '1', found: '3'

How am I supposed to know, 3919th number is from which test case ????

It would have been great help, if you had simply put here the test case number, I could have used some tricks to find out where my solution is failing :| .

cc: Misuki

»
3 hours ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

What is the difference between Code and Code 2 for the C problem? I tried and was not able to find the difference :(

Both look exactly the same. I mean Letter by Letter.

»
3 hours ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

when i trying to hack this submission, it shows "Unexpected verdict".

here is gen:

#include<bits/stdc++.h>
using namespace std;
const int N=3e5-4;
int main() {
    cout << 1 << endl;
    cout << N+1 << endl;
    for(int i=1,l=1,r=N;i<=N/2;i++) {
        if(i%2==1) {cout << r << ' ';r--;}
        if(i%2==0) {cout << l << ' ';l++;}
    }
    cout << N/2 << ' ';
    for(int i=1,l=1,r=N;i<=N/2;i++) {
        if(i%2==1) {cout << r << " \n"[i==N/2];r--;}
        if(i%2==0) {cout << l << " \n"[i==N/2];l++;}
    }
}

It seems that some code that should be TLE is incorrectly tagger correctness in polygon, please check this.

upd. physics0523 seems facing same question?

  • »
    »
    3 hours ago, # ^ |
      Vote: I like it +7 Vote: I do not like it

    Maybe some intended solution on Polygon also gets hacked or validator is broken or something

    • »
      »
      »
      2 hours ago, # ^ |
        Vote: I like it +15 Vote: I do not like it

      Turns out a tester's solution TLE on the hacked test, now it should be fixed.

      • »
        »
        »
        »
        2 hours ago, # ^ |
          Vote: I like it +6 Vote: I do not like it

        Let's share my generator:

        #include<bits/stdc++.h>
        
        using namespace std;
        
        int main(){
          ios::sync_with_stdio(false);
          cin.tie(nullptr);
          cout << "1\n";
          cout << "300000\n";
          for(int i=0;i<300000;i++){
            if(i){cout << " ";}
            int a;
            int j=i%100000;
            if(j%2){a=1+(j/2);}
            else{a=300000-(j/2);}
            if(100000<=i && i<200000){a=i;}
            cout << a;
          }cout << "\n";
          return 0;
        }
        

        Some false (and maybe too straight-forward simulation) solutions takes $$$O(N^2)$$$ in this case.

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Am i missing something in D?

Here is what i did (ITS WRONG and idk y):

3 arrs:

Step 1
Step 2
Last step

this gave me wrong answer on pretest-2 meaning that it isn't the correct logic, i just want to know why

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Thanks for the general ideas, hints, and fast editorial. Really appreciate it!!

»
2 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

I Think in problem D it is more intuitive to think about storing range min and max in a segment tree and once an element is taken update min value to 1e9 and max value to -1e9.

»
2 hours ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

I still can't figure out why my submission to C is incorrect and giving wrong ans. Somebody please help ,my implementation is clean

My submission

Found it! I was randomly printing the ans at the end , didnt see that we have to print serial wise 1..n-1

»
2 hours ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

For A , the hint encourages us to think about the lower bound of the answer . For me it is 0 (the case where all the elements in the array are equal ) , and that doesn't help in any way . What did the author expected as an answer when they gave us this hint ?

I know this is a very silly question perhaps even meaningless but any help is appreciated

  • »
    »
    2 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I mean the lower bound of the answer for any fixed $$$a$$$, not necessarily with all elements equal

»
2 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

I am new to interactive problems. My solutions got idleness limit exceeded. It is mentioned in the statement that this happens when you don't flush the output put I do. Can someone suggest what would be the problem?

  • »
    »
    111 minutes ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    If you are using c++. then please refer to this.

    1. Don't use the cin.tie() or cout.tie()
    1. Define this in your headers.

    #define IOFLUSH fflush(stdin);fflush(stdout);

    Whenever you take input, or print any output. just write this statement before and after it, to avoid any sort of issues.

    IOFLUSH

    This should solve the issue.

»
114 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone hack my solution for problem D 277416865. The complexity is O(nlog²) and I think the worst case is :

n , 1 , n-1 , 2 , n-3 , 4 , n-4 , 5....

»
114 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Can someone explain me B? I don't think I can understand the task properly(maybe cuz im dumb ;() but why can't i just go forward without returning on bot typewriters, or maybe thats not how pointer works?

  • »
    »
    77 minutes ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    The problem states that, in a move operation:

    Such operation can be performed only if after the operation, $$$1≤i≤n$$$ holds.

    Hence, after moving to the last position, the pointer must return to its initial position to be able to write again.

    The way I understand this problem, a valid permutation should have the same number of inversions of consecutive numbers, going from left to right and from right to left. One way to achieve such a permutation is to start at the middle index and go back-and-forth in the array until it goes out of bounds (or vice-versa).

    277352967

»
100 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone help me find error in my code? I'm trying to solve D and it is giving wrong answer on test case 3. Here is my submission: https://mirror.codeforces.com/contest/2001/submission/277428182

»
100 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone find my error in problem C? This is my submission 277387198, which should be quite self explanatory. I tried to find the edges on the path $$$1---u$$$ for all undiscovered node $$$u$$$ by querying $$$(1,u)$$$. If it returns $$$x$$$, query $$$(1,x)$$$ and $$$(x, u)$$$. Skip the query $$$(1,x)$$$ if x is already discovered.

The solution looks ok to me, and I got a verdict saying WA on test $$$5$$$, but seems like test $$$5$$$ is a tree with edges $$$1-2,1-3,1-4$$$ which my solution can detect. Any help with the solution or a test case that fails will be helpful. Thanks.

»
53 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

I solve problem D using Lazy segment tree. My solution: 277441928

I hope it is helpful.

»
5 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Problem D didn't have strong enough test cases a O(n^2) approach gets ac in main test, the triggering worst case test would have been n/2 1 n/2-1 2........ repeated twice.