#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(labs(x) >= mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl
const int MAX_N = 2e5 + 10;
struct DSU {
int par[MAX_N], sz[MAX_N], big[MAX_N];
int find(int x) {
if(x == par[x]) {
return x;
} else {
return par[x] = find(par[x]);
}
}
bool merge(int x, int y) {
x = find(x); y = find(y);
if(x == y) {return false;}
if(sz[x] < sz[y]) {swap(x, y);}
par[y] = x;
sz[x] += sz[y];
return true;
}
void reset() {
for(int i = 0; i < MAX_N; i ++) {
par[i] = big[i] = i;
sz[i] = 1;
}
}
};
struct Tree {
vector<int> g[MAX_N];
int in[MAX_N], out[MAX_N], tme;
void addEdge(int a, int b) {
g[a].push_back(b);
g[b].push_back(a);
}
void dfs(int x, int p) {
in[x] = ++ tme;
for(auto it : g[x]) {
if(it == p) {continue;}
dfs(it, x);
}
out[x] = tme;
}
void calculate(int x) {
tme = -1;
dfs(x, -1);
}
};
struct Query {
int v, ind;
};
Tree tPref, tSuf;
DSU dsuPref, dsuSuf;
vector<Query> query[MAX_N];
set<int> pos[MAX_N];
int ans[MAX_N];
vector<pair<pair<int, int>, int> > compPref[MAX_N], compSuf[MAX_N];
void dfs(int x, int p) {
pos[x].insert(tSuf.in[x]);
for(auto it : tPref.g[x]) {
if(it == p) {continue;}
dfs(it, x);
if(pos[it] < pos[x]) {swap(pos[x], pos[it]);}
for(auto itt : pos[it]) {
pos[x].insert(itt);
}
}
for(auto it : query[x]) {
auto found = pos[x].lower_bound(tSuf.in[it.v]);
if(found == pos[x].end() || (*found) > tSuf.out[it.v]) {
ans[it.ind] = 0;
} else {
ans[it.ind] = 1;
}
}
}
vector<int> g[MAX_N];
int werewolf[MAX_N];
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) {
vector<int> ret;
int n = N, m = X.size(), q = S.size();
for(int i = 0; i < m; i ++) {
int a = X[i], b = Y[i];
g[a].push_back(b);
g[b].push_back(a);
}
for(int i = 0; i < q; i ++) {
int s = S[i], e = E[i], l = L[i], r = R[i];
compPref[r].push_back({{s, e}, i});
compSuf[l].push_back({{s, e}, i});
}
dsuPref.reset();
dsuSuf.reset();
for(int i = n - 1; i >= 0; i --) {
for(auto it : g[i]) {
if(it > i) {
int prv = dsuSuf.big[dsuSuf.find(it)];
if(dsuSuf.merge(it, i)) {
tSuf.addEdge(i, prv);
dsuSuf.big[dsuSuf.find(i)] = i;
}
}
}
for(auto it : compSuf[i]) {
werewolf[it.second] = dsuSuf.big[dsuSuf.find(it.first.first)];
}
}
for(int i = 0; i < n; i ++) {
for(auto it : g[i]) {
if(it < i) {
int prv = dsuPref.big[dsuPref.find(it)];
if(dsuPref.merge(it, i)) {
tPref.addEdge(i, prv);
dsuPref.big[dsuPref.find(i)] = i;
}
}
}
for(auto it : compPref[i]) {
query[dsuPref.big[dsuPref.find(it.first.second)]].push_back({werewolf[it.second], it.second});
}
}
tPref.calculate(dsuPref.big[dsuPref.find(1)]);
tSuf.calculate(dsuSuf.big[dsuSuf.find(1)]);
dfs(dsuPref.big[dsuPref.find(1)], -1);
for(int i = 0; i < q; i ++) {
ret.push_back(ans[i]);
}
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
42624 KB |
Output is correct |
2 |
Correct |
30 ms |
42624 KB |
Output is correct |
3 |
Correct |
29 ms |
42624 KB |
Output is correct |
4 |
Correct |
29 ms |
42624 KB |
Output is correct |
5 |
Correct |
29 ms |
42624 KB |
Output is correct |
6 |
Correct |
29 ms |
42624 KB |
Output is correct |
7 |
Correct |
29 ms |
42616 KB |
Output is correct |
8 |
Correct |
29 ms |
42624 KB |
Output is correct |
9 |
Correct |
29 ms |
42624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
42624 KB |
Output is correct |
2 |
Correct |
30 ms |
42624 KB |
Output is correct |
3 |
Correct |
29 ms |
42624 KB |
Output is correct |
4 |
Correct |
29 ms |
42624 KB |
Output is correct |
5 |
Correct |
29 ms |
42624 KB |
Output is correct |
6 |
Correct |
29 ms |
42624 KB |
Output is correct |
7 |
Correct |
29 ms |
42616 KB |
Output is correct |
8 |
Correct |
29 ms |
42624 KB |
Output is correct |
9 |
Correct |
29 ms |
42624 KB |
Output is correct |
10 |
Correct |
37 ms |
43904 KB |
Output is correct |
11 |
Correct |
38 ms |
44160 KB |
Output is correct |
12 |
Correct |
39 ms |
44152 KB |
Output is correct |
13 |
Correct |
37 ms |
44032 KB |
Output is correct |
14 |
Correct |
36 ms |
44024 KB |
Output is correct |
15 |
Correct |
39 ms |
44152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1197 ms |
170856 KB |
Output is correct |
2 |
Correct |
758 ms |
122168 KB |
Output is correct |
3 |
Correct |
797 ms |
121712 KB |
Output is correct |
4 |
Correct |
857 ms |
130036 KB |
Output is correct |
5 |
Correct |
897 ms |
131572 KB |
Output is correct |
6 |
Correct |
1040 ms |
142200 KB |
Output is correct |
7 |
Correct |
1160 ms |
169540 KB |
Output is correct |
8 |
Correct |
753 ms |
122228 KB |
Output is correct |
9 |
Correct |
723 ms |
120936 KB |
Output is correct |
10 |
Correct |
772 ms |
128116 KB |
Output is correct |
11 |
Correct |
818 ms |
131192 KB |
Output is correct |
12 |
Correct |
982 ms |
140144 KB |
Output is correct |
13 |
Correct |
752 ms |
126196 KB |
Output is correct |
14 |
Correct |
749 ms |
126196 KB |
Output is correct |
15 |
Correct |
745 ms |
126584 KB |
Output is correct |
16 |
Correct |
747 ms |
126320 KB |
Output is correct |
17 |
Correct |
1188 ms |
172460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
42624 KB |
Output is correct |
2 |
Correct |
30 ms |
42624 KB |
Output is correct |
3 |
Correct |
29 ms |
42624 KB |
Output is correct |
4 |
Correct |
29 ms |
42624 KB |
Output is correct |
5 |
Correct |
29 ms |
42624 KB |
Output is correct |
6 |
Correct |
29 ms |
42624 KB |
Output is correct |
7 |
Correct |
29 ms |
42616 KB |
Output is correct |
8 |
Correct |
29 ms |
42624 KB |
Output is correct |
9 |
Correct |
29 ms |
42624 KB |
Output is correct |
10 |
Correct |
37 ms |
43904 KB |
Output is correct |
11 |
Correct |
38 ms |
44160 KB |
Output is correct |
12 |
Correct |
39 ms |
44152 KB |
Output is correct |
13 |
Correct |
37 ms |
44032 KB |
Output is correct |
14 |
Correct |
36 ms |
44024 KB |
Output is correct |
15 |
Correct |
39 ms |
44152 KB |
Output is correct |
16 |
Correct |
1197 ms |
170856 KB |
Output is correct |
17 |
Correct |
758 ms |
122168 KB |
Output is correct |
18 |
Correct |
797 ms |
121712 KB |
Output is correct |
19 |
Correct |
857 ms |
130036 KB |
Output is correct |
20 |
Correct |
897 ms |
131572 KB |
Output is correct |
21 |
Correct |
1040 ms |
142200 KB |
Output is correct |
22 |
Correct |
1160 ms |
169540 KB |
Output is correct |
23 |
Correct |
753 ms |
122228 KB |
Output is correct |
24 |
Correct |
723 ms |
120936 KB |
Output is correct |
25 |
Correct |
772 ms |
128116 KB |
Output is correct |
26 |
Correct |
818 ms |
131192 KB |
Output is correct |
27 |
Correct |
982 ms |
140144 KB |
Output is correct |
28 |
Correct |
752 ms |
126196 KB |
Output is correct |
29 |
Correct |
749 ms |
126196 KB |
Output is correct |
30 |
Correct |
745 ms |
126584 KB |
Output is correct |
31 |
Correct |
747 ms |
126320 KB |
Output is correct |
32 |
Correct |
1188 ms |
172460 KB |
Output is correct |
33 |
Correct |
1109 ms |
144952 KB |
Output is correct |
34 |
Correct |
389 ms |
72944 KB |
Output is correct |
35 |
Correct |
1104 ms |
138828 KB |
Output is correct |
36 |
Correct |
1108 ms |
140008 KB |
Output is correct |
37 |
Correct |
1059 ms |
135028 KB |
Output is correct |
38 |
Correct |
1100 ms |
132728 KB |
Output is correct |
39 |
Correct |
952 ms |
136180 KB |
Output is correct |
40 |
Correct |
1002 ms |
136192 KB |
Output is correct |
41 |
Correct |
1041 ms |
125932 KB |
Output is correct |
42 |
Correct |
1076 ms |
148588 KB |
Output is correct |
43 |
Correct |
1075 ms |
133744 KB |
Output is correct |
44 |
Correct |
1060 ms |
133104 KB |
Output is correct |
45 |
Correct |
817 ms |
136048 KB |
Output is correct |
46 |
Correct |
823 ms |
136048 KB |
Output is correct |
47 |
Correct |
749 ms |
126320 KB |
Output is correct |
48 |
Correct |
746 ms |
126196 KB |
Output is correct |
49 |
Correct |
752 ms |
126196 KB |
Output is correct |
50 |
Correct |
738 ms |
126196 KB |
Output is correct |
51 |
Correct |
969 ms |
132816 KB |
Output is correct |
52 |
Correct |
984 ms |
133492 KB |
Output is correct |