#include "garden.h"
#include "gardenlib.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn = 300500, mlg = 30;
int up[maxn][mlg], cnt[maxn];
void count_routes(int n, int m, int P, int R[][2], int Q, int G[]) {
memset(cnt, 0, sizeof cnt);
memset(up, -1, sizeof up);
for(int i = 0; i < m; i++) {
int f = R[i][0], t = R[i][1];
//cout << f << " " << t << " " << i << '\n';
if(cnt[f] < 2) up[2*f + cnt[f]][0] = 2*t + (cnt[t]==0);//, cout << 2*f + cnt[f] << " -- " << 2*t + (cnt[t]==0) << '\n';
if(cnt[t] < 2) up[2*t + cnt[t]][0] = 2*f + (cnt[f]==0);//, cout << 2*t + cnt[t] << " -- " << 2*f + (cnt[f]==0) << '\n';
cnt[f]++, cnt[t]++;
}
for(int i = 0; i < 2*n; i++) if(up[i][0] < 0) up[i][0] = up[i^1][0];
for(int i = 1; i < mlg; i++)
for(int j = 0; j < 2*n; j++)
up[j][i] = up[up[j][i-1]][i-1];
//for(int i = 0; i < 2*n; i++) cout << i << " = " << up[i][0] << "\n";
for(int I = 0; I < Q; I++) {
//cout << P << " " << G[I] << '\n';
int ans = 0;
for(int i = 0; i < 2*n; i+=2) cnt[i] = i;
for(int i = 0; i < mlg; i++) {
if(!((G[I]>>i)&1)) continue;
for(int j = 0; j < 2*n; j+=2) {
cnt[j] = up[cnt[j]][i];
}
}
for(int i = 0; i < 2*n; i+=2) ans += cnt[i] == 2*P || cnt[i] == 2*P+1;
answer(ans);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
36864 KB |
Output is correct |
2 |
Correct |
23 ms |
36864 KB |
Output is correct |
3 |
Correct |
24 ms |
36864 KB |
Output is correct |
4 |
Correct |
23 ms |
36736 KB |
Output is correct |
5 |
Correct |
23 ms |
36864 KB |
Output is correct |
6 |
Correct |
23 ms |
36864 KB |
Output is correct |
7 |
Correct |
23 ms |
36864 KB |
Output is correct |
8 |
Correct |
25 ms |
36864 KB |
Output is correct |
9 |
Correct |
25 ms |
36864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
36864 KB |
Output is correct |
2 |
Correct |
23 ms |
36864 KB |
Output is correct |
3 |
Correct |
24 ms |
36864 KB |
Output is correct |
4 |
Correct |
23 ms |
36736 KB |
Output is correct |
5 |
Correct |
23 ms |
36864 KB |
Output is correct |
6 |
Correct |
23 ms |
36864 KB |
Output is correct |
7 |
Correct |
23 ms |
36864 KB |
Output is correct |
8 |
Correct |
25 ms |
36864 KB |
Output is correct |
9 |
Correct |
25 ms |
36864 KB |
Output is correct |
10 |
Correct |
25 ms |
36864 KB |
Output is correct |
11 |
Correct |
33 ms |
37248 KB |
Output is correct |
12 |
Correct |
52 ms |
37504 KB |
Output is correct |
13 |
Correct |
116 ms |
38392 KB |
Output is correct |
14 |
Correct |
147 ms |
39544 KB |
Output is correct |
15 |
Correct |
157 ms |
39744 KB |
Output is correct |
16 |
Correct |
125 ms |
39416 KB |
Output is correct |
17 |
Correct |
107 ms |
39544 KB |
Output is correct |
18 |
Correct |
53 ms |
37880 KB |
Output is correct |
19 |
Correct |
146 ms |
39544 KB |
Output is correct |
20 |
Correct |
151 ms |
39672 KB |
Output is correct |
21 |
Correct |
122 ms |
39540 KB |
Output is correct |
22 |
Correct |
114 ms |
39416 KB |
Output is correct |
23 |
Correct |
188 ms |
39672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
36864 KB |
Output is correct |
2 |
Correct |
23 ms |
36864 KB |
Output is correct |
3 |
Correct |
24 ms |
36864 KB |
Output is correct |
4 |
Correct |
23 ms |
36736 KB |
Output is correct |
5 |
Correct |
23 ms |
36864 KB |
Output is correct |
6 |
Correct |
23 ms |
36864 KB |
Output is correct |
7 |
Correct |
23 ms |
36864 KB |
Output is correct |
8 |
Correct |
25 ms |
36864 KB |
Output is correct |
9 |
Correct |
25 ms |
36864 KB |
Output is correct |
10 |
Correct |
25 ms |
36864 KB |
Output is correct |
11 |
Correct |
33 ms |
37248 KB |
Output is correct |
12 |
Correct |
52 ms |
37504 KB |
Output is correct |
13 |
Correct |
116 ms |
38392 KB |
Output is correct |
14 |
Correct |
147 ms |
39544 KB |
Output is correct |
15 |
Correct |
157 ms |
39744 KB |
Output is correct |
16 |
Correct |
125 ms |
39416 KB |
Output is correct |
17 |
Correct |
107 ms |
39544 KB |
Output is correct |
18 |
Correct |
53 ms |
37880 KB |
Output is correct |
19 |
Correct |
146 ms |
39544 KB |
Output is correct |
20 |
Correct |
151 ms |
39672 KB |
Output is correct |
21 |
Correct |
122 ms |
39540 KB |
Output is correct |
22 |
Correct |
114 ms |
39416 KB |
Output is correct |
23 |
Correct |
188 ms |
39672 KB |
Output is correct |
24 |
Correct |
26 ms |
36780 KB |
Output is correct |
25 |
Correct |
830 ms |
37372 KB |
Output is correct |
26 |
Correct |
1539 ms |
37880 KB |
Output is correct |
27 |
Execution timed out |
5064 ms |
38392 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |