#include "werewolf.h"
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
#define VI vector<int>
#define nyan "(=^・ω・^=)"
#define read_input freopen("in.txt","r", stdin)
#define print_output freopen("out.txt","w", stdout)
typedef long long ll;
typedef long double ld;
using namespace std;
const int maxn = 4e5+10;
int N, M, Q; int tym;
VI adj[2][maxn], sml[maxn], big[maxn];
int parent[2][20][maxn], tour[2][maxn];
int st[2][maxn], ed[2][maxn];
struct disjointSetUnion {
int par[maxn];
void init() { for(int i = 0; i <= N; i++) par[i] = i; }
int find(int x) { return (par[x] == x)? x : par[x] = find(par[x]); }
void join(int a, int b) { par[find(b)] = find(a); }
} dsu;
struct HolyShit {
int ans[maxn];
struct binarytree {
int a[maxn];
int add(int x, int val) {
while(x < maxn) {
a[x] += val;
x += x & -x;
}
}
int sum(int x) {
int ret = 0;
while(x) {
ret += a[x];
x -= x & -x;
} return ret;
}
int range(int l, int r) { return sum(r) - sum(l-1); }
} bit;
struct event {
int x, y1, y2, typ, idx;
event(int _x=0, int _y1 = 0, int _y2=0, int _t=-1, int _i=-1) :
x(_x), y1(_y1), y2(_y2), typ(_t), idx(_i) {}
bool operator<(const event &rhs) {
if(x == rhs.x) return typ < rhs.typ;
return x < rhs.x;
}
}; vector<event> events;
void insert(int x, int y) { x++; y++; events.pb(event(x, y, -1, 1, -1)); }
void query(int x1, int y1, int x2, int y2, int id) {
x1++; y1++; x2++; y2++;
events.pb(event(x1, y1, y2, 0, id));
events.pb(event(x2, y1, y2, 2, id));
}
void process() {
sort(events.begin(), events.end());
//for(auto e : events) {
// cout << e.x << " [" << e.y1 << ", " << e.y2 << "] (" << e.typ << ") " << e.idx <<endl;
//}
for(auto e : events) {
if(e.typ == 0) ans[e.idx] -= bit.range(e.y1, e.y2);
else if(e.typ == 1) bit.add(e.y1, 1);
else ans[e.idx] += bit.range(e.y1, e.y2);
}
}
} ds;
void dfs(int u, int id) {
tour[id][tym] = u;
st[id][u] = tym++;
for(auto v : adj[id][u])
dfs(v, id);
ed[id][u] = tym-1;
}
VI check_validity(int n, VI X, VI Y, VI S, VI E, VI L, VI R) { // 0 = small, 1 = big;
N = n;
M = X.size();
Q = S.size(); VI A(Q, 0);
for(int i = 0; i < M; i++) {
if(X[i] > Y[i]) swap(X[i], Y[i]);
sml[X[i]].pb(Y[i]);
big[Y[i]].pb(X[i]);
}
dsu.init(); memset(parent, -1, sizeof parent);
for(int u = 0; u < n; u++) {
for(auto it : big[u]) {
int v = dsu.find(it);
if(v == u) continue;
adj[1][u].pb(v);
parent[1][0][v] = u;
dsu.join(u, v);
}
}
dsu.init();
for(int u = n-1; u >= 0; u--) {
for(auto it : sml[u]) {
int v = dsu.find(it);
if(v == u) continue;
adj[0][u].pb(v);
parent[0][0][v] = u;
dsu.join(u, v);
}
}
tym = 0; dfs(0, 0);
tym = 0; dfs(n-1, 1);
for(int i = 1; 1 << i < n; i++) {
for(int j = 0; j < n; j++) {
if(parent[0][i-1][j] != -1) parent[0][i][j] = parent[0][i-1][parent[0][i-1][j]];
if(parent[1][i-1][j] != -1) parent[1][i][j] = parent[1][i-1][parent[1][i-1][j]];
}
}
int aux[maxn];
for(int i = 0; i < n; i++) aux[tour[1][i]] = i;
for(int i = 0; i < n; i++) ds.insert(i, aux[tour[0][i]]);
for(int i = 0; i < Q; i++) {
int u = S[i], v = E[i];
for(int j = 18; j >= 0; j--)
if(parent[0][j][u] != -1 && parent[0][j][u] >= L[i]) u = parent[0][j][u];
for(int j = 18; j >= 0; j--)
if(parent[1][j][v] != -1 && parent[1][j][v] <= R[i]) v = parent[1][j][v];
ds.query(st[0][u], st[1][v], ed[0][u], ed[1][v], i);
//cout << st[0][u] << " " << ed[0][u] << "\t\t" << st[1][v] << " " << ed[1][v] << endl;
} ds.process();
for(int i = 0; i < Q; i++) A[i] = ds.ans[i] > 0;
return A;
}
Compilation message
werewolf.cpp: In member function 'int HolyShit::binarytree::add(int, int)':
werewolf.cpp:37:3: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
100728 KB |
Output is correct |
2 |
Correct |
88 ms |
100612 KB |
Output is correct |
3 |
Correct |
87 ms |
100592 KB |
Output is correct |
4 |
Correct |
88 ms |
100600 KB |
Output is correct |
5 |
Correct |
88 ms |
100600 KB |
Output is correct |
6 |
Correct |
87 ms |
100600 KB |
Output is correct |
7 |
Correct |
89 ms |
100728 KB |
Output is correct |
8 |
Correct |
87 ms |
100720 KB |
Output is correct |
9 |
Correct |
88 ms |
100600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
100728 KB |
Output is correct |
2 |
Correct |
88 ms |
100612 KB |
Output is correct |
3 |
Correct |
87 ms |
100592 KB |
Output is correct |
4 |
Correct |
88 ms |
100600 KB |
Output is correct |
5 |
Correct |
88 ms |
100600 KB |
Output is correct |
6 |
Correct |
87 ms |
100600 KB |
Output is correct |
7 |
Correct |
89 ms |
100728 KB |
Output is correct |
8 |
Correct |
87 ms |
100720 KB |
Output is correct |
9 |
Correct |
88 ms |
100600 KB |
Output is correct |
10 |
Correct |
95 ms |
101692 KB |
Output is correct |
11 |
Correct |
94 ms |
101720 KB |
Output is correct |
12 |
Correct |
93 ms |
101620 KB |
Output is correct |
13 |
Correct |
94 ms |
101976 KB |
Output is correct |
14 |
Correct |
93 ms |
101848 KB |
Output is correct |
15 |
Correct |
95 ms |
101924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
795 ms |
162900 KB |
Output is correct |
2 |
Correct |
900 ms |
166352 KB |
Output is correct |
3 |
Correct |
821 ms |
163928 KB |
Output is correct |
4 |
Correct |
824 ms |
163200 KB |
Output is correct |
5 |
Correct |
802 ms |
163024 KB |
Output is correct |
6 |
Correct |
797 ms |
162964 KB |
Output is correct |
7 |
Correct |
731 ms |
162896 KB |
Output is correct |
8 |
Correct |
829 ms |
166636 KB |
Output is correct |
9 |
Correct |
701 ms |
163976 KB |
Output is correct |
10 |
Correct |
632 ms |
163280 KB |
Output is correct |
11 |
Correct |
651 ms |
163024 KB |
Output is correct |
12 |
Correct |
658 ms |
162896 KB |
Output is correct |
13 |
Correct |
916 ms |
176204 KB |
Output is correct |
14 |
Correct |
932 ms |
176064 KB |
Output is correct |
15 |
Correct |
896 ms |
175828 KB |
Output is correct |
16 |
Correct |
972 ms |
175760 KB |
Output is correct |
17 |
Correct |
783 ms |
162896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
100728 KB |
Output is correct |
2 |
Correct |
88 ms |
100612 KB |
Output is correct |
3 |
Correct |
87 ms |
100592 KB |
Output is correct |
4 |
Correct |
88 ms |
100600 KB |
Output is correct |
5 |
Correct |
88 ms |
100600 KB |
Output is correct |
6 |
Correct |
87 ms |
100600 KB |
Output is correct |
7 |
Correct |
89 ms |
100728 KB |
Output is correct |
8 |
Correct |
87 ms |
100720 KB |
Output is correct |
9 |
Correct |
88 ms |
100600 KB |
Output is correct |
10 |
Correct |
95 ms |
101692 KB |
Output is correct |
11 |
Correct |
94 ms |
101720 KB |
Output is correct |
12 |
Correct |
93 ms |
101620 KB |
Output is correct |
13 |
Correct |
94 ms |
101976 KB |
Output is correct |
14 |
Correct |
93 ms |
101848 KB |
Output is correct |
15 |
Correct |
95 ms |
101924 KB |
Output is correct |
16 |
Correct |
795 ms |
162900 KB |
Output is correct |
17 |
Correct |
900 ms |
166352 KB |
Output is correct |
18 |
Correct |
821 ms |
163928 KB |
Output is correct |
19 |
Correct |
824 ms |
163200 KB |
Output is correct |
20 |
Correct |
802 ms |
163024 KB |
Output is correct |
21 |
Correct |
797 ms |
162964 KB |
Output is correct |
22 |
Correct |
731 ms |
162896 KB |
Output is correct |
23 |
Correct |
829 ms |
166636 KB |
Output is correct |
24 |
Correct |
701 ms |
163976 KB |
Output is correct |
25 |
Correct |
632 ms |
163280 KB |
Output is correct |
26 |
Correct |
651 ms |
163024 KB |
Output is correct |
27 |
Correct |
658 ms |
162896 KB |
Output is correct |
28 |
Correct |
916 ms |
176204 KB |
Output is correct |
29 |
Correct |
932 ms |
176064 KB |
Output is correct |
30 |
Correct |
896 ms |
175828 KB |
Output is correct |
31 |
Correct |
972 ms |
175760 KB |
Output is correct |
32 |
Correct |
783 ms |
162896 KB |
Output is correct |
33 |
Correct |
881 ms |
162520 KB |
Output is correct |
34 |
Correct |
484 ms |
140644 KB |
Output is correct |
35 |
Correct |
964 ms |
165584 KB |
Output is correct |
36 |
Correct |
841 ms |
163352 KB |
Output is correct |
37 |
Correct |
910 ms |
164508 KB |
Output is correct |
38 |
Correct |
880 ms |
164176 KB |
Output is correct |
39 |
Correct |
952 ms |
174720 KB |
Output is correct |
40 |
Correct |
1038 ms |
174532 KB |
Output is correct |
41 |
Correct |
793 ms |
163940 KB |
Output is correct |
42 |
Correct |
672 ms |
163744 KB |
Output is correct |
43 |
Correct |
1069 ms |
172184 KB |
Output is correct |
44 |
Correct |
855 ms |
164524 KB |
Output is correct |
45 |
Correct |
792 ms |
175020 KB |
Output is correct |
46 |
Correct |
819 ms |
174504 KB |
Output is correct |
47 |
Correct |
967 ms |
175904 KB |
Output is correct |
48 |
Correct |
953 ms |
175836 KB |
Output is correct |
49 |
Correct |
947 ms |
176080 KB |
Output is correct |
50 |
Correct |
945 ms |
175768 KB |
Output is correct |
51 |
Correct |
957 ms |
173688 KB |
Output is correct |
52 |
Correct |
964 ms |
173972 KB |
Output is correct |