#include <bits/stdc++.h>
using namespace std;
template<typename T> inline void read(T &x){
x = 0; char ch;
while(!isdigit(ch=getchar()));
do{x=10*x+ch-'0';}while(isdigit(ch=getchar()));
}
template<typename T> inline void write(T x){
if(x<=9){
putchar(x+'0');
return;
}
write(x/10);
putchar(x%10+'0');
}
template<typename T> inline void writeln(T x){
write(x); putchar('\n');
}
const int N = 2001;
const int M = 5e5+1;
int n, m, tin[2][N], tout[2][N], counter, D[N][N];
vector<int> Adj[2][N];
void DFS(int u, int type){
tin[type][u] = ++counter;
for(int i = 0; i < (int)Adj[type][u].size(); i++){
int v = Adj[type][u][i];
DFS(v,type);
}
tout[type][u] = counter;
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
read(n); read(m);
for(int i = 1; i <= n; i++){
int x, y;
read(x); read(y);
Adj[0][x].push_back(i);
Adj[1][y].push_back(i);
}
counter = -1;
DFS(0,0);
counter = -1;
DFS(0,1);
for(int i = 1; i <= m; i++){
int a, b;
read(a); read(b);
int x = tin[0][a];
int u = tout[0][a];
int y = tin[1][b];
int v = tout[1][b];
D[x][y]++;
D[x][v+1]--;
D[u+1][y]--;
D[u+1][v+1]++;
}
for(int x = 1; x <= n; x++){
for(int y = 1; y <= n; y++){
D[x][y] += D[x-1][y]+D[x][y-1]-D[x-1][y-1];
}
}
for(int i = 1; i <= n; i++){
writeln(D[tin[0][i]][tin[1][i]]);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
17940 KB |
Output is correct |
2 |
Correct |
0 ms |
17940 KB |
Output is correct |
3 |
Correct |
0 ms |
17940 KB |
Output is correct |
4 |
Correct |
0 ms |
17940 KB |
Output is correct |
5 |
Correct |
0 ms |
17940 KB |
Output is correct |
6 |
Correct |
0 ms |
17940 KB |
Output is correct |
7 |
Correct |
0 ms |
17940 KB |
Output is correct |
8 |
Correct |
0 ms |
17940 KB |
Output is correct |
9 |
Correct |
0 ms |
17940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
18104 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
18100 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |