# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
443143 |
2021-07-09T19:30:39 Z |
JovanB |
Werewolf (IOI18_werewolf) |
C++17 |
|
1184 ms |
149312 KB |
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 200000;
struct Edge{
int a, b, c;
bool operator <(const Edge &x){
return c < x.c;
}
};
struct DSU{
int n;
int par[MAXN+5];
int label[MAXN+5];
int sz[MAXN+5];
DSU(int g){
n = g;
for(int i=1; i<=n; i++){
par[i] = i;
label[i] = i;
sz[i] = 1;
}
}
int root(int x){ return (par[x] == x ? x : par[x] = root(par[x])); }
void povezi(int a, int b, int lab){
if(sz[a] < sz[b]) swap(a, b);
label[a] = lab;
sz[a] += sz[b];
par[b] = a;
}
};
const int LOG = 20;
struct PMST{
int n;
vector <pair <int, int>> graf[2*MAXN+5];
int L[2*MAXN+5];
int R[2*MAXN+5];
int val[2*MAXN+5];
int par[2*MAXN+5][LOG+1];
int niz[MAXN+5];
int tn = 0;
void dfs(int v, int p, int w){
val[p] = w;
par[v][0] = p;
for(int j=1; j<=LOG; j++) par[v][j] = par[par[v][j-1]][j-1];
L[v] = 2*MAXN+5;
R[v] = 0;
for(auto c : graf[v]){
dfs(c.first, v, c.second);
L[v] = min(L[v], L[c.first]);
R[v] = max(R[v], R[c.first]);
}
if(!graf[v].size()){
tn++;
L[v] = R[v] = tn;
niz[tn] = v;
}
}
};
PMST tree1, tree2;
int l1[MAXN+5];
int r1[MAXN+5];
int l2[MAXN+5];
int r2[MAXN+5];
int gde[MAXN+5];
int dizi_max(int v, int lm){
for(int j=LOG; j>=0; j--) if(tree1.val[tree1.par[v][j]] <= lm) v = tree1.par[v][j];
return v;
}
int dizi_min(int v, int lm){
for(int j=LOG; j>=0; j--) if(tree2.val[tree2.par[v][j]] >= lm) v = tree2.par[v][j];
return v;
}
vector <int> queries[MAXN+5];
int bit[MAXN+5];
void addbit(int x){
while(x <= MAXN){
bit[x]++;
x += x & -x;
}
}
int getbit(int x){
int res = 0;
while(x){
res += bit[x];
x -= x & -x;
}
return res;
}
std::vector<int> check_validity(int N, std::vector<int> X, std::vector<int> Y, std::vector<int> S, std::vector<int> E, std::vector<int> L, std::vector<int> R) {
int m = X.size();
vector <Edge> e1, e2;
for(int i=0; i<m; i++){
int a = X[i] + 1;
int b = Y[i] + 1;
e1.push_back({a, b, max(a, b)});
e2.push_back({a, b, min(a, b)});
}
sort(e1.begin(), e1.end());
sort(e2.begin(), e2.end());
reverse(e2.begin(), e2.end());
int n = N;
DSU dsu1(n);
DSU dsu2(n);
int lab1 = n;
int lab2 = n;
for(auto edge : e1){
int a = edge.a;
int b = edge.b;
int c = edge.c;
int a1 = dsu1.root(a);
int b1 = dsu1.root(b);
if(a1 == b1) continue;
lab1++;
tree1.graf[lab1].push_back({dsu1.label[a1], c});
tree1.graf[lab1].push_back({dsu1.label[b1], c});
dsu1.povezi(a1, b1, lab1);
}
tree1.n = lab1;
for(auto edge : e2){
int a = edge.a;
int b = edge.b;
int c = edge.c;
int a1 = dsu2.root(a);
int b1 = dsu2.root(b);
if(a1 == b1) continue;
lab2++;
tree2.graf[lab2].push_back({dsu2.label[a1], c});
tree2.graf[lab2].push_back({dsu2.label[b1], c});
dsu2.povezi(a1, b1, lab2);
}
tree2.n = lab2;
tree1.dfs(lab1, 0, 10*MAXN);
cout << endl;
tree2.dfs(lab2, 0, 0);
vector <int> soln;
int qrs = S.size();
for(int i=0; i<qrs; i++) soln.push_back(0);
for(int i=0; i<qrs; i++){
swap(S[i], E[i]);
S[i]++;
E[i]++;
L[i]++;
R[i]++;
int v = dizi_max(S[i], R[i]);
l1[i] = tree1.L[v];
r1[i] = tree1.R[v];
v = dizi_min(E[i], L[i]);
l2[i] = tree2.L[v];
r2[i] = tree2.R[v];
queries[l2[i]-1].push_back(-(i+1));
queries[r2[i]].push_back(i+1);
}
for(int i=1; i<=n; i++){
gde[tree1.niz[i]] = i;
}
for(int i=1; i<=n; i++){
tree1.niz[i] = gde[tree1.niz[i]];
tree2.niz[i] = gde[tree2.niz[i]];
}
for(int i=1; i<=n; i++){
addbit(tree2.niz[i]);
for(auto ind : queries[i]){
int kf = 1;
if(ind < 0){
kf = -1;
ind = -ind;
}
soln[ind-1] += kf*getbit(r1[ind-1]);
soln[ind-1] -= kf*getbit(l1[ind-1] - 1);
}
}
for(int i=0; i<qrs; i++) if(soln[i] > 0) soln[i] = 1;
return soln;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
28620 KB |
Output is correct |
2 |
Correct |
16 ms |
28668 KB |
Output is correct |
3 |
Correct |
15 ms |
28620 KB |
Output is correct |
4 |
Correct |
18 ms |
28620 KB |
Output is correct |
5 |
Correct |
17 ms |
28620 KB |
Output is correct |
6 |
Correct |
17 ms |
28680 KB |
Output is correct |
7 |
Correct |
15 ms |
28620 KB |
Output is correct |
8 |
Correct |
15 ms |
28620 KB |
Output is correct |
9 |
Correct |
18 ms |
28620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
28620 KB |
Output is correct |
2 |
Correct |
16 ms |
28668 KB |
Output is correct |
3 |
Correct |
15 ms |
28620 KB |
Output is correct |
4 |
Correct |
18 ms |
28620 KB |
Output is correct |
5 |
Correct |
17 ms |
28620 KB |
Output is correct |
6 |
Correct |
17 ms |
28680 KB |
Output is correct |
7 |
Correct |
15 ms |
28620 KB |
Output is correct |
8 |
Correct |
15 ms |
28620 KB |
Output is correct |
9 |
Correct |
18 ms |
28620 KB |
Output is correct |
10 |
Correct |
23 ms |
30444 KB |
Output is correct |
11 |
Correct |
25 ms |
30336 KB |
Output is correct |
12 |
Correct |
26 ms |
30420 KB |
Output is correct |
13 |
Correct |
26 ms |
30460 KB |
Output is correct |
14 |
Correct |
25 ms |
30528 KB |
Output is correct |
15 |
Correct |
27 ms |
30560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
989 ms |
140520 KB |
Output is correct |
2 |
Correct |
1074 ms |
142856 KB |
Output is correct |
3 |
Correct |
855 ms |
139728 KB |
Output is correct |
4 |
Correct |
795 ms |
138684 KB |
Output is correct |
5 |
Correct |
805 ms |
138796 KB |
Output is correct |
6 |
Correct |
931 ms |
139552 KB |
Output is correct |
7 |
Correct |
853 ms |
138952 KB |
Output is correct |
8 |
Correct |
949 ms |
142852 KB |
Output is correct |
9 |
Correct |
671 ms |
139816 KB |
Output is correct |
10 |
Correct |
608 ms |
138148 KB |
Output is correct |
11 |
Correct |
630 ms |
138068 KB |
Output is correct |
12 |
Correct |
700 ms |
137912 KB |
Output is correct |
13 |
Correct |
1164 ms |
144532 KB |
Output is correct |
14 |
Correct |
1140 ms |
144572 KB |
Output is correct |
15 |
Correct |
1141 ms |
144612 KB |
Output is correct |
16 |
Correct |
1134 ms |
144504 KB |
Output is correct |
17 |
Correct |
866 ms |
138952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
28620 KB |
Output is correct |
2 |
Correct |
16 ms |
28668 KB |
Output is correct |
3 |
Correct |
15 ms |
28620 KB |
Output is correct |
4 |
Correct |
18 ms |
28620 KB |
Output is correct |
5 |
Correct |
17 ms |
28620 KB |
Output is correct |
6 |
Correct |
17 ms |
28680 KB |
Output is correct |
7 |
Correct |
15 ms |
28620 KB |
Output is correct |
8 |
Correct |
15 ms |
28620 KB |
Output is correct |
9 |
Correct |
18 ms |
28620 KB |
Output is correct |
10 |
Correct |
23 ms |
30444 KB |
Output is correct |
11 |
Correct |
25 ms |
30336 KB |
Output is correct |
12 |
Correct |
26 ms |
30420 KB |
Output is correct |
13 |
Correct |
26 ms |
30460 KB |
Output is correct |
14 |
Correct |
25 ms |
30528 KB |
Output is correct |
15 |
Correct |
27 ms |
30560 KB |
Output is correct |
16 |
Correct |
989 ms |
140520 KB |
Output is correct |
17 |
Correct |
1074 ms |
142856 KB |
Output is correct |
18 |
Correct |
855 ms |
139728 KB |
Output is correct |
19 |
Correct |
795 ms |
138684 KB |
Output is correct |
20 |
Correct |
805 ms |
138796 KB |
Output is correct |
21 |
Correct |
931 ms |
139552 KB |
Output is correct |
22 |
Correct |
853 ms |
138952 KB |
Output is correct |
23 |
Correct |
949 ms |
142852 KB |
Output is correct |
24 |
Correct |
671 ms |
139816 KB |
Output is correct |
25 |
Correct |
608 ms |
138148 KB |
Output is correct |
26 |
Correct |
630 ms |
138068 KB |
Output is correct |
27 |
Correct |
700 ms |
137912 KB |
Output is correct |
28 |
Correct |
1164 ms |
144532 KB |
Output is correct |
29 |
Correct |
1140 ms |
144572 KB |
Output is correct |
30 |
Correct |
1141 ms |
144612 KB |
Output is correct |
31 |
Correct |
1134 ms |
144504 KB |
Output is correct |
32 |
Correct |
866 ms |
138952 KB |
Output is correct |
33 |
Correct |
1111 ms |
141356 KB |
Output is correct |
34 |
Correct |
454 ms |
57744 KB |
Output is correct |
35 |
Correct |
1184 ms |
144832 KB |
Output is correct |
36 |
Correct |
1058 ms |
140832 KB |
Output is correct |
37 |
Correct |
1151 ms |
143724 KB |
Output is correct |
38 |
Correct |
1124 ms |
141572 KB |
Output is correct |
39 |
Correct |
1061 ms |
149312 KB |
Output is correct |
40 |
Correct |
1078 ms |
149108 KB |
Output is correct |
41 |
Correct |
870 ms |
141504 KB |
Output is correct |
42 |
Correct |
747 ms |
138788 KB |
Output is correct |
43 |
Correct |
1117 ms |
148280 KB |
Output is correct |
44 |
Correct |
1048 ms |
142516 KB |
Output is correct |
45 |
Correct |
785 ms |
147744 KB |
Output is correct |
46 |
Correct |
816 ms |
147264 KB |
Output is correct |
47 |
Correct |
1155 ms |
144800 KB |
Output is correct |
48 |
Correct |
1141 ms |
144676 KB |
Output is correct |
49 |
Correct |
1146 ms |
144964 KB |
Output is correct |
50 |
Correct |
1157 ms |
144548 KB |
Output is correct |
51 |
Correct |
1016 ms |
148372 KB |
Output is correct |
52 |
Correct |
958 ms |
148436 KB |
Output is correct |