# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1003226 |
2024-06-20T08:02:44 Z |
pera |
Werewolf (IOI18_werewolf) |
C++17 |
|
738 ms |
142844 KB |
#include<bits/stdc++.h>
#include "werewolf.h"
using namespace std;
const int NMAX = 2e5 + 1 , LOG = 20;
int T = 0;
vector<int> ri(NMAX) , rd(NMAX) , ini(NMAX) , outi(NMAX) , ind(NMAX) , outd(NMAX) , t(4 * NMAX) , ord = {0};
vector<vector<int>> p(NMAX , vector<int>(2)) , g(NMAX) , gi(NMAX) , gd(NMAX);
vector<vector<vector<int>>> up(2 , vector<vector<int>>(NMAX , vector<int>(LOG))) , queries(NMAX);
void update(int u , int l , int r , int pos , int x){
if(l == r){
t[u] = x;
return;
}
int m = (l + r) / 2;
if(pos <= m){
update(u * 2 , l , m , pos , x);
}else{
update(u * 2 + 1 , m + 1 , r , pos , x);
}
t[u] = max(t[u * 2] , t[u * 2 + 1]);
}
int get(int u , int l , int r , int L , int R){
if(l > r || r < L || l > R){
return 0;
}
if(L <= l && r <= R){
return t[u];
}
int m = (l + r) / 2;
return max(get(u * 2 , l , m , L , R) , get(u * 2 + 1 , m + 1 , r , L , R));
}
int find(int u , int type){
return p[u][type] == u ? p[u][type] : p[u][type] = find(p[u][type] , type);
}
void unite(int u , int v , int type){
int root_u = find(u , type) , root_v = find(v , type);
if(root_u != root_v){
p[root_v][type] = root_u;
type == 0 ? ri[root_v] = u : rd[root_v] = u;
}
}
void dfsi(int u){
ini[u] = ++T;
for(int x : gi[u]){
dfsi(x);
}
outi[u] = T;
}
void dfsd(int u){
ord.push_back(u);
ind[u] = ++T;
for(int x : gd[u]){
dfsd(x);
}
outd[u] = T;
}
int max_up_L(int u , int val){
for(int bit = LOG - 1;bit >= 0;bit--){
if(up[1][u][bit] >= val){
u = up[1][u][bit];
}
}
return u;
}
int max_up_R(int u , int val){
for(int bit = LOG - 1;bit >= 0;bit --){
if(up[0][u][bit] <= val){
u = up[0][u][bit];
}
}
return u;
}
vector<int> check_validity(int N , vector<int> X , vector<int> Y , vector<int> S , vector<int> E , vector<int> L , vector<int> R){
int M = (int)X.size();
for(int i = 0;i < M;i ++){
g[++X[i]].push_back(++Y[i]);
g[Y[i]].push_back(X[i]);
}
for(int i = 1;i <= N;i ++){
for(int x = 0;x < 2;x ++){
p[i][x] = i;
}
ri[i] = rd[i] = i;
}
for(int i = 1;i <= N;i ++){
for(int x : g[i]){
if(x < i){
unite(i , x , 0);
}
}
}
for(int i = N;i >= 1;i --){
for(int x : g[i]){
if(x > i){
unite(i , x , 1);
}
}
}
for(int i = 1;i <= N;i ++){
up[0][i][0] = ri[i];
up[1][i][0] = rd[i];
if(ri[i] != i){
gi[ri[i]].push_back(i);
}
if(rd[i] != i){
gd[rd[i]].push_back(i);
}
}
dfsi(N);
T = 0;
dfsd(1);
for(int bit = 1;bit < LOG;bit ++){
for(int i = 1;i <= N;i ++){
for(int x = 0;x < 2;x ++){
up[x][i][bit] = up[x][up[x][i][bit - 1]][bit - 1];
}
}
}
int Q = (int)S.size();
vector<int> ans(Q);
for(int i = 0;i < Q;i ++){
int root_S = max_up_L(++S[i] , ++L[i]);
int root_E = max_up_R(++E[i] , ++R[i]);
queries[outd[root_S]].push_back({ind[root_S] , ini[root_E] , outi[root_E] , i});
}
for(int i = 1;i <= N;i ++){
update(1 , 1 , N , ini[ord[i]] , i);
for(auto x : queries[i]){
ans[x[3]] = get(1 , 1 , N , x[1] , x[2]) >= x[0];
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
103664 KB |
Output is correct |
2 |
Correct |
54 ms |
103760 KB |
Output is correct |
3 |
Correct |
55 ms |
103548 KB |
Output is correct |
4 |
Correct |
58 ms |
103504 KB |
Output is correct |
5 |
Correct |
63 ms |
103508 KB |
Output is correct |
6 |
Correct |
58 ms |
103504 KB |
Output is correct |
7 |
Correct |
72 ms |
103508 KB |
Output is correct |
8 |
Correct |
94 ms |
103508 KB |
Output is correct |
9 |
Correct |
73 ms |
103760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
103664 KB |
Output is correct |
2 |
Correct |
54 ms |
103760 KB |
Output is correct |
3 |
Correct |
55 ms |
103548 KB |
Output is correct |
4 |
Correct |
58 ms |
103504 KB |
Output is correct |
5 |
Correct |
63 ms |
103508 KB |
Output is correct |
6 |
Correct |
58 ms |
103504 KB |
Output is correct |
7 |
Correct |
72 ms |
103508 KB |
Output is correct |
8 |
Correct |
94 ms |
103508 KB |
Output is correct |
9 |
Correct |
73 ms |
103760 KB |
Output is correct |
10 |
Correct |
73 ms |
103628 KB |
Output is correct |
11 |
Correct |
69 ms |
103664 KB |
Output is correct |
12 |
Correct |
66 ms |
103508 KB |
Output is correct |
13 |
Correct |
80 ms |
103760 KB |
Output is correct |
14 |
Correct |
65 ms |
103508 KB |
Output is correct |
15 |
Correct |
65 ms |
103504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
617 ms |
133376 KB |
Output is correct |
2 |
Correct |
567 ms |
135916 KB |
Output is correct |
3 |
Correct |
561 ms |
133116 KB |
Output is correct |
4 |
Correct |
579 ms |
132352 KB |
Output is correct |
5 |
Correct |
563 ms |
132528 KB |
Output is correct |
6 |
Correct |
521 ms |
133500 KB |
Output is correct |
7 |
Correct |
501 ms |
132352 KB |
Output is correct |
8 |
Correct |
562 ms |
135684 KB |
Output is correct |
9 |
Correct |
449 ms |
132368 KB |
Output is correct |
10 |
Correct |
379 ms |
132212 KB |
Output is correct |
11 |
Correct |
386 ms |
132476 KB |
Output is correct |
12 |
Correct |
417 ms |
131888 KB |
Output is correct |
13 |
Correct |
589 ms |
141320 KB |
Output is correct |
14 |
Correct |
629 ms |
141308 KB |
Output is correct |
15 |
Correct |
570 ms |
141308 KB |
Output is correct |
16 |
Correct |
668 ms |
141308 KB |
Output is correct |
17 |
Correct |
467 ms |
132352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
103664 KB |
Output is correct |
2 |
Correct |
54 ms |
103760 KB |
Output is correct |
3 |
Correct |
55 ms |
103548 KB |
Output is correct |
4 |
Correct |
58 ms |
103504 KB |
Output is correct |
5 |
Correct |
63 ms |
103508 KB |
Output is correct |
6 |
Correct |
58 ms |
103504 KB |
Output is correct |
7 |
Correct |
72 ms |
103508 KB |
Output is correct |
8 |
Correct |
94 ms |
103508 KB |
Output is correct |
9 |
Correct |
73 ms |
103760 KB |
Output is correct |
10 |
Correct |
73 ms |
103628 KB |
Output is correct |
11 |
Correct |
69 ms |
103664 KB |
Output is correct |
12 |
Correct |
66 ms |
103508 KB |
Output is correct |
13 |
Correct |
80 ms |
103760 KB |
Output is correct |
14 |
Correct |
65 ms |
103508 KB |
Output is correct |
15 |
Correct |
65 ms |
103504 KB |
Output is correct |
16 |
Correct |
617 ms |
133376 KB |
Output is correct |
17 |
Correct |
567 ms |
135916 KB |
Output is correct |
18 |
Correct |
561 ms |
133116 KB |
Output is correct |
19 |
Correct |
579 ms |
132352 KB |
Output is correct |
20 |
Correct |
563 ms |
132528 KB |
Output is correct |
21 |
Correct |
521 ms |
133500 KB |
Output is correct |
22 |
Correct |
501 ms |
132352 KB |
Output is correct |
23 |
Correct |
562 ms |
135684 KB |
Output is correct |
24 |
Correct |
449 ms |
132368 KB |
Output is correct |
25 |
Correct |
379 ms |
132212 KB |
Output is correct |
26 |
Correct |
386 ms |
132476 KB |
Output is correct |
27 |
Correct |
417 ms |
131888 KB |
Output is correct |
28 |
Correct |
589 ms |
141320 KB |
Output is correct |
29 |
Correct |
629 ms |
141308 KB |
Output is correct |
30 |
Correct |
570 ms |
141308 KB |
Output is correct |
31 |
Correct |
668 ms |
141308 KB |
Output is correct |
32 |
Correct |
467 ms |
132352 KB |
Output is correct |
33 |
Correct |
615 ms |
133880 KB |
Output is correct |
34 |
Correct |
267 ms |
129020 KB |
Output is correct |
35 |
Correct |
667 ms |
136708 KB |
Output is correct |
36 |
Correct |
535 ms |
134144 KB |
Output is correct |
37 |
Correct |
598 ms |
135828 KB |
Output is correct |
38 |
Correct |
576 ms |
134764 KB |
Output is correct |
39 |
Correct |
604 ms |
141164 KB |
Output is correct |
40 |
Correct |
698 ms |
142844 KB |
Output is correct |
41 |
Correct |
525 ms |
134488 KB |
Output is correct |
42 |
Correct |
465 ms |
133376 KB |
Output is correct |
43 |
Correct |
722 ms |
141864 KB |
Output is correct |
44 |
Correct |
670 ms |
135788 KB |
Output is correct |
45 |
Correct |
507 ms |
140544 KB |
Output is correct |
46 |
Correct |
544 ms |
140544 KB |
Output is correct |
47 |
Correct |
634 ms |
141312 KB |
Output is correct |
48 |
Correct |
699 ms |
141228 KB |
Output is correct |
49 |
Correct |
738 ms |
141308 KB |
Output is correct |
50 |
Correct |
691 ms |
141376 KB |
Output is correct |
51 |
Correct |
728 ms |
142704 KB |
Output is correct |
52 |
Correct |
710 ms |
142584 KB |
Output is correct |