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

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

Hello, Codeforces!

I'm glad to invite you to Round 791 which will start at 14.05.2022 12:35 (Московское время). Please notice the unusual time.

There will be 6 problems in the round. Round is based on Team Olympiad in Lipetsk which is being held for the seventh time. Problems were proposed and prepared by iakovlev.zakhar, Kon567889, iura, andr1y, Masha237, welleyth and me. I would like to thank Aleks5d and KAN for CF round coordination and testers: Um_nik, 353cerega, errorgorn, Stepavly, divanik, nnv-nick, 4qqqq, to be continued...

Of course, I'd like to thank all Codeforces team for Codeforces and Polygon beautiful platforms!

I also would like to thank golikovnik, egneeS, dshindov and Inessa Shuykova (Lipetsk teams' coach) for preparing other Olympiad problems that haven't been taken for this round.

Thanks to NEAR for supporting this round, details can be found in this post.

Note that if you are an official participant of the Olympiad, you are not allowed to participate in this round.

Scoring distribution will be announced later.

Wish you good luck and high rating!

UPD.1 Scoring distribution: $$$500 - 1000 - 1500 - 1750 - 2250 - 3000$$$.

UPD.2 Congratulations to winners!

Official participants:

  1. xiaoziyaooo

  2. StickyFingers

  3. mybing

  4. huangweiliang

  5. NewPC2022

Unofficial participants:

  1. SSRS_

  2. leaf1415

  3. uwi

  4. maspy

  5. TripleM5da

UPD.3 Editorial is available here.

  • Проголосовать: нравится
  • +248
  • Проголосовать: не нравится

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

Team based round... interesting, will participate.

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

Users rated >= 2100 can't seem to register for the round?

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

I like when contests are at this time. (5:35 AM, Saturday for me) It forces me to not sleep in and be a lazy bum

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

hopeforces

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

Will the problems be a different style than regular rounds?

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

i see olympiad i upvote (unless its russian, then i just comment)

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

CF 791 -> ABC 251 -> Code Jam Round 2

No clashes with 20-25 mins break each. Sweet. Thanks for the unusual time :)

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

Is it only me, or does everyone feel that contest at an unusual time has less participation than the usual time contest? Hence have less probability for the rating to increase. I know we should not give contest for rating, but still...

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

This round will be hard. Good luck everybody!!!

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

How to know if a contest is unrated for me, I am new to the cf and could not find any official post on this info yet ?

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

The unusual time strikes back.

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

Why so unusual time? anyone any idea

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

Please add the contest link in the blog.

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

If the score is more than 2100, why do people with a score of more than 2100 participate in the ranking

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

"i_am_completely_useless for being completely useless." -- Sakura :))xD

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

Thank you for the unusual time!

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

excited for this contest, go go go !

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

Unfortunately, I need classes at that time, so I can't participate in this contest.

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

QueryForces

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

Pretests in C must be extremely weak

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

waiting for contest finish to get solution for problem E

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

