Submission #212727

# Submission time Handle Problem Language Result Execution time Memory
212727 2020-03-24T07:55:06 Z patrikpavic2 스파이 (JOI13_spy) C++17
100 / 100
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

spy.cpp: In function 'int main()':
spy.cpp:46:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &q);
  ~~~~~^~~~~~~~~~~~~~~~
spy.cpp:48:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y; scanf("%d%d", &x, &y);
             ~~~~~^~~~~~~~~~~~~~~~
spy.cpp:55:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y; scanf("%d%d", &x, &y);
             ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory 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
# Verdict Execution time Memory 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
# Verdict Execution time Memory 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