# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
421397 | 2021-06-09T06:39:55 Z | 장태환(#7576) | Collapse (JOI18_collapse) | C++17 | 39 ms | 5872 KB |
#include "collapse.h" #include <string.h> using namespace std; int st[100100]; int e[100100]; int d[200100]; unsigned int vis[200200>>6]; vector<pair<int,int>>q[100100]; int sta[100100]; int siz; vector<int> simulateCollapse(int N,vector<int> T,vector<int> X,vector<int> Y,vector<int> W,vector<int> P) { memset(vis,-1,sizeof(vis)); vector<int>ann=vector<int>(W.size(), 0); int i; int M=T.size(); for(i=0;i<M;i++) { if(T[i]) { e[X[i]]--; e[Y[i]]--; } else { e[X[i]]++; e[Y[i]]++; st[X[i]+1]=max(st[X[i]+1],e[X[i]]); st[Y[i]+1]=max(st[Y[i]+1],e[Y[i]]); } } for(i=0;i<N;i++) { if(i) st[i]+=st[i-1]; e[i]=st[i]; } int C=P.size(); for(i=0;i<C;i++) { q[W[i]].push_back({P[i],i}); } for(i=0;i<M;i++) { int ty=T[i]; int s=X[i]; int en=Y[i]; register int j; if(ty) { int fi=st[s]; int se=e[s]; for(j=fi;j<se;j++) { if(d[j]==en) { d[j]=d[se]; break; } } e[s]--; fi=st[en]; se=e[en]; for(j=fi;j<se;j++) { if(d[j]==s) { d[j]=d[se]; break; } } e[en]--; } else { d[e[s]++]=en; d[e[en]++]=s; } for(j=0;j<q[i].size();j++) { int div=q[i][j].first+1; int cur=0; int an=0; memset(vis,0,(div>>3)+4); while(cur<div) { an++; sta[siz++]=cur; while(siz) { int cou=sta[--siz]; register int k; for(k=st[cou];k<e[cou];k++) { if(!(vis[d[k]>>5]&(1U<<(d[k]&31)))) { vis[d[k]>>5]|=1U<<(d[k]&31); sta[siz++]=d[k]; } } } cur++; while((vis[cur>>5]&(1U<<(cur&31)))) { cur++; } } memset(vis+(div>>5),0,((N-div)>>3)+10); cur=N-1; while(cur>=div) { an++; sta[siz++]=cur; while(siz) { int cou=sta[--siz]; register int k; for(k=st[cou];k<e[cou];k++) { if(!(vis[d[k]>>5]&(1U<<(d[k]&31)))) { vis[d[k]>>5]|=1U<<(d[k]&31); sta[siz++]=d[k]; } } } cur--; while(cur&&(vis[cur>>5]&(1U<<(cur&31)))) { cur--; } } ann[q[i][j].second]=an; } } return ann; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3020 KB | Output is correct |
2 | Incorrect | 3 ms | 2764 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 38 ms | 5732 KB | Output is correct |
2 | Incorrect | 37 ms | 5872 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 39 ms | 5732 KB | Output is correct |
2 | Incorrect | 39 ms | 5608 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3020 KB | Output is correct |
2 | Incorrect | 3 ms | 2764 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |