Блог пользователя n0sk1ll

Автор n0sk1ll, 3 года назад, По-английски

1779A - Hall of Fame

Author: n0sk1ll

Hint
Solution
Bonus Problem

1779B - MKnez's ConstructiveForces Task

Author: n0sk1ll

Hint 1
Hint 2
Solution
Bonus Problem

1779C - Least Prefix Sum

Author: n0sk1ll

Hint 1
Hint 2
Solution
Bonus Problem

1779D - Boris and His Amazing Haircut

Author: n0sk1ll

Stupid Hint
Hint
Solution
Bonus Problem

1779E - Anya's Simultaneous Exhibition

Author: n0sk1ll

Hint
Lemma 1
Lemma 2
Solution
Bonus Problem

1779F - Xorcerer's Stones

Author: n0sk1ll

Hint 1.1
Hint 1.2
Hint 1.3
Hint 2.1
Hint 2.2
Solution
Bonus Problem
Bonus Problem Hint

1779G - The Game of the Century

Author: Giove

Hint
Solution
Bonus Problem

1779H - Olympic Team Building

Author: n0sk1ll

Huge thanks to dario2994 for helping me solve and prepare this problem.

Hint 1
Hint 2
Fake Solution
Lemma
Solution
Bonus Problem
Разбор задач Hello 2023
  • Проголосовать: нравится
  • +356
  • Проголосовать: не нравится

»
3 года назад, скрыть # |
 
Проголосовать: нравится +97 Проголосовать: не нравится

very fast tutorial ;)

»
3 года назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

Is this the fastest published editorial?

»
3 года назад, скрыть # |
 
Проголосовать: нравится +143 Проголосовать: не нравится

These are, as of now, surely the best CF problems of 2023!

»
3 года назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

F is very similar to : THis Problem

»
3 года назад, скрыть # |
Rev. 6  
Проголосовать: нравится -12 Проголосовать: не нравится

I want to know in Prob.A when I was submitting like for LR the answer is 1, why its wrong?

Since only 1 operation will be enough in this case if we find an "LR" occurence we can just swap it and it's done

  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится -25 Проголосовать: не нравится
    import java.io.BufferedOutputStream;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    
    public class HallOfFame {
       public static void main(String[] args) throws IOException {
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));
    
          int t = Integer.parseInt(br.readLine());
          while (t-- > 0) {
             int n = Integer.parseInt(br.readLine());
             String str = br.readLine();
    
             int cR = 0;
             for (int i = 0; i < n; i++) {
                if (str.charAt(i) == 'R') {
                   cR++;
                }
             }
    
             if (cR == 0 || cR == n) {
                pw.println(-1);
                continue;
             }
    
             int res = 0;
    
             for (int i = 0; i < n - 1; i++) {
                if (str.charAt(i) == 'L' && str.charAt(i + 1) == 'R') {
                   res = i + 1;
                   break;
                }
             }
    
             pw.println(res);
    
          }
    
          br.close();
          pw.flush();
          pw.close();
       }
    }
    
»
3 года назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

Queue forces on C and D

»
3 года назад, скрыть # |
Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

my sol for C was basically to do some math. Starting at m you check all the contiguous sums down from m and up from m. For the sums on the left, they have to be less than or equal to 0 and for the sums on the right, they have to be greater than or equal to 0

Did anyone use a similar approach that worked? I got a WA on pretest 2.

Edit: So I looked at the editorial and while I'm still not clear on the solution, its helped. However, can someone poke holes at my logic here? I manipulated the inequality for cases where k was smaller than m and for cases where k was larger than m. When you do that, you get the following inequalities:

Case 1: (k < m) a_k+1 + a_k+2 + a_k+3 + . . . + a_m <= 0

Case 2: (k > m) a_m+1 + a_m+2 + a_m+3 + . . . + a_k >= 0

So for the first case, you get these inequalities that I've numbered on the left

(1) a_m <= 0

(2) a_m + a_m-1 <= 0

