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

Автор Tommyr7, история, 9 лет назад, По-английски

Hi, all!

This is not Tommyr7, but the impostor behind the round (guess who I am? :P). The statements are written by me. The characters in the round feature, again, the Monogatari anime series, and to be more specific, Nisemonogatari: Fake Tale. The statements involve stories with fake things and oddities, but as per tradition, contain no spoilers. Thank you, everyone, and hope you've all enjoyed the round!

On a side note, special kudos to the best impostors of the round (except me, lol)!

Any feedback on problems and tutorials are welcome -- we look forward to doing even better in the future!

Here are hints for all problems and detailed tutorials!


Hints

Problem A
Problem B
Problem C
Problem D
Problem E

Tutorials

869A - The Artful Expedient

Author Tommyr7, cyand1317 / Preparation Tommyr7, cyand1317 / Tutorial cyand1317

Tutorial
Solution 1 (Tommyr7)
Solution 2 (cyand1317)

869B - The Eternal Immortality

Author Tommyr7 / Preparation Tommyr7 / Tutorial cyand1317

Tutorial
Model solution (Tommyr7)

869C - The Intriguing Obsession

Author Tommyr7 / Preparation Tommyr7 / Tutorial Tommyr7

Tutorial
Model solution (Tommyr7)

869D - The Overdosing Ubiquity

Author quailty / Preparation quailty / Tutorial quailty

Tutorial
Model solution (quailty)

869E - The Untended Antiquity

Author Tommyr7 / Preparation Tommyr7, cyand1317, visitWorld / Tutorial cyand1317

Tutorial
Solution 1 (visitWorld)
Solution 2 (Tommyr7)

Tommyr7: I do hope you all enjoyed yourselves during the contest. See you next time!

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

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

Maybe swap D and E will be better

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

I know the answer is always Karen but could someone tell me how this gives a wrong answer? It seems super simple so this is driving me a tad bit insane

n = int(raw_input())
x = map(int,raw_input().split())
y = map(int,raw_input().split())

numbers = set(x+y)

count = 0
for i in range(n):
    for j in range(n):
        if x[i] ^ y[i] in numbers:
            count += 1

if count % 2 == 0:
    print "Karen"
else:
    print "Koyomi"
»
9 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

why A div2 get TLE with map

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

.....

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

For me, my solution in problem A is the shortest that I have ever done in Codeforces

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

Can someone please explain the following solution: http://mirror.codeforces.com/contest/869/submission/31075785

Is it some kind of range update on 2D BIT?

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

There is a tiny mistake in the editorial. For problem A, it is 2·106 instead of 2·105, so the size of array should be at least 221 = 2097152.

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

Regarding problem A: during contest several participants raised the doubt that the number of pairs in sample 2 should be 20 instead of 16. Would anyone mind explaining the reason? :)

Upd. Figured it out. When you write i ^ j instead of x[i] ^ y[j] you get the answer 20.

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

I want to know why A di2 TLE with map :(

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

Anyone can tell me how you guys managed to use the idea of randomization for problem E? I can see a lot of submissions using this idea.

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

Please help me! For problem A, why did my solution give WA on test case 4? I though of the fact that if (x,y) satisfies the property, then so does (y,x). Hence for x!=y, the count will always be even. So I just calculated the count for all x=y cases. Here is my code: https://pastebin.com/XqRjHbBL

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

Well because all the answers in the first question is "Karen". Completely wrong code also got A/C :p :p .31069801

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

Can anyone explain solution of the problem C?

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

    I will explain mine, but I am not sure that it is the expected solution.

    You can check my code here: 31079668

    For me, the most important piece of information from the statement (apart from constraints, heh) is the following:

    For any two islands of the same colour, either they shouldn't be reached from each other through bridges, or the shortest distance between them is at least 3

    Let's think about what this constraint is imposing and lets enumerate the impositions:

    1) There can be no edge between two islands of the same colour. Why? Because if there was an edge between two islands of the same colour, their shortest distance would be 1, which is less than 3. Good! this means that we only need to consider edges between islands of different colours. We even have an upper bound right now: 2ab × 2bc × 2ac (the product of all possible subsets of edges between islands of different colours). In fact, this is the very first formula I tried.

    2) There can be no pair of islands of the same colour ai, aj such that they both have an edge to the same city of different color bk. Why? because if they had, then the shortest distance between ai and aj would be 2, which is less than 3. This second fact is the cause that makes the previous formula to give an upper bound, but not the correct amount.

    So, with these observations we can conclude that there is no need to consider the three colours at the same time, it will be enough to compute the product of the number of possible edge configurations between all the possible pairs of colours. The problem is that the formula is not as direct as a power of two or something similar, so let's think about it.

    Let's try to build a function f(r, b) that tells us in how many ways we can connect r red islands with b black islands without violating constraints. The base case for me is f(0, b) = f(r, 0) = 1. The non-base case is f(r, b) = f(r - 1, b) + b × f(r - 1, b - 1). Why? f(r-1, b) is the number of ways that you get if you ignore the rth red island. If we want to connect the rth red island with some black island we have b choices, so we must add the amount b × f(r - 1, b - 1). Note that we only need to consider where we put a single edge, because more than one edge from the rth red island to the black cluster would imply a violation of constraint 2. Given that a, b, c ≤ 5000 we can compute this formula with dynamic programming. Also, we are ignoring intra-cluster edges, as they would violate constraint 1. I hope that this convinces you enough about the correctness of the formula.

    Once we have these values computed, we must output f(a, b) × f(a, c) × f(b, c).

    I am not very sure if this solution was the expected one given the time it takes to complete a single test case and the time limit. Even if it is in java, I am not 100% sure.

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