Why Segment tree solution is giving TLE in C. :(

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

Used a single loop in Problem-B, still exceeded the time limit, is it me or python at fault here?

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

Thanks to iura for setting F! I really enjoyed solving it during testing. Here is my alternate solution to F that works for much larger constraints.

Let $$$S_i$$$ be sets containing all representatives of all arrays $$$a$$$ of size $$$i$$$ and $$$C_i$$$ be the set of cliques of size $$$i$$$. When we talk about clique, we are talking about cliques on the graph where we draw the edges as $$$(u_i,v_i)$$$. Also when we talk about arrays, we will basically refer to its equivalence class, so treat $$$a$$$ as the representative.

Take some array $$$a$$$ and let $$$s_a$$$ be the possible values of the first element of $$$a$$$ after some operations. Note that it is necessary that $$$s_a$$$ is a clique because otherwise, we are not able to swap all values in $$$s_a$$$ to the start of $$$a$$$.

Let us suppose that we know $$$S_j$$$ for all $$$j \lt i$$$ and now we want to find $$$S_i$$$. For all arrays $$$a \in S_{i-x}$$$ and $$$c \in C_{x}$$$,put $$$(c,a)$$$ into $$$T_{x}$$$. That is, we want to think about arrays $$$a \in S_i$$$ as the concatenation of some clique and another array. Unimportant remark: $$$c \subseteq s_{c+a}$$$.

However, the problem with this is that are multiple ways to make a certain array. As a simplest example, consider when we can swap $$$(1,2)$$$ only. To make array $$$[1,2,3]$$$, we can split it into $$$([1,2],[3])$$$, $$$([1],[2,3])$$$ and $$$([2],[1,3])$$$. Of course, we do not want to double count.

Let us consider some $$$a' \in S_i$$$ where $$$k=|s_a|$$$. There are $$$2^k-1$$$ combinations of $$$c+a$$$ that produces $$$a'$$$. Every subset $$$c$$$ of $$$s_a$$$ corresponds to a $$$(c,a)$$$ tuple, and there are obviously $$$\binom{k}{x}$$$ such subsets with $$$|c|=x$$$, so $$$\binom{k}{x}$$$ tuples in $$$T_x$$$ corresponds to array $$$a'$$$.

One can see that $$$|S_i|=|T_1|-|T_2|+|T_3|-\ldots$$$ by looking at the individual term of some $$$a' \in S$$$ and noticing when only considering tuples that correspond to $$$a'$$$, we have $$$\binom{k}{1} - \binom{k}{2} + \binom{k}{3} - \ldots =1$$$ on the right hand side. Note that by definition, $$$|T_x|=|S_{i-x}| \cdot |C_x|$$$.

Let the number of digits be $$$d$$$. If we let $$$ans_i$$$ be the answer for length $$$i$$$, we have the explicit recurrence $$$ans_i=\begin{cases} 0,& \text{if } i \lt 0 \\ 1, & \text{if } i=0 \\ \sum\limits_{j=1}^d ans_{i-j} (-1)^{j-1}|C_ j| & \text{if } i \gt 0\end{cases}$$$.

We can find all $$$|C_j|$$$ in $$$O(2^d)$$$ by brute force. To do this, we check if some mask $$$bm$$$ is a clique in $$$O(1)$$$ by taking an arbitrary bit $$$b$$$ from $$$bm$$$, checking if $$$bm \oplus b$$$ is a clique and that $$$b$$$ is connected to everything in $$$bm \oplus b$$$. Since we can solve linear recurrence in $$$O(d \log d \log n)$$$, we have total complexity of $$$O(2^d+d \log d \log n)$$$ but it probably does not matter what algorithm we use to solve the linear recurrence since there is no way it is going to dwarf the $$$2^d$$$ term.

Can we find all terms of $$$|C_j|$$$ faster than $$$O(2^d)$$$?

Code: 157227780

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

segment tree forces

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

n = 2 should have been in the samples in A :(
Btw, I wonder how many people solved B using segment tree

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

I tried to hack C with 2e5 queries and it said input cannot exceed 256kB, what T_T

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

how to solve c ? some one pls tell me your approach :* (i've tried to do it with brute force by making maps in the last 10 min I was knowing that it gonna get me tle :D ) so how can we solve it:*

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

    If you have at least one rock in a row set the row's value to 1. If you you have at least one rock in a column set the column's value to one. Now you wanna know if the sum of the columns in [x1,x2] is exatly x2-x1+1 or if the sum of the rows in [y1,y2] is exactly y2-y1+1. This can be easily done with a segment tree

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

      hey bro just need a favor from you basically you are a specialist you might be having a good idea about cp so can you tell me after seeing my profile and rating that should I learn segment tree or not cause some of my seniors were saying to me that to learn segment tree your rating should be at least 1500 or something but from last few contest I'm seeing that there is one question of segment tree between a,b,c and you might remember that div4 contest which just held few days ago in it also h2 problem was solved using segment tree so can u suggest me,that when should I learn about it or i should wait for few months :*

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

    Think of a way to maintain the empty rows/cols, after that when they ask you to check the subrectangle try to find if there is a row and a col that is empty and satisfy this condition: x1 <= row <= x2 && y1 <= col <= y2, if you found such a row and a column then the answer is no otherwise the answer is yes

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

    When a rook is inserted on (r, c) notice that it covers all cells on row r and col c

    Let's store for each row if it's already covered by a rook Do the same for columns

    Now the subrectangle queries ask if for each cell, either their row or their col is covered

    A subrectangle query consider a range of rows and cols

    What happens if a column is not covered ? Basically you need all the rows to be covered for the cells of this column to be covered

    (same argument in reverse)

    This way we show that the answer is "Yes" iff all the rows or all the cols are covered

    Let's say we put a 1 when a row is covered

    We just need to range sum over the range of rows and make sure the sum is equal to the length of the range

    Same for cols

    To handle rooks removal, we count for each row the number of rooks covering it

    When this count reaches 1, we add one in our segtree/bit

    When it reaches 0, we add -1

    Code: 157157585

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

How to solve D? My idea is to go through the nodes in increasing order and activate them one by one. Once I activate them I want to know if a strongly connected compononeted is activated, this means that I am done regardless of what K is. This is easy to do. The hard part was knowing whether a path that is K long in is created. How do you do it?

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

    The idea for D is fairly simple (and a good learning exercise if you aren't familiar with the "trick"). You just need to combine 3 independent pieces: Binary Search on answer, Cycle detection and Longest path in DAG.

    Since we are asked to minimize the maximum value of some quantity, it's natural to think in terms of binary search. However, this can be a trap if the function is not monotonic. To work around it, a clever way to define the predicate is to use the at least keyword. Instead of asking whether an answer with value val exists, we ask

    Does an answer with value at least val exists?

    With this keyword, it's fairly obvious that existence of at least val implies the existence of at least all value less than val as well.

    To verify a predicate, you can ignore all vertices with value > val while performing a DFS. (You might've seen this in problems asking you to find the maximum value less than threshold on a path between 2 vertices in a tree). After ignoring these vertices, if the resulting graph contains a cycle, it means you can travel it infinitely many times. If not, it is a DAG. Then, you just need to find the longest path on this DAG and verify if it's at least $$$k - 1$$$.

    Note that you can do all of this in a single DFS (and without explicitly creating the new graph).

    Code

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

    Binary search for the answer. And for each check, we could search for cycle or a longest chain in the new DAG, which we needn't really create a new graph but just judge the number on each vertex

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

    What exactly D asks for?

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

    We can use binary search to find the answer.

    When we are checking if there exists a path of length k with nodes whose values are less than or equal to 'x'(current binary search value), we consider the subgraph 'C' formed by the nodes whose values are less than or equal to 'x'. Now we have two cases. 1. There is a cycle in this subgraph C, the answer is true for this x in this case. 2. There is no cycle => subgraph is a DAG. Find max path length using DP and check if the max path length is >= k. The answer is true for this x if that is the case.

    Steps 1, 2 are of O(n) complexity each. We do them for a total of O(log(max(a[i]))). Therefore total complexity is O(n*log(max(a[i]))). code.

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

What was the approach for problem A ?

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

E was nice construction problem, I like it.

But whole contest was spoiled by unclear problem statements, except A there was not a single one I clearly understood. Had to decipher and guess the meaning of all texts, annoying.

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

me about to solve A in 6 mins.

1st error (Not considering the edge case of n == 2) be like: "I will make you pay"

2nd error (forgetting to return after printing -1) be like: "LMAO NOOB"

And that's how 'A' ruined my LIFE :)

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

Can anyone tell me why do i get TL in B

https://mirror.codeforces.com/contest/1679/submission/157177370 ?

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

thanks for the early end round,that i could see RNG's exciting game:(

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

This was a super cool round with nice algorithmic problems ! Congrats to the authors :D

Here is my advice about each problem

A
B
C
D

I didn't solve E/F so I don't really have an advice but they both look interesting

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

    how to solve d?

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

      Problems asking to minimize the maximum (or maximize the minimum) can be solved with binary search in 99% of the cases because fixing the max/min gives you a smaller structure where you have complete freedom (for example in this problem, you don't have to care anymore about whether you move on a too big node)

      So let's binary search over the maximum node you will walk on (I don't explain why you can binary search here but you can try to prove it as an exercise)

      Now we need to check if it's possible to find a path of length k (in terms of nodes) using only nodes with value <= MX

      Let's build a new graph. It'll be the same graph as the original one but only with nodes having value <= MX. We now want to find a path of length at least k. Notice that if the graph has a cycle, we can just keep moving in the cycle and get a path of length at least k. If the graph doesn't have any cycle, it's a directed acyclic graph and you can use dp to compute the longest path in it.

      Code: 157170838

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

Since I am poor in English, can anyone explain what is the difference between loops and cycles? Why "loop" is equal to "self-loop" instead of "cycle" in D?

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

Can anyone please explain a solution for Problem B? (without using segment trees)

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

Can someone please explain why I am getting TLE in C? https://mirror.codeforces.com/contest/1679/submission/157197783 I am using hashing to figure out when to add/delete row/column in sortedset(made using Fenwick Tree). And to find out if the whole sub-rectangle is there, I just subtract indexes with lower_bounds of x1,x2 in row sortedset and y1,y2 in column sortedset and compare it with difference of x1,x2 and y1,y2. It should be O(nlogn) but sadly it's giving TLE:(

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

Testcase 41 is on fire

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

so many fst on problem C and D..

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

Several stupid mistakes on A and D led to the terrible penality and the rapid descent of rank.

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

Sad to get FST on E :(

(my solution isn't the best solution so it got TLE on test 10.)

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

.

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

Problem E

Can any one explain why in input

2 ?? 1 ab

10 palindrome substring

(a, b, aa, bb, a, b which other?)

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

To not keep you waiting, the ratings are updated preliminarily. In a few days, I will remove cheaters and update the ratings again!

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

Can anyone tell me what's wrong with my code for Problem C. I was expecting a TLE but got a WA on the 27284th token!

It's in Go, but easy to understand. Uses 2 bool arrays for x and y and just loops over x1->x2 && y1->y2.

https://mirror.codeforces.com/contest/1679/submission/157188079

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

    If I add two rooks on same row and then remove one of them, in that case your code is considering that there is no rook on that row. Because of this

    mx[x] = false
    my[y] = false
    

    You should store frequency of rooks on particular row and col to resolve this

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

Can anyone tell what's wrong with my submission? Passed the pretests but failed on Test 10. https://mirror.codeforces.com/contest/1679/submission/157152675

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

write x<n instead of x<=n in the Fenwick tree and got fst on C. What a pity!

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

Problem b guarantees 1≤ai≤109 but why 0 appears in test6

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

Can anyone tell me why I got runtime error? my submissions

  • »
    »
    4 года назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится
    template <typename T>
    struct Fenwick {
        const int n;
        std::vector<T> a;
        Fenwick(int n) : n(n), a(n) {}
        void add(int x, T v) {
            for (int i = x; i <= n; i += i & -i) {
                a[i] += v;
            }
        }
        T sum(int x) {
        	if(x <= 0)return 0;
            T ans = 0;
            for (int i = x; i > 0; i -= i & -i) {
                ans += a[i];
            }
            return ans;
        }
        T rangeSum(int l, int r) {
            return sum(r) - sum(l);
        }
    };
    

    your code get an out of bound error when i == n (a[n] will out of bound).

    you should let your vector resize to n + 1.

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

Can anyone please find a test case where this code (157177615) fails. I have tried to come up with a failing test case but have had no success.

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

Why the system is testing again ?

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

What happened, why is task B being retested?

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

Thx the contest.Become Master at last!

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

who else had a rounding error in problem A haha

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

Thanks for the Problems . It was a pretty balanced round

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

我小号第一次进前一千!!!

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

Can someone see my solution for C I find nothing time consuming here. Can any minor changes make it acceptable.

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

can someone tell me how to solve D plz

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

Imao the limit on C has been too tight. Whether solution is accepted or not is up to constants and the judging machine. These two submits differ only in a tab (begining of main), however only one gets ACC: 157217055 157214568

(Played with it after the round so there might be some diffrence but the point remains anyway.)

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

Can someone please help me figure out what went wrong with my solution on problem C?

What i was doing is: - store how many free rows/cols we have upto a certain row lets say r and c (using 2 BITs)

  • when u place a rook at row r and col c, u reduce the number of free rows and cols at row r and c
  • when u remove a rook u add 1 free row/col
  • to check if all rows and cols in a certain range are under attack by a rook simply check if there are 0 free rows or columns in that range
»
4 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

public class C {

public static void main(String[] args)
{
    FastReader sc = new FastReader();  
    int t = 1;
    while(t-- >0)
    {
        int n = sc.nextInt();
        int q = sc.nextInt();
        boolean rows[] = new boolean[n];
        boolean cols[] = new boolean[n];

        outer:while(q-->0)
        {
           int type = sc.nextInt();
           if(type==1)
           {
             int x = sc.nextInt()-1;
             int y = sc.nextInt()-1;
             rows[x] = true;
             cols[y] = true;
           }
           else if(type==2)
           {
             int x = sc.nextInt()-1;
             int y = sc.nextInt()-1;
             rows[x] = false;
             cols[y] = false;
           }
           else
           {
             int x1 = sc.nextInt()-1;
             int y1 = sc.nextInt()-1;
             int x2 = sc.nextInt()-1;
             int y2 = sc.nextInt()-1;

             boolean done = true;
             for(int i=x1;i<=x2;i++)
             {
              if(!rows[i])
              {
                  done = false;
                  break;
              }
             }
             if(done)
             {
              System.out.println("Yes");
              continue outer;
             }
             done = true;
             for(int j=y1;j<=y2;j++)
          {
              if(!cols[j])
              {
                 done = false;
                 break;
              }
          }
             if(done)
             {
              System.out.println("Yes");
              continue outer;
             }
             System.out.println("No");
           }
        }

    }
}

// Can anyone help me figure out the test case, where this solution would fail?

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

Can someone tell me why my solution of Problem C is giving WA on Test Case 3?

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

For some reason I couldn't come up with using segment tree for C, instead I used a complicated data structure that contains every consecutive segments. I believe it is useful for some specific problems, but it was an overkill for this problem. It is implemented with a set<pair<int, int>> where each pair represents the endpoints of each segment. Each operation is implemented in these ways:

  • To insert a new element x, check if there is a segment that contains x-1 and x+1, respectively. If a segment [l, x-1] exists, remove it and insert [l, x]. If a segment [x+1, r] exists, remove it and insert [x, r]. If both exist, remove both and insert [l, r]. If none of them exist, just insert [x, x]
  • To remove an element x, search for a segment [l, r] that contains x. Remove this segment, and insert [l, x-1] and [x+1, r], if l != x and x != r, respectively.

Every operation can be done in $$$\mathcal{O}(\log{n})$$$ time. Searching for segments around x can be done with set::lower_bound or set::upper_bound and decrementing the iterator if needed.

AC code: 157170732

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

Can someone suggest similar problem like D

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

Can someone please explain why my solution from problem C is giving TLE. 157292933

Thanks

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

My video editorial: https://youtu.be/Qa9gabukKqg

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

With 1 minute and 30 seconds left in the competition, tourist got to the first place by a hack. Cool!

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

Should not ratings be updated again for this contest? At contests page I got 894 place but at official standings 883 place.
Check out your own