# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
465398 |
2021-08-15T20:45:52 Z |
dutch |
Werewolf (IOI18_werewolf) |
C++17 |
|
4000 ms |
52512 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];
vi g[2][NL], g2[NL];
int find(int u){
return e[u] < 0 ? u : e[u] = find(e[u]);
}
void dfs(int u){
tL[k][u] = ++dfsTimer;
for(int v : g2[u]) dfs(v);
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]);
g[0][Y[i]].push_back(X[i]);
g[1][X[i]].push_back(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){
iota(r, r+N, 0);
fill(e, e+N,-1);
for(int &i : h){
if(k) while(Sp >= 0 && L[byS[Sp]] > i)
lca[k][byS[Sp]] = r[find(S[byS[Sp]])], --Sp;
else while(Ep >= 0 && R[byE[Ep]] < i)
lca[k][byE[Ep]] = r[find(E[byE[Ep]])], --Ep;
g2[i].clear();
int u = i;
for(int v : g[k][u]){
u = find(u), v = find(v);
g2[i].push_back(r[v]);
if(u != v){
if(e[u] > e[v]) swap(u, v);
e[u] += e[v], e[v] = u;
}
}
r[find(u)] = i;
}
if(k) for(int i=0; i<=Sp; ++i) lca[k][byS[i]] = h.back();
else for(int i=0; i<=Ep; ++i) lca[k][byE[i]] = h.back();
dfsTimer = -1;
dfs(h.back());
reverse(begin(h), end(h));
}
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 |
Execution timed out |
4074 ms |
14412 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4074 ms |
14412 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
579 ms |
52512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4074 ms |
14412 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |