Educational Codeforces Round 162 [Rated for Div. 2]
source link: https://codeforces.com/blog/entry/126248
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Educational Codeforces Round 162 [Rated for Div. 2]
Hello Codeforces!
On Friday, February 23, 2024 at 14:35UTC Educational Codeforces Round 162 (Rated for Div. 2) will start.
This round will be rated for the participants with rating lower than 2100. It will be held on extended ICPC rules. The penalty for each incorrect submission until the submission with a full solution is 10 minutes. After the end of the contest, you will have 12 hours to hack any solution you want. You will have access to copy any solution and test it locally.
You will be given 6 or 7 problems and 2 hours to solve them.
The problems were invented and prepared by Adilbek adedalic Dalabaev, Ivan BledDest Androsov, Maksim Neon Mescheryakov, Roman Roms Glazov and me. Also, huge thanks to Mike MikeMirzayanov Mirzayanov for great systems Polygon and Codeforces.
Good luck to all the participants!
41 hour(s) ago, # | Good luck to everyone! |
41 hour(s) ago, # | Such a short and clear announcement I hope problems statements be like this too! |
41 hour(s) ago, # | Hope able to solve ABC this round |
40 hours ago, # | Hope able to AK this round |
40 hours ago, # | Good luck to everyone! (please upvote i need contribution) |
39 hours ago, # | Good luck to all , i hope to solve ABC |
38 hours ago, # | Excited! |
37 hours ago, # | Excited to get to Expert |
35 hours ago, # | Hope to solve ABCDEFGHIJKLMNOPQRSTUVWXYZ in this round (i'm a divinity i can do things you dont think are possible) |
32 hours ago, # | Hope to reach 2024 |
29 hours ago, # | I think the title should say [Rated upto div2] instead of [Rated for div2] |
-
Div. 2 includes all ratings below 2100 (if there's no Div. 1 contest)
-
Oh then why we have div3 and div4 contests.. if no such division exists?
-
Div. 3 and Div. 4 are not exclusive to Div. 2. Usually Div. 3 includes Div. 4 and Div. 2 includes Div. 3 and Div. 4. The only exception so far, to my knowledge, was https://codeforces.com/blog/entry/121579 this Div. 1 & 2 & 3 contest.
-
-
28 hours ago, # | My last contest in this winter vacation |
25 hours ago, # | Score distribution? |
25 hours ago, # | Who tested? |
24 hours ago, # | good luck :> |
23 hours ago, # | Educational rounds are mathforces af, thats a skip |
22 hours ago, # | Just to let you guys know vimdhayak ji is here Sabko dekh lenge |
22 hours ago, # | Enjoy the contest! |
22 hours ago, # | stay up to late again:) |
20 hours ago, # | Small and clear announcement. Hopefully we will enjoy this contest. </> |
18 hours ago, # | Good luck everybody. Hope to get positive delta :) |
18 hours ago, # | Ah Shit, Here We Go Again. |
17 hours ago, # | we can solve F with simple DP |
17 hours ago, # | Missed opportunity to name problem C. as "Find C" |
17 hours ago, # | Do we write outputs for each test case as it comes or all the way at the end? |
16 hours ago, # | Finally, Goodbye 2023 has a worthy competitor. |
16 hours ago, # | It's like Div 1.5 |
16 hours ago, # | B>>>C |
-
wtf? just kill the nearest mob
-
i couldnt get the implementation right for B , C was just prefix sum
-
priority_queue or even std::sort should work
-
hi can you please check with my code once i know i made it too much complex but i still used the same approach you mentioned. here it is
-
-
-
16 hours ago, # | problem D :( |
-
it was just about binary search.
-
What's your approach?
-
for each index,i checked on both sides and if any side's sum exceed the number at current index than can compress the range.Also note that if any side's range have all number same then will not consider that side.
-
how did you find if all numbers are same in a range?
-
For example, arr=[1,1,2,3,3,3] i stored the ranges (0,1) , (2,2) , (3,5) in a vector 'vec' in sorted manner. It can be done in O(n).
now suppose i want to check if (4,5) has all number same,what will i do? i will find the largest index in vec such that vec[i][0]<=4, now i will check if vec[i][1]>=5 than (4,5) lies under the range (vec[i][0],vec[i][1]) otherwise some numbers are diff.
Just binary search things...
-
you can check it easy if all elements in the segments are the same or not you can use prefix sum and check if the summation in the segment is equal to r-l
vector<ll>id(n+1); for(int x=1;x<=n;x++){ if(v[x]==v[x-1]) id[x] =id[x-1]+1; else id[x] = id[x-1]; } if(id[r]-id[l]==r-l) all elemnts are the same
-
-
-
-
-
16 hours ago, # | I couldn't get the implementation for B right for over an hour... fml |
16 hours ago, # | E too easy to be an E, swap D and E |
16 hours ago, # | cheaters ruined the contest again :( |
Nice problem F! Thanks! |
-
How to solve it? My intuition is that we will perform 2nd operation at most once. Since number of 1s stays constant , we will try to merge 1s as close as possible.
-
That's it! (I didn't realize we needn't do the 2nd operation twice in the contest QWQ)
When we perform the 2nd operation only once, we can consider on the reversed string. We can try all positions for the highest bit, and binary search on the final length of the string ignoring leading zeroes.
If the positions of the highest bit and the lowest bit are determined, the greedy solution is to put all 1 outside to the last few 0s in the interval, so the prefix of some length doesn't change. So we can use hash or suffix array to compare the prefixes, and then the best starting position can be determined.
-
16 hours ago, # | I finally joined the dark side, selling my soul to Atcoder! If you want to build intuition and upsolve problem D without looking at the editorial, try out 1901D : Yet Another Monster Fight. I've added hints as well. A major hint for this problem: Spoiler |
16 hours ago, # | after getting 15 WA on problem C, I wished contest end earlier. screwed up, going gray again |
-
can you share the approach for C? thanks in advance
16 hours ago, # | in B is it not optimal to kill the nearest monster? |
-
nearest with low hp
-
it does not matter
-
I got wrong answer 4 times in the contest because I forget to sort the position array and after I used sort it got accepted so I think it matters (https://codeforces.com/contest/1923/submission/247981283)
-
-
16 hours ago, # | hint for D pls |
16 hours ago, # | Enjoyable contest. At least I will not come back to pupil ^-^ |
16 hours ago, # | Why so tough time limit in E? |
16 hours ago, # | how to approach B? |
-
Loop from the closest monster to the farthest (you need to take only the absolute value of all monster positions and then sort them), but you need to know each monster's health after the sorting, so you need to use something like a vector<pair<int,int>> where the first value is for position and the second value is for the index of that monster corresponding for its health . Now just loop from the closest to the farthest and sum their health and check how many rounds you need to get rid of the current sum, Rounds_required = ceil(current_sum/k).
If at any time the rounds required are bigger than the current monster position, then we can't kill that monster so break and print no
16 hours ago, # | for Problem C why i'm getting an WA : submission |
-
To determine if the answer for a query is yes, you need to the number of non-ones from L to R.
Instead of sum-cnt*2 > 0, try sum-cnt*2-num_nons (where num_nons is the number of values in the range that is not 1).
-
After number of non-ones,then what ?
-
That's it. Just create another prefix array that allows constant time counting of the number of "non-ones" from [L,R].
It is optimal to set b[i] to 1 when c[i] is not 1, and then set b[i] to 2 when c[i] is 1. If b's sum is too small, then it suffices to increase one b[i] to match c's sum. If b's sum is too large, the answer is "NO".
What amoad forgot to do was consider all indices where c[i] is not 1, as b[i] would be 1 and therefore part of b's count.
I hope this explanation makes sense
-
-
16 hours ago, # | Clutched problem C |
16 hours ago, # | Need More Practice for Educational Rounds. Btw Can anyone tell me the approach for C.(B>C) |
16 hours ago, # | Very nice problems |
16 hours ago, # | How to hack others? |
16 hours ago, # | any hint for problem c???? |
-
Basically, if you have 's in array , they will be at least in array and all other elements will be at least . So, for some , you just need to check if sum on subarray from to is at least it's length amount of 's in it. is an edge-case.
A: Let L=the minimum position of i such that a[i]==1, R=the maximum position of i such that a[i]==1, the until occurences of 1 become a single block, R-L will decrease 1 if you do operation on position R, otherwise it will not decrease. So the answer is (R-L)-(cnt-1) where cnt is the count of occurences of 1. B: For each 1<=i<=n we need sum(j:abs(x[j])<=i)(a[i])<=k*i to kill monsters with distance <=i in i turns. C: If L==R answer is no. Otherwise, for each a[i]==1 we need some j such that a[j]>1 and let a[i]+=1, a[j]-=1. Then we need sum(i:a[i]==1)(1)<=sum(j:a[j]>1)(a[j]-1). We can check this condition in O(1) by prefix sum. D: Assume slime i is eaten by some slime to the left (the other case is similar), and all slimes used to eat i will form an interval [j, i-1]. So we need to find the maximum j such that sum(j, i-1)>a[i]. If j==i-1, slime i-1 can eat slime i directly. If value of a[j...i-1] is not all the same, then there will be a largest slime which can eat all other slimes in range [j, i-1] then eat slime i. Otherwise, all slimes in [j, i-1] have the same size and cannot eat each other, and slime i-1 is not larger than slime i. So we need to extend this interval to the left to find some k such that a[k]!=a[i-1] (if such k exist). E: Small-to-large merge. Let dp[u][c]= (the number of nodes v in subtree of u, such that v is color c, and nodes on the path from u to v (except v) are not colot c). Then the number of valid paths with lca=u is sum(v1)(dp[v1][color[u]]) + sum(v1,v2,c)(dp[v1][c]*dp[v2][c]), where v1,v2 iterates over childs of u, c iterates over all colors on subtree of u, and v1<v2, c!=color[u]. The first term means valid paths start from u, and second term means valid paths start and end in subtree of u. To calculate the value we have dp[u][c]=sum(v: child of u)(color[v]==c) (if c!=color[u]), dp[u][color[u]]=1, we can maintain imformation in std::map and merge them small-to-large. |
-
Can you explain what merging small to large means? I had the same dp relation but got TLE on testcase 10.
-
using tmii = map<int, int>; tmii& dfs(int node,int prev){ tmii& mp=*new tmii(); for(int next:adj[node]){ if(next==prev) continue; tmii& mp2=dfs(next,node); if(mp.size()<mp2.size()) swap(mp,mp2); for(auto [color,cnt]:mp2){ if(color!=c[node]) ans+=(ll)mp[color]*cnt; mp[color]+=cnt; } mp2.clear(); } ans+=mp[c[node]]; mp[c[node]]=1; return mp; }
-
16 hours ago, # | Can anyone please tell me why does this code won't work for problem C :( |
-
3 1 1 1 3 1 3
Your answer is , but should be ().
-
Will you help me in solution of D also?
16 hours ago, # | B >>> D > E > A > C |
-
I felt B was a standard implementation problem
16 hours ago, # | Anyone who got WA on test 2 at problem D, then managed to solve it? What was missing? I did a binary search on prefix sums while checking for the existence of different elements using two segment trees (minimum != maximum). I got WA on test 2, and I couldn't find one where it was not working. |
-
Let's say we have 3 9 9 9 9 9. We're checking how far right we need to go to eat 3. Simple binary search will result in -1 (no answer for it), because it will first check 3 9s but they're the same so then it will try more than 3 9s, etc. You need to process 1-length case separately.
16 hours ago, # | In problem D sample input and ouput it is given in the third testcase that 2 2 3 1 1 will give an output of 2 1 -1 1 2 but cant slime 3 be eaten when 2 eats 2 and then eats 3. Making the expected output 2 1 2 1 2 or am I going wrong somewhere |
16 hours ago, # | F is beautiful! Too bad I only managed to solve it a few minutes late lol |
16 hours ago, # | B — Can anyone find out the my mistake Thanks int main(){ int t; cin>>t; while(t--){ ll n,k; cin>>n>>k; ll hel[n]; for(int i=0;i<n;i++){ cin>>hel[i]; } map<ll,ll> m; int mon[n]; for(int i=0;i<n;i++){ ll x; cin>>x; if(x<0) x=x*-1; mon[i]=x; m[x]=m[x]+hel[i]; } ll cnt=0; ll p=0; int flag=0; for(auto &ele:m){ ll extra=cnt+((ele.first-p)*k); if(extra<ele.second){ flag=1; break; } ll remain=extra-ele.second; cnt+=remain; p=ele.first; } if(flag==1) cout<<"NO"<<endl; else cout<<"YES"<<endl; } |
Edit --> My question was dumb asf. I misunderstood the entire question so resolving now |
247976858 Can you give me test case wrong ? My program WA on test 2 (Problem D) |
-
test: 1 7 1 5 10 4 4 1 1 correct output: 1 1 -1 1 2 1 2 your output: 1 1 -1 1 2 3 2
15 hours ago, # | Can anyone find out the my mistake Thanks[submission:247947411] |
-
void solve() {
ll n, q; cin >> n >> q; vector<ll>a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; } vector<ll>b(n + 1, 0); for (int i = 1; i <= n; i++) { b[i] = a[i] + b[i - 1]; } while (q--) { ll l, r; cin >> l >> r; if (l == r) { cout << no << endl; continue; } ll tem = b[r] - b[l - 1]; ll h = r - l + 1; if (tem >= h / 2 + (h - h / 2) * 2) { cout << yes << endl; } else { cout << no << endl; } }
15 hours ago, # | COULD YOU MAKE SAMPLES IN TASK C BETTER? |
I think problem D can be solved using binary search |
-
And problem A using greedy
-
And we can solve 1923F - Shrink-Reverse using greedy algorithm with string suffix structures :D
-
15 hours ago, # | Do anyone know how can my O(n * log(n)^2) solution for problem D got TLE, since n * log(n)^2 is only around 10^8 Thank you so much |
-
I think you don't consider Segment Tree constant per query, which is very big.
-
I've got TLE because of that too. Is the constant really that big? Why it isn't just log(n)?
-
15 hours ago, # | Why does C have so many hacks? |
-
even tourist got hacked? tf
-
does anyone know that missing edge case?
-
I don't think there's an edge case possible for that task? (except L==R which his submission covers). My code is exactly the same as tourists so I'll probably get hacked as well smh
-
-
15 hours ago, # | What is an "easy" solution of problem E? I solved it exactly as this problem. |
-
I just saw your comment. I already posted my solution elsewhere but here it is again.
It consists in one dfs. The idea is to keep track of which colors were accessible before on the dfs tree, with multiplicity. When branching, we set the current color to multiplicity = because it then loses its multiplicity (the path needs to be beautiful). But then it needs to regain its old multiplicity when we end the dfs.
15 hours ago, # | D: For each index ,I gonna binary search on the answer. So consider position i, we have to check if after x seconds, we can eat this slime or not. Im computing the left side first, that mean we considering only from 1 to i-1. In the position i and after x second, there are two case:
After finishing the left side, we do the same on the right side and compare the answer 247990076 E : I saw a lot of simpler solution for problem E (merge set/map on tree, etc...). Anyway, I have another technique for E that is "Auxiliary Tree", which was very useful and generic in some specific type of problems. You can find it here : https://codeforces.com/blog/entry/76955. This problem is similar to E, which you can try to solve it first : 613D - Kingdom and its Cities. You can read my solution for E here : 247980215. |
15 hours ago, # | What is the hack on C? Asking for a friend.. |
15 hours ago, # | Unfortunately, hacks for C were judged incorrectly due to a very peculiar case of UB :( We are sorry for that, all hacks have been rejudged. The solutions during the contest were judged correctly, so this affected only the hack phase. |
14 hours ago, # | Im not able to understand why im getting wrong answer 2 for problem D,247990642 Could anyone please help!! |
14 hours ago, # | I wasted 30 minutes in Q2 just because I didn't used int64_t |
14 hours ago, # | it may not appropriate to write such comment but There is a case where my code for C is failing, i tried a lot to debug even stress testing but still couldn't found anything! it's failing on token 59831 on testcase 3 i don't know what's minor mistake i'm making 247924659 can anyone help me ? |
13 hours ago, # | Approach for solving Problem E using auxillary tree and DP. Suppose for each color we perform a on the tree and calculate number of nodes in subtree of node- of color such that none of it's ancestor has color . Now we divide our answer in two cases: Case-1: Node-R has color c Case-2: Node R has color c But this will take time. To optimise this, we compress the tree in a way such that we only take nodes of color (and some extra nodes less than equal to number of nodes of color in number) without losing any information that we could obtain for any node of color . Now we can use the same logic without any problem. For each color our complexity would then reduce to (ignoring the extra factor that comes because of and . Here is my submission for the problem. Problems Blogs and Videos |
12 hours ago, # | is problem D prefix/suffix sum problem? then using binary search on pref(left), suff(right) then take lower..? but how to handle case where having same size adjacent? |
-
I took care of this case by first going through the whole array and extracting the adjacent subarrays of same values (in the form of a vector of pairs (left index, right index)). Then, when binary searching, I would call the condition not met whenever the currently considered subarray lied in one of the precomputed "adjacent subarrays of same value".
To handle this with a good complexity, I used another binary search to find the good (left index, right index) candidate with which I should check if I am inside or not. It's like geometry, so maybe there are easier ways to do so.
-
To make the implementation easier, you could use DP. Define to be the index of the leftmost consecutive identical element that ends at .
- If , then .
- If , then .
Using this DP array, how to check if the range has identical elements? Just check if . If yes, then the range has identical elements.
Now, you can do a binary search on to figure out the answer.
-
12 hours ago, # | Any small counter testcase for my C 1923C - Find B; submission 247973573 as well? I have used all the TCs posted by AVdovin and 29logN |
void solve() { ll n, q; cin >> n >>q; vll v(n),pref(n+1),one(n+1); for(int i=0;i<n;i++)cin>>v[i]; for(int i=0;i<n;i++){ pref[i+1]+=(pref[i]+v[i]); one[i+1]+=(one[i]+(v[i]==1)); } debug(pref) while(q--){ ll a,b; cin>>a>>b; ll z=(b-a+1); if(z==1){ cout<<"NO"<<endl;continue; } ll sum=pref[b]-pref[a-1]; debug(sum) if(sum>=(((z+1)/2)*2+(z)/2)){ cout<<"YES"<<endl; } // else if(sum>z-(one[b]-one[a-1])){ // cout<<"YES"<<endl; // } else{ cout<<"NO"<<endl; } } signed main() { ifndef ONLINE_JUDGEfreopen("Error.txt", "w", stderr); endiffastio(); int tt=1; cin>>tt; while(tt--) { solve(); } return 0; wrong answer expected NO, found YES [59831st token] can anyone provide any test case or tell me wherei got wrong seen the test case |
11 hours ago, # | I guess we can solve problem F using greedy algorithm with string suffix structures :D |
10 hours ago, # | I got a time limit on C even though it passes now :( (barely though) Python always does me dirty like that |
Hello Everyone, Hope Everybody is doing great. I am stuck at problem C, can someone help me, what's wrong with my code 248047400 this code is after i have take the input array
According to me it should be correct,but failed at some 58k token. |
-
Can you explain what's the meaning of
sum
in your code?-
Basically sum is the minsum of the array for which good array is possible Suppose pattern {1 1 1 2 2 2} -->3 one and 3 two if we decrease any of the two then it wouldn't be good array and this pattern would be min sum possible for length 6 good array possible
{1 1 1 2 2} max sum for which good array of length 5 is not possible. {1 1 2 2 2} min sum for which good array of length 5 is possible.
let say length of array is k then we need min sum of k/2 one's and (k-k/2) two's for array of length k to be good array
-
-
Find possible b's for
1 1 1 1 4
and1 1 1 2 3
on paper and with your solution-
You cannot find right?
-
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK