# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
431010 | 2021-06-17T08:53:01 Z | juggernaut | Regions (IOI09_regions) | C++17 | 8000 ms | 30144 KB |
#include<bits/stdc++.h> #define fr first #define sc second using namespace std; void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);} typedef long long ll; #define USING_ORDERED_SET 0 #if USING_ORDERED_SET #include<bits/extc++.h> using namespace __gnu_pbds; template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; #endif template<class T>void umax(T &a,T b){if(a<b)a=b;} template<class T>void umin(T &a,T b){if(b<a)a=b;} #ifdef IOI2021SG #define printl(args...)printf(args) #else #define printl(args...)((void)0) #endif int n,r,q; int reg[200005]; vector<int>g[200005]; int timer; int tin[200005]; int tout[200005]; int precalc[505][505]; bool big[25005]; int id[25005]; int tot; int cnt[25005]; int tmp[25005]; void dfs(int v){ if(big[reg[v]])for(int i=1;i<=tot;i++)precalc[i][id[reg[v]]]+=tmp[i]; tmp[id[reg[v]]]++; tin[v]=++timer; for(int to:g[v])dfs(to); tout[v]=++timer; tmp[id[reg[v]]]--; } vector<pair<int,int>>color[25005]; vector<int>spec[25005]; int main(){ scanf("%d%d%d",&n,&r,&q); scanf("%d",®[1]); cnt[reg[1]]++; for(int i=2;i<=n;i++){ int par; cnt[reg[i]]++; scanf("%d%d",&par,®[i]); g[par].push_back(i); } for(int i=1;i<=r;i++)if(cnt[i]>500){ big[i]=true; id[i]=++tot; } dfs(1); for(int i=1;i<=n;i++){ spec[reg[i]].push_back(tout[i]); color[reg[i]].emplace_back(tin[i],tout[i]); } for(int i=1;i<=r;i++){ sort(color[i].begin(),color[i].end()); sort(spec[i].begin(),spec[i].end()); } while(q--){ int x,y; scanf("%d%d",&x,&y); int ans=0; if(!big[x]){ for(auto to:color[x]){ ans+=(lower_bound(color[y].begin(),color[y].end(),make_pair(to.sc,0))-color[y].begin())-(lower_bound(color[y].begin(),color[y].end(),make_pair(to.fr,0))-color[y].begin()); } }else if(big[x]&&big[y]){ ans=precalc[id[x]][id[y]]; }else{ for(auto to:color[y]){ ans+=(lower_bound(color[x].begin(),color[x].end(),make_pair(to.fr,0))-color[x].begin()); ans-=lower_bound(spec[x].begin(),spec[x].end(),to.fr)-spec[x].begin(); } } printf("%d\n",ans); fflush(stdout); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 6088 KB | Output is correct |
2 | Correct | 5 ms | 6088 KB | Output is correct |
3 | Correct | 7 ms | 6088 KB | Output is correct |
4 | Correct | 10 ms | 6088 KB | Output is correct |
5 | Correct | 11 ms | 6216 KB | Output is correct |
6 | Correct | 22 ms | 6216 KB | Output is correct |
7 | Correct | 35 ms | 6216 KB | Output is correct |
8 | Correct | 39 ms | 6216 KB | Output is correct |
9 | Correct | 50 ms | 6728 KB | Output is correct |
10 | Correct | 88 ms | 6728 KB | Output is correct |
11 | Correct | 134 ms | 7036 KB | Output is correct |
12 | Correct | 148 ms | 7624 KB | Output is correct |
13 | Correct | 205 ms | 7360 KB | Output is correct |
14 | Correct | 288 ms | 8048 KB | Output is correct |
15 | Correct | 320 ms | 11184 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 8083 ms | 11456 KB | Time limit exceeded |
2 | Execution timed out | 8045 ms | 10068 KB | Time limit exceeded |
3 | Execution timed out | 8068 ms | 13640 KB | Time limit exceeded |
4 | Correct | 286 ms | 8056 KB | Output is correct |
5 | Correct | 381 ms | 10024 KB | Output is correct |
6 | Correct | 1461 ms | 9412 KB | Output is correct |
7 | Correct | 1671 ms | 10624 KB | Output is correct |
8 | Correct | 1403 ms | 16592 KB | Output is correct |
9 | Correct | 2350 ms | 16760 KB | Output is correct |
10 | Correct | 4264 ms | 22580 KB | Output is correct |
11 | Correct | 3736 ms | 16436 KB | Output is correct |
12 | Correct | 6019 ms | 17692 KB | Output is correct |
13 | Correct | 7166 ms | 18080 KB | Output is correct |
14 | Execution timed out | 8019 ms | 17968 KB | Time limit exceeded |
15 | Execution timed out | 8022 ms | 23232 KB | Time limit exceeded |
16 | Execution timed out | 8025 ms | 30144 KB | Time limit exceeded |
17 | Execution timed out | 8007 ms | 28824 KB | Time limit exceeded |