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

Автор vovuh, история, 8 лет назад, По-русски

1042A - Benches

Разбор
Решение

1042B - Vitamins

Разбор
Решение

1042C - Array Product

Разбор
Решение

1042D - Petya and Array

Разбор
Решение

1042E - Vasya and Magic Matrix

Разбор
Решение

1042F - Leaf Sets

Разбор
Решение (O(n log n))
Решение (Small to Large, O(n log^2 n))
Решение (O(n))
  • Проголосовать: нравится
  • +57
  • Проголосовать: не нравится

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

so fast :/

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

gone in a flash :o

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

Wow, I failed C because of writing >= 2 instead of >= 1

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

Loving the quick editorials !

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

F*cking Monikaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa........

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

Back to Back contest. And Back to Back fast editorial. I'm loving it.

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

I'm loving quick editorials. Really helpful.

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

    Hey can you please explain the line "It's easy to see that the answer for the fixed L is n∑R=Lpref[R]<t+pref[L−1]. We can calculate this formula using some data structure which allows us to get the number of elements less than given and set the value at some position. "?

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

fast as always

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

For F,(untested)

I was thinking of fixing the centers of subtree formed by the leaves. For fixing centers, we greedily move from lowest to highest depth(from bottom to top) and pick centers when necessary. Also to avoid problems, we can assume k is even (If not add some dummy vertices and make it even).Now from a center we want distance to farthest not yet taken leaf node to be k/2 (which is what I mean by when necessary).

Does this work?

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

Задача Д https://algotester.com/en/ArchiveProblem/Display/40362 Надеюсь, что это совпадение

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

I really hope that no one will fst!

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

Got TLE on testcase 68, coz of using cout,cin DAH! :((((((

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

Got TLE on tc 68 of C , DAAAAAAAH!

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

Got TLE on tc 68 in C, DAAH! :(((((((((((((((( .

.

.

.

.

.

.

Because of cin,cout DOuble DAAH! :(((((((((((((((((((

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

Can anyone explain me solution to Problem D?

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

can someone help me generate some hacks for my C solution 42986208 it looks quite similar to editorial

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

In F, I get AC by following greedy algorithm but I don't know why it can get AC:

Let the center of the tree is vertex c.

Let the leaves are x1, x2, ...xm and dis(x1, c) ≥ dis(x2, c) ≥ ... ≥ dis(xm, c).

for i from 1 to m:
    if x_i is not selected, make all vertices y that are not selected and dis(y,x_i) <= k be a beautiful set.

Can someone prove or disprove it >__<?

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

IN array product my answer fails on 7 th test case . but i think my code is right.

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

http://codeforces.me/contest/1042/submission/42995015

Please, Can someone see my solution? Codeforces says wrong answer but it is producing output as expected.

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

    Your logic is incorrect, you are forgetting that you cannot move the people who have occupied the benches, hence not necessarily you can make equal people sit on all the benches to find the minimum.

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

    I think your solution is wrong

    Here is the sample 2 3 1 10

    The answer is 10 13 Your code output 7 13

    Cause the three people can sit on the second bench

    So for each time where not all the people were sat , should find the min people of all bench and let this person sit here

    ( people who is already sat can not move , maybe you should read this problem again :)

    Hope this can help you

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

Am I the only one who thought of DP at the first glance of B?

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

Could anyone please explain for me the basic idea of F. It is not so vivid to me. I understand the technique here but the idea....

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

By the way, how to write the judge code for problem C? (I think this is not trivial.) Does anyone have an idea?

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

Why does this D solution gives TLE on 46 test case?

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

I have another solution for problem D(Petya and Array) which doesn't need any data structure and I think it is really easier. It's using the merge sort.

let the given array be a. we make array A such that A[0]=0 and for i>0 A[i]=A[i-1]+a[i-1]. (it's the partial sum!)

now we must find number of pairs i,j (0<=i<j<=n) such that A[j]-A[i]<t . now we run merge sort on array A this way:

void Sort(int l,int r){
    if (r-l<2) return ;
    int mid=(l+r+1)/2;
    Sort(l,mid);
    Sort(mid,r);
    for (int i=l; i<mid; i++){
	ans+=(lower_bound(A+mid, A+r, A[i]+t)-A) - mid;
    }
    merge(l, mid, r);
}

explanation: in fact I am using divide and conquer. this algorithm at each time splits the given array into two arrays and counts the number of such pairs and sorts them. then it counts the number of pairs between the two sub arrays. and to count the number of pairs between two sub arrays it does the following: first we know the two arrays are sorted (we are using merge sort!); so we can use binary search on them! for each element A[i] in the first piece we can count the number of elements A[j] such that A[i]+t<A[j] using binary search!

time complexity of this algorithm is O(n * log^2(n)). my code: 43010896 It got AC in 156 ms. (I think if I have used scanf instead of cin it would be also faster) :)

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

Can any one explain me what am I doing wrong in question C? I am continuously getting wrong answer verdict on test case 7.

My solution link is:-

http://codeforces.me/contest/1042/submission/43011863

Thanks in advance

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

About Problem E, what is the "real" answer for sample case 2 (that can be represented by a rational number P/Q?

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

    It is .

    There can be some paths, with their respective possibilities:

    • (1, 2) → (1, 1) — probability of , final score of 1

    • (1, 2) → (2, 3) — probability of , final score of 2

    • (1, 2) → (2, 1) → (1, 1) — probability of , final score of 3

    • (1, 2) → (2, 1) → (2, 3) — probability of , final score of 6

    • (1, 2) → (2, 2) → (1, 1) — probability of , final score of 3

    • (1, 2) → (2, 2) → (2, 3) — probability of , final score of 2

    • (1, 2) → (2, 2) → (2, 1) → (1, 1) — probability of , final score of 3

    • (1, 2) → (2, 2) → (2, 1) → (2, 3) — probability of , final score of 6

    To summarize, the expected answer will be: .

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

      Hey Akikaze, can you tell me what evi is, in the tutorial of E?

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

      Why can't we calculate for [r, c] all the possible jumps from it to all the elements with value < val[r, c]? we ((sum them up) / number of such elements < val[r,c])? And similarly for all the other elements < val[r, c], summing them up until we no more find element < val[i, j]?
      (By summing them up, I mean summing the euclidean distance between them.)
      Here is my code. Would be awesome if somebody cleared this doubt.

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

Failed on tooooo many troubles. Sad.

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

can someone explain the part in D's editorial how segment tree or fenwick tree can be used

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

For the problem D, anyone can explain more details for me please. What do we do when call upd(k)?

int npos = upper_bound(sums.begin(), sums.end(), pr - T) - sums.begin();
ans += (i + 1 - get(npos - 1));
		
int k = lower_bound(sums.begin(), sums.end(), pr) - sums.begin();
upd(k);
  • »
    »
    8 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +1 Проголосовать: не нравится

    It's actually bad editorial. It's hard to understand ( cost me one day )

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

      This is similar to the Inversion number problem, formally:

      Given an integer sequence A which consists of N elements, count the number of pair (i, j) where i < j and A[i] > A[j] are satisfied.

      It is known that this problem can be solved with BIT. The strategy is like:

      1. S = [], ans = 0
      2. iterate j from 0 to N - 1, and do A), B), C).
      3. A) calculate the number of elements in S which is less than A[j]. Let this number be x.
      4. B) add j-x to ans
      5. C) add A[j] to S
      6. print ans

      The important part is A). if you count this value with straight forward algorithm, it will work in O(number of elements in S). To get this value efficiently, we can use BIT.

      BIT provides these operations:

      1. add(i, x): v[i] += x; (in the tutorial code, upd(i) := add(i, 1) )
      2. get(i): return v[0] + v[1] + ... + v[i]

      O(N) memory is required and both operation can be done in time (where N is max i).

      Treating A[j] as i, we can perform A) and C) operations using BIT, like A): get(A[j]), C): add(A[j], 1)

      But there is a problem: A[j] can be big and it will cause MLE...

      So, we have to pre-calculate k, such that A[j] is the k-th smallest number in A. (This can be done with sorting, unique the array and calling lower_bound)

      After that, we can use k instead of A[j] for BIT.

      This solution works in where N is the number of elements in A.

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

Solution (O(n log n)) has some problem for this data.

14 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14

this solution's answer is 2.
this is incorrect, yes?

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

I solve D with wavelet tree, then realise the operation I use can be done with simple coordinate compression and fenwick tree.

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

Problem F, the constant of O(n) solution is so large that the real runtime between O(n) and O(nlogn) is similar. (1076ms for O(n), 1091ms for O(nlogn))

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

I think there is a bug in answer checker for problem Array product In the sample test case

4

0 -10 0 0

jury's output is

1 1 2

1 2 3

1 3 4

which is 0

My output is

1 4 1

2 1

1 2 4

which also makes it 0.

So why is it wrong answer?

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

Every time I read the editorials I think I need to put lot more effort

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

Problem D can be solved with STL's red-black tree implementation (https://codeforces.me/blog/entry/11080): http://codeforces.me/contest/1042/submission/43157263.

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

Can someone please tell me what is the bug in my code (http://codeforces.me/contest/1042/submission/43167869) for problem D. I used sqrt decomposition technique and am not able to find any bug myself. My logic is basically to find all the r>=l for every l.

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

In problem F, why the greedy algorithm is correct ?

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

How can we do D(Petya and Array) by using merge sort ?

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

In prob D: In pbds solution can anyone tell me why we need pair in ordered_set? I think it should be ok without pair. Details explanation would be great.

Thanks in advance :)

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

For D, Why does Multiset Time out?

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

in Problem F, a very important part of the proof is not mentioned in the editorial. Lemma: for each subtree, if $$$A$$$ and $$$B$$$ are any two sets which cannot be merged, then $$$dA+dB > k$$$. We can prove this by induction on height.

The reason this is an important part of the proof is that when we merge subtrees, we may ask, can't any other possible combination of sets be possible? It is not, because the lemma implies that the way to divide the leaves into sets is unique upto the height of the maximum element in the set ($$$dA$$$ and $$$dB$$$ can't be in the same set).

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

Even unoptimized $$$\mathcal{O}(N logN^2)$$$ solution can work comfortably in $$$1400$$$ ms: 160761034