# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
212727 | 2020-03-24T07:55:06 Z | patrikpavic2 | 스파이 (JOI13_spy) | C++17 | 170 ms | 8184 KB |
#include <cstdio> #include <vector> #define PB push_back using namespace std; const int N = 2e3 + 50; int rootA, rootB; vector < int > vA[N], vB[N]; vector < int > skim[N]; int L[N], R[N], cur = 1, loga[N], sol[N], n, q; void dfs(int x){ L[x] = cur++; for(int y : vB[x]) dfs(y); R[x] = cur; } void add(int x, int y){ for(; x < N ; x += x & -x) loga[x] += y; } int query(int x){ int ret = 0; for(; x ; x -= x & -x) ret += loga[x]; return ret; } void rijesi(int x){ for(int y : skim[x]) add(L[y], 1), add(R[y], -1); sol[x] = query(L[x]); for(int y : vA[x]) rijesi(y); for(int y : skim[x]) add(L[y], -1), add(R[y], 1); } int main(){ scanf("%d%d", &n, &q); for(int i = 1;i <= n;i++){ int x, y; scanf("%d%d", &x, &y); if(!x) rootB = i; else vB[x].PB(i); if(!y) rootA = i; else vA[y].PB(i); } for(int i = 0;i < q;i++){ int x, y; scanf("%d%d", &x, &y); skim[y].PB(x); } dfs(rootB); rijesi(rootA); for(int i = 1;i <= n;i++) printf("%d\n", sol[i]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 512 KB | Output is correct |
2 | Correct | 5 ms | 512 KB | Output is correct |
3 | Correct | 5 ms | 512 KB | Output is correct |
4 | Correct | 5 ms | 512 KB | Output is correct |
5 | Correct | 5 ms | 512 KB | Output is correct |
6 | Correct | 5 ms | 512 KB | Output is correct |
7 | Correct | 5 ms | 512 KB | Output is correct |
8 | Correct | 5 ms | 512 KB | Output is correct |
9 | Correct | 4 ms | 512 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 768 KB | Output is correct |
2 | Correct | 6 ms | 768 KB | Output is correct |
3 | Correct | 6 ms | 640 KB | Output is correct |
4 | Correct | 6 ms | 640 KB | Output is correct |
5 | Correct | 6 ms | 640 KB | Output is correct |
6 | Correct | 6 ms | 640 KB | Output is correct |
7 | Correct | 7 ms | 768 KB | Output is correct |
8 | Correct | 7 ms | 640 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 161 ms | 8184 KB | Output is correct |
2 | Correct | 144 ms | 7396 KB | Output is correct |
3 | Correct | 152 ms | 7528 KB | Output is correct |
4 | Correct | 154 ms | 7652 KB | Output is correct |
5 | Correct | 167 ms | 8056 KB | Output is correct |
6 | Correct | 143 ms | 6760 KB | Output is correct |
7 | Correct | 170 ms | 8184 KB | Output is correct |
8 | Correct | 170 ms | 8056 KB | Output is correct |