Thank you for participating!
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Thank you for participating!
Name |
---|
Thanks for the fast editorial!
I am having a little problem in D. Its working on nearly all the test cases and logic is to point. But I think there is some problem with modulus and its giving wrong answer on one test case-v 179 1000000000000000000 Can any body help I cant seem to figure it our. This is my code where maxi is modulus ll l,r; cin>>l>>r;
ll te=l; ll ans=0; while(te<=r) { ll p=log2(te); ll up; // if(p==63) // up=r; // else up=min((ll)(pow(2,p+1)-1LL),r); //cout<<up<<endl; ll ct=0; ll x=1;
while(x*p<=te) { x*=p; ++ct; } // cout<<te<<" "<<x<<endl; while(true) { ll nx; //cout<<x*p<<e ndl; x*=p;nx=min(x,up+1); ll nxm=nx%maxi; ll tem=te%maxi; ans=(ans+(ct*((nx-te)%maxi))%maxi)%maxi; if(nx>up) break; ct=(ct+1)%maxi; te=nx; } if(up==r) break; te=up+1;
} cout<<ans<<endl;
I had kinda similar problems, try using unsigned long long instead if you're not using that
Ohhh...Ok thanks a lot
Why the approach for F with euler tour+Lazy prop is giving tle on tc 21? here is the code-https://mirror.codeforces.com/contest/1891/submission/230589277
any help will be appreciated.
I think the problem is that you are passing the adj vector to dfs not by reference
vector*adj means we are passing vector adj[n] by reference.
Thanks for responding but i got AC by using unordered_map instead of map.
I came up with the author's solution F, but I didn't have enough time to debug((
F can be solved without reversing the queries. It is offline though.
It would be online if the final tree was known beforehand. Otherwise — yes, the online solution would be quite nasty with maybe some link-cut trees or treaps.
What do you mean by reversing the queries? I just run on the queries and update to 0 when adding a node
What does the "transition" mean in D?
nvm, got it
I did not. Can you explain?
indexes i where g[i] != g[i+1]
achha contest
In C problem I did as proposed in editorial, but in one test case answers differ. Here is sequence of 14 hits from my implementation:
Can someone provide a sequence to win with just 13 hits?
On the final stack of 6 use the combo at the end (2 small attacks (4) -> combo(-1)) instead of doing combo(3) -> 3 small attacks(0).
Thanks. Premature use of combo is the root of evil
How to avoid tle for C https://mirror.codeforces.com/contest/1891/submission/230581501
If you want to stick to this approach, try using std::deque, erase() from the beginning of vector is expensive operation. Or take a look how beautifully contest leaders solved it.
Here is an alternative solution for F, using Fenwick Tree.
Same, I think this is more direct.
What's the logic?
I believe that my solution 230576374 is the same as in this comment, so I'll describe it.
Let's build our tree and for each vertex save its creation time and updates with current time and value.
What is answer for some vertex? It's sum of all requests which were made on this vertex or any of parents LATER than creation time of current vertex. So let's create BIT for sum of requests by time and dfs our tree. We perform updates before getting ans and rollback them before dfs exit thus for each vertex only relevant updates remain:
Each update is made exactly twice, so it's $$$O((n + q) \log(n))$$$
Thanks for the explanation! Very creative solution. I like that you no longer need range updates, only point updates and range queries.
What was the reasoning for putting problem F at that position?
This is probably the easiest F I've ever seen :(
C can be implemented not using two pointers. But during the contest i forgot to check if n == 1 and a[i] == 1 :\
I have a problem on C . In 230619057 the code id accepted , but in 230619275 , the code is wrong . The only difference between them is merely in "lower_bound(pres,prew+n+1)" or "lower_bound(pres+1,pres+n+1)" . But the pres is the prefix sum of a which indicates that the sum divided by 2 (floor,except for n = 1) must be positive . So "+1" should not make a difference to my solution . I am quite confused . Please help we .
I reverse the order , sorry . The former one is wrong , while the latter one is correct .
I think swap E and F is a good idea
#
because sorting of array takes O(nlogn)
oh okay
but i sill didnt get solution.
I also tried similar logic but in some test case like : 1 1 2 5 6 6
it is not working. My Solution
I wrote some comments on it. Hope it will help you! 230751313
Can someone please tell me why is my submission for Problem D giving TLE?
You recalculate intervals every time you run "func" function. Doing it once and storing it somewhere could help. My solution working as I said: 230684869
Yeah, I got that later. Even this solution is correct if I directly calculate from L to R rather 1 to R and 1 to L.
Mathforces
Nope
I guess most of the questions are implementation-based!
why is E is much difficult than F. Or why is F much easier than E.
Maybe the simplest implementation for C:
can anyone explain why the greedy solution works in C? also for the case when i==j and the last number is an odd number and x=0, then there is no way we can use the 2nd method on this horde
It's possible to use 2nd method when there is only 1 horde left with odd size and x = 0.
For example left horde size = 7 and x = 0 Use 3 attacks of first type. After that horde size = 4 and x = 3. Use second type (ultimate) attack. After that horde size = 1 and x = 0. Use 1 attack of first type. After that horde size = 0.
So it takes 5 attacks to destroy horde size including second attack. Without second attack it would take 7 attacks.
thanks, and it was my bad, I took the 2nd method as it can be used only when there are exactly x monsters left in a horde :-(
it's also clear now why the greedy solution works
I came up with using offline query in problem F. My idea is first save the query and build the completed tree which is presented in the end. Then, I just need to loop from q to 1 and update normally using Euler's tour when type 2 is meet otherwise if type 1 is the current query, output it's node value. But unfortunately, I got WA immediately at 2nd test case although this idea is kind of nature (or maybe it's wrong in some case), anyone suggests me why am i wrong here?
My submissions: 230648660
can anyone help in f...getting wa on 2..230657380
are u wrong answer in 4927th or 799th
4927
It is wrong in answer of node. Node in tree is different from node in euler tour (my english is bad sry about it)
sorry for being such stupid....replaced a[i] with a[tin[i]] and accepted....thanks
#
sorting is $$$O(n \log n)$$$ :unamused:
allright i got it .
but i sill didnt get solution.
I also tried similar logic but in some test case like : 1 1 2 5 6 6
it is not working. My Solution
It's exactly the same thing I missed, see discussion above https://mirror.codeforces.com/blog/entry/121876?#comment-1081838
Can someone give a simple idea about F? Also may I know what are the prerequisites to learn to solve problem F?
I guess there are multiple ways of doing the 2. one you have mentioned. Can you suggest which method is good to opt.
You can do $$$dfs$$$ and go down from root to leafes.
If in node $$$x$$$ you get some sum from above, you also get same sum into all nodes in $$$x$$$ subtree.
Prerequisites: "offline" approach, DFS pre-order, fenwick tree (range add/point get interpretation)
Is there any online solution for F?
Maybe sqrt?
In problem D
shouldnt there be like at most 2 transitions per segment because if we make 3 transitions that would mean jump to next segment?
My logic is similar to one in editorial but I am having issues with MOD. What changes should be done in my code ?
https://mirror.codeforces.com/contest/1891/submission/230655160
Also what are some good sources for topics like modular arithmetic and other topics that will help me remain stable expert. Thanks
Out of curiosity following problem F , how will this problem be solved? Initially i have only one vertex which is numbered 1.There are 1e5 qeuries where in one type of query i can add a vertex to the tree with number sz+1 (sz is the no of nodes in the tree currently).Can i answer other type of query where i need to tell the size of subtree rooted at a given vertex in logn time or what will be the most optimized algorithm for this.
Euler Tour Technique
Note that you don't need to answer the queries online. So you can create the whole tree and process queries later.
can you explain a bit more . Like when a node is added i need to change the size of subtree of all the ancestors of the node . How will i do that?
From the page:
So, to add something to the subtree of
i
, you just update the values fromstart[i]
toend[i]
. This can be done with any range update technique.what does online means here? I saw it in other comments also but don't know it's meaning
u dont know the queries in advance
PROBLEM D
Here is the implementation of sqrt decomposition for F. It is giving TLE as warned by author. Any optimisation in provided code is welcomed.
is there a way to solve problem c with binary search
Can F be solved online?
I think it is better with spoilers, and code.
Thank you, 127.0.0.1
127.0.0.1 I am having a little problem in D. Its working on nearly all the test cases and logic is to point. But I think there is some problem with modulus and its giving wrong answer on one test case-v 179 1000000000000000000 Can any body help I cant seem to figure it our. This is my code where maxi is modulus ll l,r; cin>>l>>r;
can someone help me,i am getting WA on test 2 of F https://mirror.codeforces.com/contest/1891/submission/232563023
I have a problem in D. I got a wrong anwer on test 8, and I have trouble finding where I went wrong. My submission is Your text to link here... . Can someone help me figure out what the problem is? Thanks a lot if you can help!
I am having the same issue, failed on the same test case. Did you manage to figure it out? if so, what was the issue?
I filed on test case 8 because I used the function std::log2(), which led to a accuracy issue. I switched to using binary search to avoid the accuracy issue.
Ok thank you, I will try that out
Can anyone please tell me if the error is in the steps of modular operations or in the map in the following solution. It would be a big help. My submission for Problem D
I am quite stuck on the 1891D task. I have checked the solution explanation, and I can't figure out one key element. The explanation says, that on each part with f(i)==f(i+1) we will have at max O(logn) transitions, such that g(i)!=g(i+1).
My question: how can g(i)!=g(i+1) be on the segment where f(i)==f(i+1), when f(x)=log2(x), while g(x) = logf(x)x, which means that it's base is bigger than 2, and that it should change its values significantly more rare that log2(x).
In Problem C, can someone explain why we are taking the attack iteratively rather than the subarray smaller to the largest horde (in this case the current j pointer)? Why not distributing attacks (of type I) on the remaining hordes beneficial since we can keep the largest hordes larger? and also, why are we minimizing the attacks of type II, wouldn't they be more effective if use them when the combo is higher than 1?
Solution to problem F- A Glowing Tree
Click here
If you like my solution please upvote me
2nd ques. can be done in less than O(30.N) if we maintain another array for counting the what should be added to the array element if it is divisible by some power of 2.
The time complexity comes out to be O(Q + NlogM), M = 30 at max.