# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
465388 |
2021-08-15T19:40:26 Z |
dutch |
Werewolf (IOI18_werewolf) |
C++17 |
|
664 ms |
42692 KB |
#include <bits/stdc++.h>
using namespace std;
#include "werewolf.h"
typedef vector<int> vi;
#define vii(Z) iota(begin(Z), end(Z), 0)
const int NL = 2e5, ML = 6e5;
int N, M, Q, k, dfsTimer;
int e[NL], r[NL], lca[2][NL], st[2*NL], tL[2][ML], tR[2][ML];
array<int, 2> g[ML];
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); vii(h);
vi byE(Q); vii(byE);
vi byS(Q); vii(byS);
sort(begin(byS), end(byS), [&](int u, int v){ return L[u] < L[v]; });
sort(begin(byE), end(byE), [&](int u, int v){ return R[u] > R[v]; });
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]);
if(k) while(!empty(byS) && L[byS.back()] > X[i]){
lca[k][byS.back()] = r[find(S[byS.back()])];
byS.pop_back();
}else while(!empty(byE) && R[byE.back()] < Y[i]){
lca[k][byE.back()] = r[find(E[byE.back()])];
byE.pop_back();
}
if(e[u] > e[v]) swap(u, v);
g[i] = {r[u], r[v]};
if(u != v){
e[u] += e[v];
e[v] = u;
}
r[u] = i+N;
}
if(k) for(int &i : byS) lca[k][i] = h.back() + N;
else for(int &i : byE) lca[k][i] = h.back() + N;
dfsTimer = -1;
dfs(h.back()+N);
}
vector<array<int, 3>> q(Q);
for(int i=0; i<Q; ++i)
q[i] = {tL[0][lca[0][i]], tR[0][lca[0][i]], i};
vi byL(N), res(Q); int pt = N-1;
vii(byL);
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 qL = tL[1][lca[1][id]], qR = tR[1][lca[1][id]], 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 |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
5 ms |
844 KB |
Output is correct |
11 |
Correct |
5 ms |
716 KB |
Output is correct |
12 |
Correct |
5 ms |
716 KB |
Output is correct |
13 |
Correct |
5 ms |
844 KB |
Output is correct |
14 |
Correct |
5 ms |
844 KB |
Output is correct |
15 |
Correct |
7 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
456 ms |
28440 KB |
Output is correct |
2 |
Correct |
432 ms |
31628 KB |
Output is correct |
3 |
Correct |
433 ms |
29580 KB |
Output is correct |
4 |
Correct |
429 ms |
28696 KB |
Output is correct |
5 |
Correct |
454 ms |
28688 KB |
Output is correct |
6 |
Correct |
454 ms |
28556 KB |
Output is correct |
7 |
Correct |
414 ms |
28560 KB |
Output is correct |
8 |
Correct |
412 ms |
31640 KB |
Output is correct |
9 |
Correct |
425 ms |
29616 KB |
Output is correct |
10 |
Correct |
419 ms |
28692 KB |
Output is correct |
11 |
Correct |
412 ms |
28740 KB |
Output is correct |
12 |
Correct |
417 ms |
28560 KB |
Output is correct |
13 |
Correct |
429 ms |
31668 KB |
Output is correct |
14 |
Correct |
433 ms |
31640 KB |
Output is correct |
15 |
Correct |
422 ms |
31556 KB |
Output is correct |
16 |
Correct |
436 ms |
31672 KB |
Output is correct |
17 |
Correct |
415 ms |
28460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
5 ms |
844 KB |
Output is correct |
11 |
Correct |
5 ms |
716 KB |
Output is correct |
12 |
Correct |
5 ms |
716 KB |
Output is correct |
13 |
Correct |
5 ms |
844 KB |
Output is correct |
14 |
Correct |
5 ms |
844 KB |
Output is correct |
15 |
Correct |
7 ms |
972 KB |
Output is correct |
16 |
Correct |
456 ms |
28440 KB |
Output is correct |
17 |
Correct |
432 ms |
31628 KB |
Output is correct |
18 |
Correct |
433 ms |
29580 KB |
Output is correct |
19 |
Correct |
429 ms |
28696 KB |
Output is correct |
20 |
Correct |
454 ms |
28688 KB |
Output is correct |
21 |
Correct |
454 ms |
28556 KB |
Output is correct |
22 |
Correct |
414 ms |
28560 KB |
Output is correct |
23 |
Correct |
412 ms |
31640 KB |
Output is correct |
24 |
Correct |
425 ms |
29616 KB |
Output is correct |
25 |
Correct |
419 ms |
28692 KB |
Output is correct |
26 |
Correct |
412 ms |
28740 KB |
Output is correct |
27 |
Correct |
417 ms |
28560 KB |
Output is correct |
28 |
Correct |
429 ms |
31668 KB |
Output is correct |
29 |
Correct |
433 ms |
31640 KB |
Output is correct |
30 |
Correct |
422 ms |
31556 KB |
Output is correct |
31 |
Correct |
436 ms |
31672 KB |
Output is correct |
32 |
Correct |
415 ms |
28460 KB |
Output is correct |
33 |
Correct |
482 ms |
29292 KB |
Output is correct |
34 |
Correct |
552 ms |
42692 KB |
Output is correct |
35 |
Correct |
497 ms |
32580 KB |
Output is correct |
36 |
Correct |
470 ms |
29344 KB |
Output is correct |
37 |
Correct |
519 ms |
31468 KB |
Output is correct |
38 |
Correct |
456 ms |
30172 KB |
Output is correct |
39 |
Correct |
434 ms |
34840 KB |
Output is correct |
40 |
Correct |
617 ms |
40828 KB |
Output is correct |
41 |
Correct |
456 ms |
30736 KB |
Output is correct |
42 |
Correct |
438 ms |
29252 KB |
Output is correct |
43 |
Correct |
584 ms |
39284 KB |
Output is correct |
44 |
Correct |
464 ms |
31352 KB |
Output is correct |
45 |
Correct |
410 ms |
35416 KB |
Output is correct |
46 |
Correct |
413 ms |
34848 KB |
Output is correct |
47 |
Correct |
455 ms |
31892 KB |
Output is correct |
48 |
Correct |
453 ms |
31688 KB |
Output is correct |
49 |
Correct |
431 ms |
31936 KB |
Output is correct |
50 |
Correct |
450 ms |
31628 KB |
Output is correct |
51 |
Correct |
626 ms |
40476 KB |
Output is correct |
52 |
Correct |
664 ms |
40580 KB |
Output is correct |