(3) a_m + a_m-1 + a_m-2 <= 0

. . .

(m-1) a_m + a_m-1 + a_m-2 + . . . + a_2 <= 0

For the second case, you get these inequalities that I've numbered on the left

(1) a_m+1 >= 0

(2) a_m+1 + a_m+2 >= 0

(3) a_m+1 + a_m+2 + a_m+3 >= 0

. . .

(n-m) a_m+1 + a_m+2 + a_m+3 + . . . + a_n >= 0

So I assumed that as long as you solved these cases independently and in order, you would get the optimal answer (go through inequalities numbered 1 through m-1 in case 1, and then go through the inequalities numbered 1 through n-m in case 2.

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Why is this solution to C wrong? 187783695

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Could someone help? Why I got runtime 187832356

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

wow, so fast!

»
3 года назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

super fast

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

E is brilliant!

»
3 года назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

submitted editorial in 0ms

»
3 года назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

Damn, B was very sneaky! Great problems!

»
3 года назад, скрыть # |
 
Проголосовать: нравится +42 Проголосовать: не нравится

Bonus for E (hopefully it's correct :)) Let's find outdegree for all people, call it deg[i]. It's sufficient to find minmum R such that there exists subset of people of size R such that their sum of outdegrees equals nCr(R, 2) + R * (N — R). I was thinking about this during contest but how do you implement it if you want to recover answer as well?? I mean can you do this faster than O(N^4), and in particular in better space complexity?

Btw amazing problemset.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

My first contest in my life and the first contest in 2023

»
3 года назад, скрыть # |
 
Проголосовать: нравится -8 Проголосовать: не нравится

For problem F, the editorial says "Time complexity is $$$O(n.A^2)$$$ and memory complexity is $$$O(nA)$$$. It is possible to optimize this, but not necessary". I believe my code has the same complexity as said above but it got TLE at test 10 :( 187833020

»
3 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

The way you meet the New Year is the way you live the whole year: that fast editorial for all 2023 contests :)

»
3 года назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

The n = 3 case in B was really terrifying.

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Why did we look for i > j in problem E (lemma 2)? It seemed to me that i < j should. If I'm wrong, please explain why.

Sorry for my poor English

»
3 года назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

FST is not a funny joke.

About E:

Interactive problems takes a lot time to test the sample of it , so I submit it with out testing the sample .

My program WA on pretest 2 , but pretest 2 is a sample and I don't think this should be deducted from the score .

If there many samples , and I get WA on 2 , in codefoeces's rules , should my score be deducted ? Is this a mistake ?

I don't know , TAT.

(My English is so bad.)

»
3 года назад, скрыть # |
 
Проголосовать: нравится +31 Проголосовать: не нравится

I think that the author should swap E and F, it's so confusing.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

Bonus problems. Yeah !!!

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I even cannot come up with the lemma 1 of problem E during the contest. Perhaps I've forgotten the knowledge of the Graph Theory I've learned.

»
3 года назад, скрыть # |
Rev. 3  
Проголосовать: нравится +47 Проголосовать: не нравится

Bonus E :

View the match where player $$$u$$$ beat player $$$v$$$ as a directed edge from node $$$u$$$ to $$$v$$$ in a complete graph of $$$N$$$ vertices. Candidate masters are nodes that can be visited from all other nodes through some simple path (in other words, there exist a series of matches(=edges) to disqualify all other players).

All possible candidate masters are the nodes located in the last/terminal Strongly Connected Component(SCC) (SCC that doesnt have any outgoing edge to another SCC). As the graph is complete, this terminal SCC is unique.

For each node, find its outdegree. For the first $$$N-1$$$ nodes, do a simuls againts all other node(player) and count each of their loss match, with a total of $$$N-1$$$ queries. For the final node, calculate its outdegree from the remaining out/in-going edges from the previous $$$N-1$$$ nodes.

The terminal SCC (the candidate masters) are composed of the $$$x$$$ nodes with smallest outdegree such that their sum is equal to the number of edges among those $$$x$$$ nodes $$$=\frac{x(x-1)}{2}$$$. Pick minimum such $$$x$$$.

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Very fast tutorial and Bonus Problems are really interesting

»
3 года назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

I don't know why this solution gets AC while it shouldn't (Problem D)

187838626

i used sparse table for RMQ but i forgot to initialize the logs array but it passed with no problem!

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

What will be generalized approach for Problem B bonus part ?

»
3 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Bonus task for B:

Let n = km + r where 0 <= r <= m-1. Similar with original problem we get (k-1)s_m+s_r=0, where s_m = a1 + a2 + ... + am. When k = 1, r = 1, there's no solution because in this case a1 = s_1 = 0. Otherwise there exist some { a1, a2, ..., am } satisfy the condition. We let ai = a_(i-1)%m+1 for 1 <= i <= n and get a solution.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

For rank1 to rank4, all of them got "wrong answer on pretest 2" at B for one time.

What a great problem!

»
3 года назад, скрыть # |
 
Проголосовать: нравится +18 Проголосовать: не нравится

I used vector in the iteration of F, and get stack overflow(maybe in fact MLE?) in the system test. Can anyone explain the reason? Thank you.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

As a candidate master, I even CANNOT solve the problem E which is about finding "candidate master".

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Why in problem C we are going till i>=1 and not i>=0?

»
3 года назад, скрыть # |
 
Проголосовать: нравится -15 Проголосовать: не нравится

Even though I liked problem E myself, it felt weird that it was interactive, and not just giving degrees for each vertice, and asking the same. Can someone explain to me the reason it was given in such a way?

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

anyone can explain this??

problem B solution
»
3 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится +7 Проголосовать: не нравится

Alternative explanation for Div2D.

Observation 1: If $$$a_i \lt b_i$$$ for any $$$i$$$, then the answer is NO.

So we may assume WLOG that $$$a_i \geq b_i$$$ for all $$$i$$$.

Observation 2: We can restrict to using scissors in descending order of $$$x_1 \geq x_2 \geq ... \geq x_n$$$ (i.e use taller scissors first, then go down in size). This is because if there is a solution using another order (not descending), then the same solution intervals but sorted in descending order of the scissors length is still a feasible solution.

Observation 3: We need a scissors of length $$$b[i]$$$ to cut index $$$i$$$.

Notation: For index i, let $$$nx_i$$$ denote the next index after $$$i$$$ such that $$$b[nx_i] \gt b[i]$$$ (i.e next bigger element in $$$b$$$). This can be preprocessed using a monotonic stack. This is a standard problem so I'll skip the details, but I'll assume you can precompute $$$nx_i$$$ for all $$$i$$$ in $$$O(n)$$$ time. See https://leetcode.com/problems/next-greater-element-ii/ for example.

I'll also treat $$$b$$$ as a set using $$$v\in b$$$ to denote a value in the array $$$b$$$.

For each $$$v \in b$$$, let $$$indices[v]={u_1, ..., u_k }$$$ be a set of all the indices with value $$$v$$$: $$$b[u_j]=v$$$. We can divide $$$indices[v]$$$ into "slots" $$$[u_1, u_2, ..., u_{i_1} ], [u_{i_1+1},..., u_{i_2}],..., [u_{i_r+1}, ..., u_{k}]$$$ where each slot is separated by an element with $$$b$$$ value greater than $$$v$$$. For example, first slot separated from second by $$$nx_{u_1}$$$, and so on.

This means that the interval for scissor with length $$$v$$$ cannot cross the slots in $$$indices[v]$$$.

Now we proceed greedily. If $$$x_i \not\in b$$$, then there is no point using $$$x_i$$$, so skip it.

If $$$x_i \in b$$$, then we look at $$$indices[x_i]$$$. Take the smallest index $$$i_{\min}\in indices[x_i]$$$, and let $$$j_{\max}=nx_{i_{\min}}$$$. We trim all the indices in $$$indices[x_i]$$$ in the range $$$[i_{\min}, j_{\max})$$$ by repeatedly removing the smallest index until the slot is entirely trimmed. Some care should be taken if $$$a_{i_{\min}}=b_{i_{\min}}$$$ since we can skip this index (without starting a new slot).

And that's it, in the end, we check if $$$a_i=b_i$$$ after all the trimming. If it is, we return true, otherwise False.

C++ Implementation Details: $$$indices[v]$$$ is implemented as a map from int (value of $$$b$$$) to set where $$$indices[v]$$$ contains all the indices with value $$$v$$$ in $$$b$$$.

Code: https://mirror.codeforces.com/contest/1779/submission/187842280

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone please explain lemma 2 of problem E in more simple words. I don’t get why degree of every vertex in Si will be higher than Sj for (i<j).Also why S1 is set of candidate masters.

»
3 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится -15 Проголосовать: не нравится

i may sound a fool or someone who have less knowledge but in problem H cant we just do :

  1. sort the array ( not the original but make another array that have same elements )

  2. Then we have the sorted array , so 1...n/2 elements we will put in an array namely smallelements(lets say), and next n/2+1...n elements in an array namely largeelements(lets say)

  3. Then with repsect to original array we will check that whether a[i] is present in which array (smallelments or largeelements)... if a[i] is in smallelements we will print '0' else if a[i] is in largeelements we will print 1.

  4. FOR THE CASES WHERE DISTINCT ELEMENTS ARE JUST '1' we will simply print 1 for n times

  • anyone can correct me please? why my this approach is wrong?
»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Fast & perfect editorial

»
3 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

This contest was probably not good for #1 tourist

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

That moment when you realize all that time you were trying to solve a version of $$$E$$$ where in each game only $$$1$$$ player is chosen and the other is the winner of the previous game.

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

More and more vegetable,what should I do?

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I had great difficulty in C.

My idea was to use Segment tree but I WA on 2 many times. (Who can help to hack me? Please)

The Segment Tree includes the maxinum and the mininum of each section.

First, Reverse traversal [1~m-1].

s1 = 0

if sum[i] < sum[m] — s1:

s1 = s1 + 2 * query_max{a_i+1~m}

update(the location of the maxinum, -maxinum)

Then, traversal [m+1~n].

s2 = 0

if sum[i] + s2 < sum[m]:

s2 = s2 — 2 * query_min{a_m+1~n}

update(the location of the mininum, -mininum)

Please help.... QWQ

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

will there be a tutorial for bonus problem :")

»
3 года назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

jiangly fanbase strong

lol
»
3 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

can anyone please tell me where my solution is wrong:

https://mirror.codeforces.com/contest/1779/submission/187871735

Thanks in advance

Edit: nvmi.. i was stupid

»
3 года назад, скрыть # |
Rev. 3  
Проголосовать: нравится +26 Проголосовать: не нравится

Bonus F: After using the hint 6, you will find that this problem equals to choosing some non intersecting subtrees and make them have an xor sum of $$$s$$$. After you get a solution using whatever way (not neccessary with <=6 operations), you can make it within 6 steps using this simple trick about xor vector basis, and you will find that if it is possible to do so, you will always get an answer with less than $$$\log v+1$$$ steps.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

n0sk1ll, any insights on how you implemented the adaptive checker for E?

  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится +8 Проголосовать: не нравится

    Usually, adaptive jury is implemented by fixing some invariant in the input. In this one, I fixed the whole tournament graph, but allowed permutations (i.e. the resulting graph after all participants' queries have been asked will be isomorphic to the jury's initially intended one). Jury permutes the graph in a way such that the newly asked vertices will always have the smallest possible (available) out-degree, meaning that there is practically no information about the winners before $$$n-1$$$ queries are asked.

    In fact, there exists a solution which uses exactly $$$n-1$$$ queries — the tests seem to be strong. (and in practice, all fake solutions fail to squeeze into $$$2n$$$ queries, which was the constraint in the problem)

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I passed problem H with the following fix of the fake greedy:

While expanding from size 2 to size 4, we enumerate all the 15 ways instead of using greedy.

I don't know if it's correct or not. Can anyone prove its correctness or come up with a counterexample?

»
3 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

In Problem E Lemma 2,

We can also conclude that x has a higher out-degree than y for each x∈Si, y∈Sj, i<j.

How are we able to conclude this?

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Anyone have solution Bonus Problem for C ?

»
3 года назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

1779D in second hint, I think it will be x >= bi

»
3 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

How did some people used DSU in solving D ? Example jiangly

»
3 года назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Can anybody explain me D problem solution using segment trees???

  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится +1 Проголосовать: не нравится

    I solved it using segment tree 187802839. The only purpose of the segment tree is to be able to calculate the maximum element of b in the range [l, r).

    I'll try to explain my solution.

    1. If for any i, b[i] > a[i], answer is NO.
    2. If a[i] == b[i] then this hair doesn't need a razor.
    3. If a[i] > b[i], then we need to cut hair i, and so there must be a razor with length b[i], else answer is NO.

    Now the only thing is that when we make a cut using razor x on the interval [l, r), there must not be any element of b in the range [l, r) such that b[i] > x. If there exist such b[i] > x, we will cut short i to length x < b[i] which can not be grown back.

    A conclusion from above is that maximum element of b in range [l, r) must be <= x. To find the maximum element of b in range [l, r) in O(log n) time, we use a segment tree. A even better data structure to use is a sparse table which can return the maximum of a range in O(1).

    All I do is store in a map, razor of which length will have to cut which indices. And then I try to distribute the ranges among all razors available of that length.

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

About problem H, I have two questions:

  1. How to construct a test with over $$$1000$$$ subsets we have to consider (not $$$8000$$$, just $$$1000$$$).
  2. How to implemented quickly in the meet in the middle part (I only know to use sort and binary search).
  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится +10 Проголосовать: не нравится
    1. Make all (reachable) big subsets intersect. I used different strategies, the simplest of which is generating $$$15$$$ numbers close to each other by value. There will be $$$\binom{15}{8} = 6425$$$ different subsets, all having similar value, and all are intersecting. Fill the rest of the array in a way such that the "smallest" subset can be extended into a full solution, but others cannot. In practice, more than $$$1000$$$ subsets would have to be considered in any solution.

    2. Write two pointers instead of binary search. As for sorting, It is possible to sort all subsets of an array of length $$$n$$$ in $$$O(2^n)$$$. Consider that all subsets of some prefix $$$a_1, a_2, \ldots a_i$$$ are already sorted, let their array be $$$b_1,b_2,\ldots b_k$$$ where $$$k=2^i$$$, and let $$$x = a_{i+1}$$$ be the new element we consider. The new subsets we add will have sums $$$b_1+x, b_2+x, \ldots b_k+x$$$, and in that order since $$$b$$$ is sorted from previous steps. We only need to merge two already sorted arrays, which is possible in $$$O(k)$$$.

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone explain how non-intersecting subtrees can be ensured in problem F?

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I love these bounce problems thank you for the good contest (⁠。⁠♡⁠‿⁠♡⁠。⁠)

»
3 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

nvm

»
3 года назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

I solved problem D all by myself (after the contest of course) using a monotonic stack approach. I have no one to share it with but I feel happy because that's probably the most challenging problem I've solved with no hints

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In problem C, I'm wondering why moving from right to left is correct than moving from left to right

»
3 года назад, скрыть # |
 
Проголосовать: нравится +24 Проголосовать: не нравится

We have a simple way to solve E with $$$n$$$ querys, and to be skipped.

My submission: 187829528 and the one coincides with mine: 187788613.

The code is short and simple so it is easy to be close with others without leaking I think.

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Anyone mind to post the solution for E's bonus problem?

Thanks in advance

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In F, I have a solution in mind for finding if it is possible to get xor=0 but how to restore the steps is what I can't figure out. I would love it if someone could help. Thankyou

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

What does "we are only interested in the closest road of each direction to the big triangle's side" means in G's solution? More specifically, what does the "closet road of each direction" means?

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Why this Seg tree implementation of D is giving WA?? https://mirror.codeforces.com/contest/1779/submission/187831216

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Problem G's solution is very confusing. Maybe too obvious to explain the meaning of "closest road to the big triangle's side"?

  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Solved it. "closest road to the big triangle's side" refer to the closest road that is parallel with the corresponding big triangle's side. And the proving is fun, it only takes me about 3 hours of my sleep to do the "case works"

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

For everyone struggling with H's TLE, here's a little something too TRIVIAL for the solution to mention: just ignore all the cases of which sum is lower than (S * k / 32) (k is the number of elements of the case and S is the total sum of all elements). Pretty TRIVIAL right? Works like magic(at least for me 1000ms -> 100ms) and here's the code (In Java)190213361 btw since it only takes less than 10% of the TL, it makes you wonder what will happen if you replace some of the techs with brute force.

»
3 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone help me in F? It is clear that if we can find 2 non intersecting even subtrees whose XOR sum is XOR sum of all nodes, then we can solve the problem. But why is this condition necessary?

»
3 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

202603354 Can anyone tell me why this submission for problem D fails for test 2?

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Why did I have this code title? Help!!

#define  _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <list>
#include <string>
#include <cmath>
#include <bitset>
#include<stack>

#define ll long long

#define N 200005



void solve() {
	int n; cin >> n;
	ll a[N], b[N]; 
	int cnt = 0;
	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i]);
	map<int, int>use;
	map<int, int>need;
	bool flag = 0;
	pair<int, int> pi[N];
	for (int i = 0; i < n; i++) {
		scanf("%lld", &b[i]);
		if (b[i] > a[i])
			flag = 1;
		if (b[i] != a[i]) {
			pi[cnt] = { b[i],i };
			need[b[i]]++;
			cnt++;
		}
	}

	int m; cin >> m;
	for (int i = 0; i < m; i++) {
		ll num; scanf("%lld", &num);
		use[num]++;
	}

	if (flag) {
		cout << "NO" << endl;
		return;
	}


	ll f[N][20];//st表记录区间最大值
	memset(f, 0, sizeof(f));
	for (int j = 0; j < 18; j++)
		for (int i = 0; i + (1 << j) - 1 < n; i++) {
			if (!j)f[i][j] = b[i];
			else
				f[i][j] = max(f[i][j - 1], f[i + 1 << (j - 1)][j - 1]);
		}

	sort(pi, pi + cnt);
	auto p1 = 0, p2 = 1;//进行区间合并
	while (p2 < cnt) {
		if (pi[p1].first != pi[p2].first) {
			p1++; p2++;
			continue;
		}
		else {
			int k = log2(pi[p2].second - pi[p1].second + 1);
			
			if (max(f[pi[p1].second][k]
				, f[pi[p2].second - (1 << k) + 1][k]) <= pi[p1].first)
				need[pi[p1].first]--;//st表查询区间最大值

			p1++; p2++;
		}
	}

	for (auto nd : need) {
		if (nd.second > use[nd.first]) {
			cout << "NO" << endl;
			return;
		}
	}

	cout << "YES" << endl;

}
int main() {

	int t; cin >> t;
	while (t--)
		solve();

	return 0;
}


»
2 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

n0sk1ll Regarding D, don't understand in editorial, why we need to keep l small as much as possible.

I used monotonic stack and I have kept l as long as possible unless it affects any B[i] such that razer < B[i].

https://mirror.codeforces.com/contest/1779/submission/237616405

»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

can anybody explain what is wrong in this solution (failed on 17 testcase) — https://mirror.codeforces.com/contest/1779/submission/316726659