# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
121479 | 2019-06-26T14:31:11 Z | TadijaSebez | Regions (IOI09_regions) | C++11 | 8000 ms | 57208 KB |
#include <stdio.h> #include <vector> #include <algorithm> using namespace std; #define pb push_back #define mp make_pair #define ll long int const int N=200050; const int S=250; const int H=805; const int M=25050; int sol[H][M]; int hid[M],reg[N],tsz; vector<int> E[N],My[M],ids[M]; int lid[N],rid[N],tid; void DFS(int u) { lid[u]=++tid; ids[reg[u]].pb(tid); for(int i=0;i<E[u].size();i++) DFS(E[u][i]); rid[u]=tid; } void Heavy(int u, int r, int c) { if(reg[u]==r) c++; else sol[hid[r]][reg[u]]+=c; for(int i=0;i<E[u].size();i++) Heavy(E[u][i],r,c); } int Get(int l, int r, int ty) { return upper_bound(ids[ty].begin(),ids[ty].end(),r)-lower_bound(ids[ty].begin(),ids[ty].end(),l); } int par[N]; int main() { int n,m,q,i; scanf("%i %i %i",&n,&m,&q); scanf("%i",®[1]); for(i=2;i<=n;i++) scanf("%i %i",&par[i],®[i]),E[par[i]].pb(i); for(i=1;i<=n;i++) My[reg[i]].pb(i); DFS(1); for(i=1;i<=m;i++) if(My[i].size()>=S) hid[i]=++tsz,Heavy(1,i,0); int x,y; while(q--) { scanf("%i %i",&x,&y); if(My[x].size()>=S) printf("%i\n",sol[hid[x]][y]); else { int ans=0; for(i=0;i<My[x].size();i++) { ans+=Get(lid[My[x][i]],rid[My[x][i]],y); } printf("%i\n",ans); } fflush(stdout); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 6144 KB | Output is correct |
2 | Correct | 8 ms | 6144 KB | Output is correct |
3 | Correct | 9 ms | 6144 KB | Output is correct |
4 | Correct | 10 ms | 6144 KB | Output is correct |
5 | Correct | 10 ms | 6272 KB | Output is correct |
6 | Correct | 18 ms | 6272 KB | Output is correct |
7 | Correct | 27 ms | 6272 KB | Output is correct |
8 | Correct | 42 ms | 6320 KB | Output is correct |
9 | Correct | 55 ms | 6656 KB | Output is correct |
10 | Correct | 86 ms | 6812 KB | Output is correct |
11 | Correct | 113 ms | 7040 KB | Output is correct |
12 | Correct | 125 ms | 7424 KB | Output is correct |
13 | Correct | 112 ms | 7240 KB | Output is correct |
14 | Correct | 293 ms | 7936 KB | Output is correct |
15 | Correct | 401 ms | 9848 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1751 ms | 11216 KB | Output is correct |
2 | Correct | 1865 ms | 10360 KB | Output is correct |
3 | Correct | 3183 ms | 13032 KB | Output is correct |
4 | Correct | 246 ms | 8064 KB | Output is correct |
5 | Correct | 397 ms | 9216 KB | Output is correct |
6 | Correct | 470 ms | 11128 KB | Output is correct |
7 | Correct | 1050 ms | 12624 KB | Output is correct |
8 | Correct | 1041 ms | 19832 KB | Output is correct |
9 | Correct | 3161 ms | 22608 KB | Output is correct |
10 | Correct | 3188 ms | 31192 KB | Output is correct |
11 | Execution timed out | 8070 ms | 57208 KB | Time limit exceeded |
12 | Correct | 1683 ms | 17704 KB | Output is correct |
13 | Correct | 2669 ms | 17916 KB | Output is correct |
14 | Correct | 3135 ms | 19548 KB | Output is correct |
15 | Correct | 3904 ms | 22292 KB | Output is correct |
16 | Correct | 3493 ms | 30868 KB | Output is correct |
17 | Correct | 3466 ms | 28156 KB | Output is correct |