# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
465366 |
2021-08-15T17:47:22 Z |
dutch |
Werewolf (IOI18_werewolf) |
C++17 |
|
1415 ms |
147856 KB |
#include <bits/stdc++.h>
using namespace std;
#include "werewolf.h"
typedef vector<int> vi;
const int NL = 2e5, ML = 6e5, LOG = 21;
int N, M, Q, k, dfsTimer;
int e[NL], r[NL], p[2][LOG][ML], st[2*NL], tL[2][ML], tR[2][ML];
array<int, 2> g[2*NL];
int find(int u){
return e[u] < 0 ? u : e[u] = find(e[u]);
}
void dfs(int u){
if(u < N){
tL[k][u] = ++dfsTimer;
}else{
tL[k][u] = 1+dfsTimer;
auto &[vL, vR] = g[u-N];
dfs(vL);
if(vL != vR) dfs(vR);
}
tR[k][u] = dfsTimer;
}
vi check_validity(int __N, vi X, vi Y, vi S, vi E, vi L, vi R){
N = __N, Q = size(S), M = size(X);
for(int i=0; i<M; ++i)
if(X[i] > Y[i]) swap(X[i], Y[i]);
vi h(M);
iota(begin(h), end(h), 0);
for(; k<2; ++k){
sort(begin(h), end(h), [&](int &u, int &v){
return k ? X[u] > X[v] : Y[u] < Y[v];
});
iota(r, r+N, 0);
fill(e, e+N,-1);
for(int &i : h){
int u = find(X[i]), v = find(Y[i]);
p[k][0][r[u]] = i+N;
p[k][0][r[v]] = i+N;
g[i] = {r[u], r[v]};
if(e[u] > e[v]) swap(u, v);
if(u != v){
e[u] += e[v];
e[v] = u;
}
r[u] = i+N;
}
dfsTimer = -1;
dfs(p[k][0][h.back()+N] = h.back()+N);
for(int i=0; i+1<LOG; ++i)
for(int u=0; u<N+M; ++u)
p[k][i+1][u] = p[k][i][p[k][i][u]];
}
vector<array<int, 3>> q(Q);
for(int i=0; i<Q; ++i){
int u = E[i];
for(int j=LOG; --j>=0; )
if(Y[p[0][j][u] - N] <= R[i]) u = p[0][j][u];
q[i] = {tL[0][u], tR[0][u], i};
}
vi byL(N), res(Q); int pt = N-1;
iota(begin(byL), end(byL), 0);
sort(begin(byL), end(byL), [&](int u, int v){
return tL[0][u] < tL[0][v];
});
sort(rbegin(q), rend(q));
fill(st, st+N+N, ML);
for(auto &[lx, rx, id] : q){
while(pt>=0 && tL[0][byL[pt]] >= lx){
int i = tL[1][byL[pt]];
for(st[i+=N]=tL[0][byL[pt]]; i/=2; )
st[i] = min(st[2*i], st[2*i+1]);
--pt;
}
int u = S[id];
for(int j=LOG; --j>=0; )
if(X[p[1][j][u] - N] >= L[id]) u = p[1][j][u];
int qL = tL[1][u], qR = tR[1][u], x = N+N;
for(qL+=N, qR+=N+1; qL<qR; qL/=2, qR/=2){
if(qL & 1) x = min(x, st[qL++]);
if(qR & 1) x = min(x, st[--qR]);
}
res[id] = x <= rx;
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
716 KB |
Output is correct |
2 |
Correct |
1 ms |
716 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
716 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
716 KB |
Output is correct |
2 |
Correct |
1 ms |
716 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
716 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
7 ms |
2216 KB |
Output is correct |
11 |
Correct |
7 ms |
2124 KB |
Output is correct |
12 |
Correct |
6 ms |
2124 KB |
Output is correct |
13 |
Correct |
7 ms |
2252 KB |
Output is correct |
14 |
Correct |
6 ms |
2252 KB |
Output is correct |
15 |
Correct |
10 ms |
2892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
738 ms |
99864 KB |
Output is correct |
2 |
Correct |
1075 ms |
102928 KB |
Output is correct |
3 |
Correct |
905 ms |
100932 KB |
Output is correct |
4 |
Correct |
785 ms |
100016 KB |
Output is correct |
5 |
Correct |
798 ms |
99964 KB |
Output is correct |
6 |
Correct |
803 ms |
99800 KB |
Output is correct |
7 |
Correct |
680 ms |
99812 KB |
Output is correct |
8 |
Correct |
958 ms |
102996 KB |
Output is correct |
9 |
Correct |
561 ms |
101044 KB |
Output is correct |
10 |
Correct |
466 ms |
99888 KB |
Output is correct |
11 |
Correct |
524 ms |
99964 KB |
Output is correct |
12 |
Correct |
497 ms |
100036 KB |
Output is correct |
13 |
Correct |
1162 ms |
102984 KB |
Output is correct |
14 |
Correct |
1102 ms |
102856 KB |
Output is correct |
15 |
Correct |
1099 ms |
102940 KB |
Output is correct |
16 |
Correct |
1116 ms |
102948 KB |
Output is correct |
17 |
Correct |
706 ms |
99796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
716 KB |
Output is correct |
2 |
Correct |
1 ms |
716 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
1 ms |
716 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
7 ms |
2216 KB |
Output is correct |
11 |
Correct |
7 ms |
2124 KB |
Output is correct |
12 |
Correct |
6 ms |
2124 KB |
Output is correct |
13 |
Correct |
7 ms |
2252 KB |
Output is correct |
14 |
Correct |
6 ms |
2252 KB |
Output is correct |
15 |
Correct |
10 ms |
2892 KB |
Output is correct |
16 |
Correct |
738 ms |
99864 KB |
Output is correct |
17 |
Correct |
1075 ms |
102928 KB |
Output is correct |
18 |
Correct |
905 ms |
100932 KB |
Output is correct |
19 |
Correct |
785 ms |
100016 KB |
Output is correct |
20 |
Correct |
798 ms |
99964 KB |
Output is correct |
21 |
Correct |
803 ms |
99800 KB |
Output is correct |
22 |
Correct |
680 ms |
99812 KB |
Output is correct |
23 |
Correct |
958 ms |
102996 KB |
Output is correct |
24 |
Correct |
561 ms |
101044 KB |
Output is correct |
25 |
Correct |
466 ms |
99888 KB |
Output is correct |
26 |
Correct |
524 ms |
99964 KB |
Output is correct |
27 |
Correct |
497 ms |
100036 KB |
Output is correct |
28 |
Correct |
1162 ms |
102984 KB |
Output is correct |
29 |
Correct |
1102 ms |
102856 KB |
Output is correct |
30 |
Correct |
1099 ms |
102940 KB |
Output is correct |
31 |
Correct |
1116 ms |
102948 KB |
Output is correct |
32 |
Correct |
706 ms |
99796 KB |
Output is correct |
33 |
Correct |
901 ms |
100588 KB |
Output is correct |
34 |
Correct |
1415 ms |
117232 KB |
Output is correct |
35 |
Correct |
1142 ms |
107432 KB |
Output is correct |
36 |
Correct |
861 ms |
101572 KB |
Output is correct |
37 |
Correct |
1025 ms |
104528 KB |
Output is correct |
38 |
Correct |
935 ms |
102996 KB |
Output is correct |
39 |
Correct |
924 ms |
106328 KB |
Output is correct |
40 |
Correct |
1263 ms |
147856 KB |
Output is correct |
41 |
Correct |
780 ms |
102932 KB |
Output is correct |
42 |
Correct |
551 ms |
101440 KB |
Output is correct |
43 |
Correct |
1275 ms |
128452 KB |
Output is correct |
44 |
Correct |
988 ms |
104388 KB |
Output is correct |
45 |
Correct |
678 ms |
108504 KB |
Output is correct |
46 |
Correct |
742 ms |
106276 KB |
Output is correct |
47 |
Correct |
1136 ms |
104200 KB |
Output is correct |
48 |
Correct |
1144 ms |
103056 KB |
Output is correct |
49 |
Correct |
1135 ms |
104184 KB |
Output is correct |
50 |
Correct |
1122 ms |
103136 KB |
Output is correct |
51 |
Correct |
1268 ms |
147548 KB |
Output is correct |
52 |
Correct |
1225 ms |
147620 KB |
Output is correct |