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

Автор ilya_the_lamer, история, 9 лет назад, По-английски
Tutorial is loading...

Author: s17b2_voroneckij Development: s17b2_voroneckij

Tutorial is loading...

Author: akvasha Development: akvasha

Tutorial is loading...

Author: akvasha Development: akvasha , ilya_the_lamer

Tutorial is loading...

Author: ilya_the_lamer Development: ilya_the_lamer , akvasha

Tutorial is loading...

Author: platypus179 Development: platypus179

Tutorial is loading...

Author: platypus179 Development: platypus179

Tutorial is loading...

Author: KAN Development: platypus179 , ilya_the_lamer , akvasha

Разбор задач Codeforces Round 395 (Div. 1)
Разбор задач Codeforces Round 395 (Div. 2)
  • Проголосовать: нравится
  • +32
  • Проголосовать: не нравится

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

can someone please explain the problem statement of DIV 2 C more precisely?

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

Editorial for Div.2 D???

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

Thanks for such great problems, I enjoyed from solving them :)

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

Can anybody expalin Div2 D please...

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

    We may assume that our rectangles are drawn on an infinite sheet of squared paper. Divide it into squares 2 × 2 and mark the cells in each square by 1, 2, 3, 4 clockwise starting from the upper left corner. Since both sides of each rectangle are of odd length, its corner cells are marked by the same number. Let us number four different colors by 1, 2, 3, 4 and paint each rectangle with the color whose number marks the corner cells. It is readily seen that the numbers in the corners of any two adjacent rectangles are distinct.

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

problem E can be solved in as well with MO's Algorithm + DSU with rollbacks and adding the border edges by brute.

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

763C — Тимофей и перемодулирование Sorry for stupid question,

How it calculated??

This is right: x % k mod (m) == x*k1 mod m, where k1*k == 1 mod m ==> k1 == k^(m-2) mod m??

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

Please give some more explanation for Div-2 D.

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

    Since sides of all rectangles are parallel to x and y axis only there can not be 4 or more rectangles which touch each other therefore solution always exists. Now since side lengths are odd therefore one of x1 or x2 is odd and other is even same goes for y (one can check by drawing in x,y plane) . For rectangles with x1 odd, since its x2(end) is even its neighbors will always have there x1(start) as even (they cannot have same color) and the same goes for y.Therefore 4 possible combinations are possible for x,y -> odd,odd even,odd odd,even and even,even. Hence the solution.

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

for div 2 C , wont the given editorial give a time complexity of O(n^2).... if each vertice is coloured differently, then it will do dfs from each of the vertice ...? or i understood the solution incorrectly.. B-)

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

    No, the answer will have complexity of O(n).

    1. We iterate over all edges to find one edge that connects different colored nodes — O(n).
    2. We check if one of those nodes can be the answer. How do we check it? We use DFS — O(n). So we end up with O(n) + O(n) + O(n) = O(n) complexity.
    • »
      »
      »
      9 лет назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      There can be more than one edge connecting different coloured vertices eg. 1->2->3 and c[i] is same as vertices number , then we can hold by two...similarly if there were many coloured vertices ,I would have to dfs it those many times according to the editorial....atleast that's what I understood ☺☺

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

      I can't understand how to promise that a subtree doesn't annoy him if there are vertices of same color in it, please explain this sample: 4 1 2 2 4 4 3 1 1 3 2 YES 4 But in 4's subtree, the color of 3 and the color of 1 or 2 are different

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

problem C Does it really necessary to solve it in two case? when we choose some element y,then we check if y-d,y-2d,...,y-kd belongs to A until it not or k=n-1.Then,the same,check y+d,y+2d,....,y+kd.Because what we check is continous,it's "safe" and easy to find the value of the first element.

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

Edit: got it!

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

Can someone explain 763C more elaborately? I am unable to understand it.

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

Div1.C Please explain why we consider the case 2*n>m? I don't understand

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

    Note that an arithmetic progression of m terms are all distinct mod m if we have (d,m)=1. So if the given set forms an arithmetic progression, so does the complement of it.

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

    I noticed that I misunderstood your point, thanks to Ismll. :) So let me answer your question again: If we do not consider the case when 2*n>m, the following statement is not true.

    On the other hand, x must be difference of exactly n - k + 1 pairs of elements of A. (Actually, I think that this should be n-k)

    This is due to somewhat number theoretic reason. It is like, let me say, an overflow mod m. For example, let x = 3*d (i.e. k=3), n = m-2. The pair (s, s+(n-1)d) should not be counted, but it is counted since s = s+(n+2)d mod m. However if 2*n<m, this does not happen.

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

    More precisely, we should consider the size relation between 2n-3 and m, rather than 2n. As jo_on put it above, overflow mod m may happen in some situation. In fact, the boundary condition is that the sum of the two largest differences(in absolute value) of element pairs equals to m*d. That is pairs (s,s+(n-1)d) and (s,s+(n-2)d), whose sum of differences is (2n-3)d.So we should consider the size relation between 2n-3 and m. Once 2n-3<m, the insecurity, namely overflow mod m won't happen.

    In short, when 2n-1=m, the case must be safe.In practice, whether 2n or 2n-3, both of them can get accepted.

    Ps: My AC code with 2n 24488586 and 2n-3 24491759.

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

My algorithm for Div. 2 C was exactly the same.

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

Can anyone give an easier-to-understand explanation for Div1-C? I still don't understand how to deal with modulo m operation.

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

Weak cases in Div2C

4

1 2

2 3

3 4

5 3 2 4

My AC code gives YES but correct one is NO

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

From a problemsetting perspective, I'd like to ask ilya_the_lamer about how you wrote a checker for this problem, and how this affected the system testing.

By the way, writing the checker surely seems harder than the original problem, and I'm assuming you wrote a n log n (take all the rectangles of some color, do horizontal/vertical segments independently, check for overlap). I wonder how running O(n log n) for n=500000 on ~50 test cases for a bunch of programs affected this system testing. It seemed pretty fast to me, just curious how it ran so fast in this way!

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

    We used 2 scanlines to build graph, and then just simply checked, that there is no edges with same-colored vertexes. As you correctly mentioned, this works in .

    I can share you checker, if you are really interested in it.

    What about fast working, most of the solutions, that used wrong idea, didn't pass small pretests (n near 100), so testing on big tests didn't even start in most cases.

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

Although I couldn't submit it during the competition (and honestly it took to long to code to be practical for myself), I have a very different number theoretical approach to 763C - Timofey and remoduling. The problem is effectively to find x and d such that {a[0],a[1],...a[n-1]} = {x,x+d,...x+(n-1)d} (mod m). We solve this using the sum and sum of squares to create a quadratic equation of either x or d, confirm the existence of a solution with the Legendre symbol and use Cipolla's algorithm to find the solutions if they exist. There are at most two, which we can confirm in O(n log n).

In order to meet the conditions for which this algorithm can work, we consider only m which is odd and n<m-1. While there is no deterministic way for solving an arbitrary quadratic equation, it can easily be transformed into y^2 = k (mod m) where the Cipolla algorithm allows us to solve with approximately 1/2 probability for each random number. So, the expected value is 2. The overall complexity is O(n log n + k log m), where k is the number of tries in the Cipolla algorithm. It can be quite high for the problem conditions, so although there is a probability for failure, it is very small.

Submission: 24420260

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

    Nice solution! And in fact, you can simply try all a[i]-a[1] as d and find x with x+(x+d)+...+(x+(n-1)d) equals to the sum of the elements. As you have said, there are at most two pairs (x,d) which satisfy x^2+(x+d)^2+...+(x+(n-1)d)^2 equals to the sum of square. So we can check these two pairs by brute force.

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

      Wow. I actually realized we can easily reduce the candidates for d to n-1 candidates without additional calculations but I didn't think to use that in conjunction to this approach. This approach has a far simpler implementation.

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

    May I ask why you said that "There are at most two"?

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

      Assume there is a solution y which is not x ≡ y or x ≡  - y. Then p|x2 - y2 = (x + y)(x - y) is not possible as (x + y, p) = 1 and (x - y, p) = 1. More generally the number of solutions of a modular n-th order polynomial equation is bounded by n (Lagrange's theorem).

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

Can somebody please explain Div 1C? I am unable to understand the solution.

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

Regarding Div1 B about coloring rectangles: is there any reasonable way to solve the problem just by looking at the connectivity graph and not by taking advantage of odd side lengths?

Btw. this problem is genius IMO, thanks ilya_the_lamer!

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

763E — Timofey and our friends animals

aren't we storing O(N) values?

hoping not to say something stupid: let be f(n) the number of node needed by a segment tree with lenght n f(1) is clearly 1; //himself f(n) = 1 + f(floor(n/2)) + f(ceil(n/2)); //himself + left son + right son

we can simply prove that this lead us to f(n) = 2n-1;

if i didn't understand, can you please explain me why? thanks

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

Model solution provided in editorial gets AC; at the same time it is not clear to me how segment gluing is being done there, and for example on test

16 4
6
8 9
8 10
9 11
11 13
10 12
12 13
1
8 13

it says 0 :)

P.S. And I also started to believe that a nice O(N*K*K) solution works here as well (like 24603977), but this one gives 2 for

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

In Div2E/Div1C, I don't understand the following statement:

"On the other hand, we have that n is less then m/2, so x must be difference of exactly n - k + 1 pairs of elements of A."

Formally, why the following holds?

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

Can someone please look into issue for Div1 E Timofey and our friends animals: http://mirror.codeforces.com/blog/entry/52419

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

In Div2 E Timofey and remoduling, I think author's solution code is wrong It can't answer for this simple input. 8 3 0 6 7 Results should be 6 1 but author's code stucks in somewhere.

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

For Prob Div2C Just have a look at my code it's pretty simple and clear. https://mirror.codeforces.com/contest/763/submission/89345877

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

I dont know if anyone has solved Div1 A (763A) this way or not. (The concept is root changing)

I just took the root as 1 intially and checked if it is possible for that root to have a value by checking (No. of subtree nodes)*(value of one of the immediate child of the root)==(sum of the values in the subtree), If not then shift the roots.

For better understanding you can check my solution here.

Solution by the method explained

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

Smh , tried Div2C with tree rerooting , got TLE

tried with an additional constraint on rerooting and got AC.

sub: 309746515

pfft why do I have to make things complicated :/