#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define all(x) (x).begin(), (x).end()
#define SZ(x) int((x).size())
#define X first
#define Y second
#define sep ' '
const int LOG = 22;
const int MAXN = 5e5 + 10;
int n , m , q , curInd , Root[2] , Par[MAXN] , sz[MAXN] , root[MAXN] , value[2][MAXN] , par[2][LOG][MAXN];
int timer , st[MAXN] , fn[MAXN];
vector<pair<int, pii>> Edge[2];
vector<int> adj[2][MAXN] , ans;
vector<pii> Q[MAXN];
set<int> ST[MAXN];
int Find(int v){
return (Par[v] == -1 ? v : Par[v] = Find(Par[v]));
}
void Union(int ind , int v , int u , int w){
v = Find(v); u = Find(u);
if(u == v) return;
if(sz[v] < sz[u]) swap(v , u);
Par[u] = v;
sz[v] += sz[u];
//cout << curInd << sep << root[v] << sep << root[u] << sep << w << endl;
par[ind][0][root[v]] = par[ind][0][root[u]] = curInd;
adj[ind][curInd].push_back(root[v]);
adj[ind][curInd].push_back(root[u]);
value[ind][curInd] = w;
root[v] = curInd++;
}
void PreDFS(int v){
st[v] = timer++;
for(int u : adj[0][v]){
PreDFS(u);
}
fn[v] = timer;
}
void SolveDFS(int v){
if(v < n){
ST[v].insert(st[v]);
}
for(int u : adj[1][v]){
SolveDFS(u);
if(SZ(ST[u]) > SZ(ST[v])){
ST[v].swap(ST[u]);
}
for(int j : ST[u]){
ST[v].insert(j);
}
}
for(pii i : Q[v]){
int u = i.X , ind = i.Y;
auto it = ST[v].lower_bound(st[u]);
if(it != ST[v].end() && (*it) < fn[u]){
ans[ind] = 1;
}
}
}
vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E,
vector<int> L, vector<int> R) {
n = N; m = SZ(X); q = SZ(S);
for(int i = 0 ; i < m ; i++){
int v = X[i] , u = Y[i];
Edge[0].push_back({max(v , u) , {v , u}});
Edge[1].push_back({min(v , u) , {v , u}});
}
sort(all(Edge[0]));
sort(all(Edge[1]) , greater<pair<int , pii>>());
for(int i = 0 ; i < 2 ; i++){
curInd = n;
for(int j = 0 ; j < MAXN ; j++){
Par[j] = -1;
sz[j] = 1;
root[j] = j;
}
for(auto &j : Edge[i]){
Union(i , j.Y.X , j.Y.Y , j.X);
}
par[i][0][curInd - 1] = curInd - 1;
for(int j = 1 ; j < LOG ; j++){
for(int k = 0 ; k < curInd ; k++){
par[i][j][k] = par[i][j - 1][par[i][j - 1][k]];
}
}
Root[i] = curInd - 1;
}
ans = vector<int>(q , 0);
for(int i = 0 ; i < q ; i++){
int v = S[i] , u = E[i] , l = L[i] , r = R[i];
for(int j = LOG - 1 ; j >= 0 ; j--){
if(value[0][par[0][j][u]] <= r){
u = par[0][j][u];
}
if(value[1][par[1][j][v]] >= l){
v = par[1][j][v];
}
}
Q[v].push_back({u , i});
}
PreDFS(Root[0]);
SolveDFS(Root[1]);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
65352 KB |
Output is correct |
2 |
Correct |
29 ms |
65296 KB |
Output is correct |
3 |
Correct |
30 ms |
65208 KB |
Output is correct |
4 |
Correct |
33 ms |
65260 KB |
Output is correct |
5 |
Correct |
37 ms |
65208 KB |
Output is correct |
6 |
Correct |
35 ms |
65264 KB |
Output is correct |
7 |
Correct |
34 ms |
65224 KB |
Output is correct |
8 |
Correct |
30 ms |
65276 KB |
Output is correct |
9 |
Correct |
31 ms |
65332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
65352 KB |
Output is correct |
2 |
Correct |
29 ms |
65296 KB |
Output is correct |
3 |
Correct |
30 ms |
65208 KB |
Output is correct |
4 |
Correct |
33 ms |
65260 KB |
Output is correct |
5 |
Correct |
37 ms |
65208 KB |
Output is correct |
6 |
Correct |
35 ms |
65264 KB |
Output is correct |
7 |
Correct |
34 ms |
65224 KB |
Output is correct |
8 |
Correct |
30 ms |
65276 KB |
Output is correct |
9 |
Correct |
31 ms |
65332 KB |
Output is correct |
10 |
Correct |
38 ms |
67496 KB |
Output is correct |
11 |
Correct |
39 ms |
67408 KB |
Output is correct |
12 |
Correct |
39 ms |
67588 KB |
Output is correct |
13 |
Correct |
38 ms |
67404 KB |
Output is correct |
14 |
Correct |
41 ms |
67620 KB |
Output is correct |
15 |
Correct |
40 ms |
67532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1190 ms |
235784 KB |
Output is correct |
2 |
Correct |
928 ms |
211972 KB |
Output is correct |
3 |
Correct |
881 ms |
220348 KB |
Output is correct |
4 |
Correct |
956 ms |
234636 KB |
Output is correct |
5 |
Correct |
999 ms |
237772 KB |
Output is correct |
6 |
Correct |
1161 ms |
243176 KB |
Output is correct |
7 |
Correct |
1119 ms |
245792 KB |
Output is correct |
8 |
Correct |
732 ms |
212040 KB |
Output is correct |
9 |
Correct |
554 ms |
219700 KB |
Output is correct |
10 |
Correct |
574 ms |
234272 KB |
Output is correct |
11 |
Correct |
617 ms |
235704 KB |
Output is correct |
12 |
Correct |
690 ms |
241820 KB |
Output is correct |
13 |
Correct |
952 ms |
214792 KB |
Output is correct |
14 |
Correct |
960 ms |
214748 KB |
Output is correct |
15 |
Correct |
936 ms |
214836 KB |
Output is correct |
16 |
Correct |
962 ms |
214840 KB |
Output is correct |
17 |
Correct |
1111 ms |
244008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
65352 KB |
Output is correct |
2 |
Correct |
29 ms |
65296 KB |
Output is correct |
3 |
Correct |
30 ms |
65208 KB |
Output is correct |
4 |
Correct |
33 ms |
65260 KB |
Output is correct |
5 |
Correct |
37 ms |
65208 KB |
Output is correct |
6 |
Correct |
35 ms |
65264 KB |
Output is correct |
7 |
Correct |
34 ms |
65224 KB |
Output is correct |
8 |
Correct |
30 ms |
65276 KB |
Output is correct |
9 |
Correct |
31 ms |
65332 KB |
Output is correct |
10 |
Correct |
38 ms |
67496 KB |
Output is correct |
11 |
Correct |
39 ms |
67408 KB |
Output is correct |
12 |
Correct |
39 ms |
67588 KB |
Output is correct |
13 |
Correct |
38 ms |
67404 KB |
Output is correct |
14 |
Correct |
41 ms |
67620 KB |
Output is correct |
15 |
Correct |
40 ms |
67532 KB |
Output is correct |
16 |
Correct |
1190 ms |
235784 KB |
Output is correct |
17 |
Correct |
928 ms |
211972 KB |
Output is correct |
18 |
Correct |
881 ms |
220348 KB |
Output is correct |
19 |
Correct |
956 ms |
234636 KB |
Output is correct |
20 |
Correct |
999 ms |
237772 KB |
Output is correct |
21 |
Correct |
1161 ms |
243176 KB |
Output is correct |
22 |
Correct |
1119 ms |
245792 KB |
Output is correct |
23 |
Correct |
732 ms |
212040 KB |
Output is correct |
24 |
Correct |
554 ms |
219700 KB |
Output is correct |
25 |
Correct |
574 ms |
234272 KB |
Output is correct |
26 |
Correct |
617 ms |
235704 KB |
Output is correct |
27 |
Correct |
690 ms |
241820 KB |
Output is correct |
28 |
Correct |
952 ms |
214792 KB |
Output is correct |
29 |
Correct |
960 ms |
214748 KB |
Output is correct |
30 |
Correct |
936 ms |
214836 KB |
Output is correct |
31 |
Correct |
962 ms |
214840 KB |
Output is correct |
32 |
Correct |
1111 ms |
244008 KB |
Output is correct |
33 |
Correct |
1197 ms |
217792 KB |
Output is correct |
34 |
Correct |
370 ms |
103532 KB |
Output is correct |
35 |
Correct |
1217 ms |
216920 KB |
Output is correct |
36 |
Correct |
1223 ms |
218692 KB |
Output is correct |
37 |
Correct |
1318 ms |
215864 KB |
Output is correct |
38 |
Correct |
1302 ms |
217744 KB |
Output is correct |
39 |
Correct |
1265 ms |
228288 KB |
Output is correct |
40 |
Correct |
995 ms |
223812 KB |
Output is correct |
41 |
Correct |
820 ms |
214204 KB |
Output is correct |
42 |
Correct |
651 ms |
217452 KB |
Output is correct |
43 |
Correct |
995 ms |
222620 KB |
Output is correct |
44 |
Correct |
929 ms |
215080 KB |
Output is correct |
45 |
Correct |
753 ms |
218296 KB |
Output is correct |
46 |
Correct |
878 ms |
228028 KB |
Output is correct |
47 |
Correct |
1000 ms |
215024 KB |
Output is correct |
48 |
Correct |
978 ms |
214888 KB |
Output is correct |
49 |
Correct |
1020 ms |
215116 KB |
Output is correct |
50 |
Correct |
983 ms |
214784 KB |
Output is correct |
51 |
Correct |
849 ms |
223792 KB |
Output is correct |
52 |
Correct |
871 ms |
223600 KB |
Output is correct |