Did anyone actually used the solution for A that prints "Karen"?

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

Is there any deterministic solution for E?

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

Auto comment: topic has been updated by Tommyr7 (previous revision, new revision, compare).

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

Where can I find more counting/combinatorial problems like C? I can never get the idea in-contest, and its hard to find more of them to practice

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

Auto comment: topic has been updated by Tommyr7 (previous revision, new revision, compare).

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

Auto comment: topic has been updated by Tommyr7 (previous revision, new revision, compare).

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

Auto comment: topic has been updated by Tommyr7 (previous revision, new revision, compare).

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

Auto comment: topic has been updated by Tommyr7 (previous revision, new revision, compare).

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

This is my first Codeforces contest and I have doubts regarding Tommyr7's solution to Problem C.

  1. Why is the value of Maxn 5007 (The constraint is 1 <= a,b,c <= 5000)? Souldn't it be 5000?

  2. Also, why taking %modp at every step is necessary?

  3. When dealing with factorials and combinations, is it a norm to store the values in advance for fast calculations? I am quite intrigued by the beauty of the code.

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

    Thanks for supporting my contest. Here are my answers: 1.Well, 1<=a,b,c<=5000 is true, but you know sometimes your program gets an RE if you just use array size of 5000 (if you have some operations like a[i+1]), it's a good habit to make the size of array a little bigger. (Just a little is needed) 2.It's unnecessary. But sometimes if the answer is too large, a multiplies b may get WA (two very large integers may get an answer less than 0). For example, (1e12)*(1e12) will get WA. So, talking %modp at every step is also one of my habits. (Of course, it's not necessary) 3.Actually, it's not necessary again. But, store the values in advance can make me clear what I should do next. I don't need to be careful about the combination values if I have stored them in advance. This can make me have more possibility to get Accepted or I can code it faster.

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

I think the problem D is actually the hardest one.

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

Auto comment: topic has been updated by Tommyr7 (previous revision, new revision, compare).

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

I want to learn about quad trees and also want to solve some good problems of quad trees. Please share the links of some good tutorial on quad tree, and the links to some good problems ! Thank you !

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

869B — The Eternal Immortality ,// the Tutorial of this question said "and it's not hard to prove a tighter upper bound of 5." hence my understanding is the maximum Output is 5? but i want to give a example ,such as ,if the Input is 0 3 ,then Output should be 6 ,but the tutorial said "a tighter upper bound of 5" so it exceed the bound 5..... my point of view...

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

You have typo in word "Suppuse".

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

I probably misunderstood E, but why can't we use 2D segment tree in the next way: 1: set square [r1,r2]*[c1,c2] to unique value 2: set square [r1,r2]*[c1,c2] to same value as (r1-1, c1-1) 3: check if (r1, c1), (r2, c2) have the same value?

Thank you!

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

I was confused that problem E why has to be randomize? I try to replace

if (t==1)
     del.first=rand();
     del.second=rand();

with

if (t==1)
{
	del.first=i;//the iterate index
	del.second=i;

I submit this a little bit different solution and this pass 19 test,and fail in test 20. I think it may be different set of number has the same sum,but in this situation,the collission probility may be not 2-64.

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

In problem E for the BIT solution,why is probability of collision 2^-64 ? Suppose a certain cell belongs in region 1 and 2, and there is another cell that lies in region 3. If we were to query whether a path is possible between them, the output would be Yes even though it was supposed to be no, and there was no repetition in random number generation

Intuitively I feel that the probability of collision is still extremely low, but I am unable to prove it. Can anyone pls help me?

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

    Let's assume you assign 64-bit random value for each rectangle. If you want to check reachability for two points you can calculate xor of covering rectangles. If this values aren't equal — points aren't reachable for sure. Otherwise there can be a collision. Let's estimate its probability. One can observe that bits of values are in fact independent. For one bit: this bit will be equal in two calculated numbers with probability (xor of any non-empty set of bits is either 0 or 1 with equal probability, because and and we generate bits with equal probability too). So we obtain probability of collision.

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

The following is a GNU C++11 solution for problem 869E - The Untended Antiquity:

31224413

The solution uses a rectangle_tree class whose root node is the entire 2500 x 2500 area. The children of each node (u) in the rectangle_tree are the largest non-intersecting rectangles contained in (u). Insertions and deletions update the tree according to inserted/deleted rectangles. A walk query returns "Yes" if and only if the smallest rectangles containing the source and the target cells are the same.

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

A way can be there in total ways or not when there is no bridge among any islands?

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

in problem E : " the creation/deletion of a barrier is equivalent to adding/subtracting/xoring a value to all cells in a rectangular region".

can anyone please explain (or give some links) how range updates works in 2D segment trees or 2D BIT !

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

hello ,

i know i didn't totally listen to the editorial but i don't understand why my implementation could be wrong and why i get WA at test 9 on problem E.

My implementation is 33746043.

i thought about keeping the square in which my element 1 and element 2 are and i am keeping it using a global variable k which i use to mark the square in which my element is. i am introducing new squares by increasing k and marking with it, removing a square with a matrix whatwasthere and marking with the value of whatwasthere[line][column] of the first element of the query , and display yes when the square in which the first element is meets the square in which the second element of the query is

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

Problem B was outstanding. Thanks Tommyr7