# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
465390 |
2021-08-15T19:46:42 Z |
dutch |
Werewolf (IOI18_werewolf) |
C++17 |
|
635 ms |
42628 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);
int Ep = Q - 1, Sp = Q - 1;
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(Sp >= 0 && L[byS[Sp]] > X[i])
lca[k][byS[Sp]] = r[find(S[byS[Sp]])], --Sp;
else while(Ep >= 0 && R[byE[Ep]] < Y[i])
lca[k][byE[Ep]] = r[find(E[byE[Ep]])], --Ep;
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=0; i<=Sp; ++i) lca[k][byS[i]] = h.back() + N;
else for(int i=0; i<=Ep; ++i) lca[k][byE[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 |
304 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 |
304 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 |
451 ms |
28428 KB |
Output is correct |
2 |
Correct |
424 ms |
31684 KB |
Output is correct |
3 |
Correct |
416 ms |
29592 KB |
Output is correct |
4 |
Correct |
449 ms |
28732 KB |
Output is correct |
5 |
Correct |
435 ms |
28760 KB |
Output is correct |
6 |
Correct |
442 ms |
28564 KB |
Output is correct |
7 |
Correct |
422 ms |
28528 KB |
Output is correct |
8 |
Correct |
408 ms |
31600 KB |
Output is correct |
9 |
Correct |
390 ms |
29664 KB |
Output is correct |
10 |
Correct |
398 ms |
28704 KB |
Output is correct |
11 |
Correct |
411 ms |
28688 KB |
Output is correct |
12 |
Correct |
425 ms |
28568 KB |
Output is correct |
13 |
Correct |
425 ms |
31556 KB |
Output is correct |
14 |
Correct |
447 ms |
31616 KB |
Output is correct |
15 |
Correct |
427 ms |
31660 KB |
Output is correct |
16 |
Correct |
418 ms |
31640 KB |
Output is correct |
17 |
Correct |
431 ms |
28464 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 |
304 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 |
451 ms |
28428 KB |
Output is correct |
17 |
Correct |
424 ms |
31684 KB |
Output is correct |
18 |
Correct |
416 ms |
29592 KB |
Output is correct |
19 |
Correct |
449 ms |
28732 KB |
Output is correct |
20 |
Correct |
435 ms |
28760 KB |
Output is correct |
21 |
Correct |
442 ms |
28564 KB |
Output is correct |
22 |
Correct |
422 ms |
28528 KB |
Output is correct |
23 |
Correct |
408 ms |
31600 KB |
Output is correct |
24 |
Correct |
390 ms |
29664 KB |
Output is correct |
25 |
Correct |
398 ms |
28704 KB |
Output is correct |
26 |
Correct |
411 ms |
28688 KB |
Output is correct |
27 |
Correct |
425 ms |
28568 KB |
Output is correct |
28 |
Correct |
425 ms |
31556 KB |
Output is correct |
29 |
Correct |
447 ms |
31616 KB |
Output is correct |
30 |
Correct |
427 ms |
31660 KB |
Output is correct |
31 |
Correct |
418 ms |
31640 KB |
Output is correct |
32 |
Correct |
431 ms |
28464 KB |
Output is correct |
33 |
Correct |
455 ms |
29380 KB |
Output is correct |
34 |
Correct |
589 ms |
42628 KB |
Output is correct |
35 |
Correct |
529 ms |
32588 KB |
Output is correct |
36 |
Correct |
495 ms |
29240 KB |
Output is correct |
37 |
Correct |
519 ms |
31456 KB |
Output is correct |
38 |
Correct |
510 ms |
30044 KB |
Output is correct |
39 |
Correct |
418 ms |
34832 KB |
Output is correct |
40 |
Correct |
635 ms |
40644 KB |
Output is correct |
41 |
Correct |
452 ms |
30772 KB |
Output is correct |
42 |
Correct |
434 ms |
29360 KB |
Output is correct |
43 |
Correct |
563 ms |
39240 KB |
Output is correct |
44 |
Correct |
469 ms |
31460 KB |
Output is correct |
45 |
Correct |
434 ms |
35532 KB |
Output is correct |
46 |
Correct |
425 ms |
34856 KB |
Output is correct |
47 |
Correct |
453 ms |
31936 KB |
Output is correct |
48 |
Correct |
495 ms |
31736 KB |
Output is correct |
49 |
Correct |
445 ms |
31840 KB |
Output is correct |
50 |
Correct |
442 ms |
31628 KB |
Output is correct |
51 |
Correct |
616 ms |
40560 KB |
Output is correct |
52 |
Correct |
629 ms |
40400 KB |
Output is correct |