Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

MikeMirzayanov's blog

By MikeMirzayanov, 4 years ago, In English

You can view PDF version of the tutorial by the link.

Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
Tutorial is loading...
  • Vote: I like it
  • +86
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it +37 Vote: I do not like it

That trick for pairs in problem M is just awesome... During the whole contest we were struggling to remove that logn factor but couldn't find the way.

»
4 years ago, # |
Rev. 2   Vote: I like it -8 Vote: I do not like it

I think that there is a mis-written part in problem A in editorial: a[posi−1]≤a[posi]≥a[posi+1] should be a[posi−1]≤a[posi]≤a[posi+1]

  • »
    »
    4 years ago, # ^ |
      Vote: I like it +6 Vote: I do not like it

    i can not understand editorial for A. can you explain?

»
4 years ago, # |
  Vote: I like it -8 Vote: I do not like it

I think there is an error in tutorial for L. "If there are no more than 2 such integers" (second sequence) should be "If there are no more than 1 such integers" or "If there are less than 2 such integers". Because in next paragraph $$$k_i > 1$$$ implies that $$$p$$$ can be important if there are 2 numbers of form $$$p^q$$$.

»
4 years ago, # |
Rev. 2   Vote: I like it +3 Vote: I do not like it

For M, how is finding all pairs (x,y) not time complexity (k^2)? How exactly do you create a separate array for each integer x and then add all values y to it

»
4 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

In problem C Berpizza why I am getting tle on test case 12 My code please let me know and also how to resolve it

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I notice that you are sorting the vector every time a monocarp or polycarp query is done. This is probably making it slow. You can instead try using sets as they are implemented using binary-search trees and will be faster (O(log n) vs O(n logn) per query). My submission using sets

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

In problem M's tutorial, does it mean that: For every small sets, we find all pairs, which is O(k^2) where the k is the size of the sets. There are M/k sets so that their are O(M*k) pairs in total? How should I implement it? I tried 2 dimension unorderedmap but TLE.

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anybody share the code of C. Berpizza

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    See in my submissions

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it
    #include<bits/stdc++.h> 
    using namespace std;
    typedef long long int ll;
    typedef vector<ll> vi;
    typedef vector<vector<ll>> vvi;
    typedef vector<bool> vb;
    typedef pair<ll,ll> pii;
    #define fo(i,s,e_ex) for(i=s;i<e_ex;i++)
    #define Fo(i,k,n) for(i=k;k<n?i<=n:i>=n;k<n?i+=1:i-=1)
    #define endl '\n'
    #define MOD 1000000007//998244353
    #define setbits(x) __builtin_popcountll(x)
    #define pbb push_back
    #define mpp make_pair
    #define ff first
    #define ss second
    #define all(x) x.begin(),x.end()
    #define mset(arr,val) memset(arr,val,sizeof(arr))
    vi guest(500005,1);
    bool compForPair(pii a,pii b){
    	if(a.first==b.first){
    		return a.second>b.second;
    	}
    	return a.first<b.first;
    }
    void solve(ll caseno){
        ll i,j,q;
    	ll type,m=0,guestNo=1;
    	priority_queue<pii, vector<pii>, decltype(&compForPair)> poly(compForPair);
    	priority_queue<ll, vi,  greater<ll> > mono;
    	cin>>q;
    	while(q--){
    		cin>>type;
    		if(type==1){
    			cin>>m;
    			poly.push(mpp(m,guestNo));
    			mono.push(guestNo);
    			guestNo++;
    		}else if(type==2){
    			while(true){
    				ll gtorem = mono.top();mono.pop();
    				if(guest[gtorem]==1){
    					cout<<gtorem<<" ";
    					guest[gtorem]=0;
    					break;
    				}
    			}
    		}else{
    			while(true){
    				ll gtorem = poly.top().second;poly.pop();
    				if(guest[gtorem]==1){
    					cout<<gtorem<<" ";
    					guest[gtorem]=0;
    					break;
    				}
    			}
    		}
    	}
    }
    int main(){
    	ios_base::sync_with_stdio(false);
    	cin.tie(0);cout.tie(0);
    	ll t=1;
    	//cin>>t;
    	for(ll i=1;i<=t;i++){
    		solve(i);
    	}
    	return 0;
    }
    
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

"Now, we can note that each a[i] is either minimum in LaIS or i = nxt[j] for some other element a[j]".

Can someone give me a proof of that?

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

can someone explain how are we finding if it is possible to burst f crackers in problem D?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    i dont know if you have figured it out, but f is min(distance between the cop and hooligan,total number of crackers).The reasoning behind it is that the distance between hooligan is either decreasing or constant. And whenever he bursts a cracker, the cop comes one step closer to him, which means that at max he can burst Dist crackers(unless of course m is smaller than Dist). (Dist = distance between cop and hooligan).

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

How do you get to the conclusion that only collinear but oppositely facing vision vectors will make eye contact in problem f. How to prove that any other vision vectors wont make it ??

  • »
    »
    3 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    Consider a straight line between 2 persons. So, if they will ever make eye contact then only if they both have a vision on that line heading towards each other. Now the degree both persons rotate must be equal, you can observe that it is only possible if both vectors are collinear and have opposite directions.

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

A note on problem $$$M$$$: it's actually better to set the bound to be $$$400$$$ as opposed to $$$\sqrt{N}$$$. My solution improved from $$$900$$$ ms to $$$700$$$ ms using this better bound.

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I know this is extremely late, but for problem D, you don't even need to do binary search. All you need to do is sort the firecrackers. Then iterate from the firecrackers with largest time to smallest time. For firecracker i, check if the space between the hooligan and the cop plus the space between the hooligan and the end is greater than the time of the firecracker and that the hooligan isn't caught yet. Then increase your answer by 1

149971062

»
22 months ago, # |
  Vote: I like it 0 Vote: I do not like it

The problem $$$M$$$ has a bipartite graph and asks if there is a cycle of length $$$4$$$.

Given any bipartite graph if we want to find if there exists a cycle of size $$$N$$$. Where $$$N$$$ is even. Is there any general solution for this?

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Btw, I don't think anyone said this yet, but you actually don't need to use binary search for D! After sorting the array, set $$$f = min(m, |a - b| - 1)$$$ since we can't possibly chose any more firecrackers than this. Like the editorial, the optimal order is to chose $$$s[f], s[f - 1], ... s[1]$$$ in that order. The amount of time the security guard will take to reach him depends on where the hooligan is in comparison. If the hooligan is to the left, it will take $$$b - 1$$$ time, since he will run to the left at the end and there are that many squares to the left. If he is to the right, then it will take $$$n - b$$$ units of time since there are that many squares to the right. Let's make that value be equal to $$$t$$$. If we have already selected $$$k$$$ values, there is a bound on the $$$i$$$th value we chose: $$$s[i] <= t - k - 1$$$. The first value must be at most $$$t - 1$$$ instead of $$$t$$$ because it explodes $$$s[i]$$$ seconds after it is dropped, i.e. not including the moment it is dropped. After selecting $$$k$$$ values (the aforementioned case was $$$k = 0$$$), the requirement will decrease by $$$k$$$, of course. If $$$s[i]$$$ does satisfy this condition, we increment $$$k$$$, but either ways we move on to the next. The actual method takes at most $$$O(m)$$$ time since $$$f$$$ is the minimum of it and $$$|a - b| - 1$$$, so the time complexity is $$$O(mlogm)$$$ due to sorting. If you like using counting sort it is $$$O(m)$$$. I used the built-in sort, aka the former. This is my accepted submission using this method.. Also, sorry for being extremely late lol.