Блог пользователя Erfan.aa

Автор Erfan.aa, 12 лет назад, По-английски

459A - Pashmak and Garden

Four vertices of a square with side length a (and sides parallel to coordinate axis) are in this form: (x0, y0), (x0 + a, y0), (x0, y0 + a), (x0 + a, y0 + a).

Two vertices are given, calculate the two others (and check the ranges).

Total complexity : O(1)

Sample solution: 7495194

459B - Pashmak and Flowers

If all numbers are equal then answer will be n * (n - 1) / 2, otherwise the answer will be cnt1 * cnt2, where cnt1 is the number of our maximum elements and cnt2 is the number of our minimum elements.

Total complexity : O(n)

Sample solution: 7495202

459C - Pashmak and Buses

For each student consider a sequence of d elements from 1 to k that shows the bus number which is taken by this student on each day. Obviously, there are kd different sequence at all, so if n > kd, pigeonhole principle indicates that at least two of this sequences will be equal, so that two students will become close friends and no solutions exist. But if n ≤ kd, then we can assign a unique sequence to each student and compute the answer. For computing that, we can find the first n d-digits numbers in k-based numbers.

Total complexity : O(n * d)

Sample solutions: 7495236

459D - Pashmak and Parmida's problem

First of all, we can map the given numbers to integers of range [1, 106]. Let li be f(1, i, ai) and let ri be f(i, n, ai), we want to find the number of pairs (i, j) such that i < j and li > rj. For computing lis, we can store an array named cnt to show the number of occurence of any i with cnt[i]. To do this, we can iterate from left to right and update cnt[i]s; also, li would be equal to cnt[ai] at position i (ri s can be computed in a similar way).

Beside that, we get help from binary-indexed trees. We use a Fenwick tree and iterate from right to left. In each state, we add the number of elements less than li to answer and add ri to the Fenwick tree.

Total complexity : O(n * logn)

Also we can solve this problem using divide and conquer method. You can see the second sample solution to find out how to do this exactly.

Sample solutions: 7495225 7495225

459E - Pashmak and Graph

In this problem, a directed graph is given and we have to find the length of a longest strictly-increasing trail in it.

First of all consider a graph with n vertices and no edges, then just sort the given edges by their weights (non-decreasingly) and add them to the graph one by one.

Let dp[v] be the length of a longest increasing trail which ends in the vertex v. In the mentioned method, when you're adding a directed edge xy to the graph, set dp[y] value to max(dp[y], dp[x] + 1) (because of trails which ends in y and use this edge). You need to take care of the situation of being some edges with equal weights; for this job we can add all edges of the same weights simultaneously.

Total complexity : O(n + m * logm)

Sample solution: 7495216

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

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

Thanks for the fast editorial!

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

Can you please include judge's code that will be great.

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

i donot understand the E's solution cannot u explain in more details ??

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

in problem c it think it will be k^d not d^k

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

thanks for nice editorial.

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

How can you get the n * (n - 1) / 2 formula in B (otherwise than by wolfram alpha)?

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

The solution of C(Pashmak and Buses) was awesome. Thanks a lot!!

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

I solved E with the same algorithm I get wrong answer in test 5 and don't know what's wrong ! this is my submission http://mirror.codeforces.com/contest/459/submission/7507479

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

Can anyone explain how to solve problem D using divide and conquer. I think the idea used in this problem is similar to finding the number of inversions in an array using divide and conquer.But, I am not getting how to solve it exactly..

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

in problem C,can someone please explain what the author means by "n d-digits numbers in k-based numbers."??

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

http://mirror.codeforces.com/contest/459/submission/11762173 can someone help me with optimizations.used the divide and conquer technique. my code is getting tle. thanks :) ShayanH

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

For problem:D..just use fenwick tree to solve it. its fun to solve it with fenwick tree :-) my submission :- 17314867

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

In problem C , Can anyone explain what does 'sequence of d elements from 1 to k' means in the editorial and how did we arrive to k^d , also how the pigeonhole principle is helping us here? Thanks. EDIT :- I solved the problem. Nice Editorial and Nice problem, I got it now. Thanks anyways.

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

    Each student can choose from k buses each day, so for each student there are k^d options to choose from for d days. Now there are total n students and we have to distribute these k^d options among them, if n>k^d, then at least two students will get exactly the same sequence for d days

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

Merge sort tree is getting MLE??Could someone tell me how to tackle this.My code : http://mirror.codeforces.com/contest/459/submission/36654409

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

Really good contest, with innovative problems. Here are all my solutions to the problems of this contest.

I liked C, especially the Pigeonhole Principle and I liked D for the data structures. I wrote an editorial on it here.

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

Why cant we use PBDS was problem D? it is giving me runtime error.. Can anyone explain me why ? Link to my solution- Your text to link here...

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

In E, what if we're asked unique vertices (No, I am not curious, I interpreted the question wrongly, thought about it around 3 hours, then realized I had read the question wrongly).

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

How to solve E when the edges are undirected?

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

I tried D with seg tree, got a TLE at tc 9, any help would be appreciated

My submission

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

D could be done even by persistent segment tree

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

Can someone explain why in C using first n d-digits numbers in k-based numbers is right?

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

    I'll try to explain.

    Let us define each student's bus information(required answer) for all the d days in array info of size d where info[i] = bus that this particular student took in ith day

    Observation -> For two students to be friends this info array of both the students should be the same.

    Now we can form at max k^d combinations of busses and take n combinations from this set and assign each to a student so that there are no friends.

    So it's not necessary to take first n d-digits numbers in k-based numbers, rather we have to take n distinct d-digit numbers in k-based numbers

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

In problem C, Can someone please explain or give some references to why the code for generating first n d-digit permutations in the editorial generates the required permutations.

for (int i = 1; i < n; i ++) {
        for (int j = 0; j < d; j ++) ans[i][j] = ans[i - 1][j];
        for (int j = d - 1; j >= 0; j --){
            ans[i][j] = (ans[i][j] + 1) % k;
            if (ans[i][j]) break;
        }
    }

Thanks in advance.

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

Can anyone help me in D. Pashmak and Parmida's problem, getting TLE on test case 17 when impl with seg 209582654. and what is the problem with this submission- 192035586 As this submission passes 192038110 Only by just changing the query process. Thanks.

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

In D: Pashmak and Parmida problem, why using coordinate compression and vectors does not give MLE whereas by just using map it gives MLE. What is underlying concept between memory usages in vector arr(1e6) and map of size 1e6 ( in case of distinct values).

Someone please clarify..