#include "werewolf.h"
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
using namespace std;
typedef vector<int> vi;
const int N=(1<<18);
int r[N];
vector<int> edg[N];
vector<int> E[N], E2[N];
int find(int v){
if(r[v]==v)return v;
return r[v]=find(r[v]);
}
int wsk2=0;
int pre[N], post[N];
void dfs(int v){
pre[v]=wsk2++;
for(int u:E[v]){
dfs(u);
}
post[v]=wsk2;
}
int tab[N+N];
void add(int i){
for(i+=N; i>0; i>>=1){
tab[i]++;
}
}
int sum(int l, int r){
int ans=0;
for(l+=N, r+=N; l<r; l>>=1, r>>=1){
if(l&1)ans+=tab[l++];
if(r&1)ans+=tab[--r];
}
return ans;
}
vector<int> A;
vector<pair<int, int> > quer[N];
void dfs2(int v){
for(auto i:quer[v]){
A[i.nd]=-sum(pre[i.st], post[i.st]);
}
add(pre[v]);
for(int u:E2[v])dfs2(u);
for(auto i:quer[v]){
A[i.nd]+=sum(pre[i.st], post[i.st]);
}
}
std::vector<int> check_validity(int n, vi X, vi Y,
vi S, vi T,
vi L, vi R) {
iota(r, r+N, 0);
int m=X.size(), q = S.size();
for(int i=0; i<m; i++){
edg[X[i]].pb(Y[i]);
edg[Y[i]].pb(X[i]);
}
vector<pair<int, int> > Q;
for(int i=0; i<q; i++){
Q.push_back({R[i], i});
}
sort(Q.begin(), Q.end());
int wsk=0;
for(int i=0; i<n; i++){
for(int j:edg[i]){
if(j<i){
int v=find(j);
if(i!=v){
r[v]=i;
E[i].push_back(v);
}
}
}
while(wsk<q && Q[wsk].st==i){
//cout<<i<<" "<<T[Q[wsk].nd]<<" "<<find(T[Q[wsk].nd])<<"\n";
T[Q[wsk].nd]=find(T[Q[wsk].nd]);
wsk++;
}
}
//cout<<wsk<<"\n";
iota(r, r+N, 0);
wsk=0;
Q.clear();
for(int i=0; i<q; i++){
Q.push_back({L[i], i});
}
sort(Q.begin(), Q.end());
reverse(Q.begin(), Q.end());
for(int i=n-1; i>=0; i--){
for(int j:edg[i]){
if(j>i){
int v=find(j);
if(i!=v){
r[v]=i;
E2[i].push_back(v);
}
}
}
while(wsk<q && Q[wsk].st==i){
S[Q[wsk].nd]=find(S[Q[wsk].nd]);
wsk++;
}
}
//cout<<wsk<<"a\n";
A.resize(q);
dfs(n-1);
for(int i=0; i<q; i++){
quer[S[i]].push_back({T[i], i});
}
dfs2(0);
for(int i=0; i<q; i++)A[i]=!!A[i];
return A;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
26012 KB |
Output is correct |
2 |
Correct |
15 ms |
25908 KB |
Output is correct |
3 |
Correct |
17 ms |
26060 KB |
Output is correct |
4 |
Correct |
17 ms |
25932 KB |
Output is correct |
5 |
Correct |
15 ms |
25952 KB |
Output is correct |
6 |
Correct |
15 ms |
25932 KB |
Output is correct |
7 |
Correct |
14 ms |
26020 KB |
Output is correct |
8 |
Correct |
15 ms |
25956 KB |
Output is correct |
9 |
Correct |
15 ms |
25916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
26012 KB |
Output is correct |
2 |
Correct |
15 ms |
25908 KB |
Output is correct |
3 |
Correct |
17 ms |
26060 KB |
Output is correct |
4 |
Correct |
17 ms |
25932 KB |
Output is correct |
5 |
Correct |
15 ms |
25952 KB |
Output is correct |
6 |
Correct |
15 ms |
25932 KB |
Output is correct |
7 |
Correct |
14 ms |
26020 KB |
Output is correct |
8 |
Correct |
15 ms |
25956 KB |
Output is correct |
9 |
Correct |
15 ms |
25916 KB |
Output is correct |
10 |
Correct |
20 ms |
26604 KB |
Output is correct |
11 |
Correct |
20 ms |
26608 KB |
Output is correct |
12 |
Correct |
19 ms |
26620 KB |
Output is correct |
13 |
Correct |
21 ms |
26728 KB |
Output is correct |
14 |
Correct |
20 ms |
26604 KB |
Output is correct |
15 |
Correct |
21 ms |
26700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
530 ms |
59820 KB |
Output is correct |
2 |
Correct |
500 ms |
69020 KB |
Output is correct |
3 |
Correct |
506 ms |
67748 KB |
Output is correct |
4 |
Correct |
507 ms |
67052 KB |
Output is correct |
5 |
Correct |
487 ms |
67252 KB |
Output is correct |
6 |
Correct |
526 ms |
67856 KB |
Output is correct |
7 |
Correct |
535 ms |
67244 KB |
Output is correct |
8 |
Correct |
545 ms |
68980 KB |
Output is correct |
9 |
Correct |
459 ms |
67504 KB |
Output is correct |
10 |
Correct |
446 ms |
66772 KB |
Output is correct |
11 |
Correct |
459 ms |
66808 KB |
Output is correct |
12 |
Correct |
505 ms |
66716 KB |
Output is correct |
13 |
Correct |
541 ms |
78552 KB |
Output is correct |
14 |
Correct |
620 ms |
78624 KB |
Output is correct |
15 |
Correct |
538 ms |
78772 KB |
Output is correct |
16 |
Correct |
568 ms |
78656 KB |
Output is correct |
17 |
Correct |
506 ms |
67368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
26012 KB |
Output is correct |
2 |
Correct |
15 ms |
25908 KB |
Output is correct |
3 |
Correct |
17 ms |
26060 KB |
Output is correct |
4 |
Correct |
17 ms |
25932 KB |
Output is correct |
5 |
Correct |
15 ms |
25952 KB |
Output is correct |
6 |
Correct |
15 ms |
25932 KB |
Output is correct |
7 |
Correct |
14 ms |
26020 KB |
Output is correct |
8 |
Correct |
15 ms |
25956 KB |
Output is correct |
9 |
Correct |
15 ms |
25916 KB |
Output is correct |
10 |
Correct |
20 ms |
26604 KB |
Output is correct |
11 |
Correct |
20 ms |
26608 KB |
Output is correct |
12 |
Correct |
19 ms |
26620 KB |
Output is correct |
13 |
Correct |
21 ms |
26728 KB |
Output is correct |
14 |
Correct |
20 ms |
26604 KB |
Output is correct |
15 |
Correct |
21 ms |
26700 KB |
Output is correct |
16 |
Correct |
530 ms |
59820 KB |
Output is correct |
17 |
Correct |
500 ms |
69020 KB |
Output is correct |
18 |
Correct |
506 ms |
67748 KB |
Output is correct |
19 |
Correct |
507 ms |
67052 KB |
Output is correct |
20 |
Correct |
487 ms |
67252 KB |
Output is correct |
21 |
Correct |
526 ms |
67856 KB |
Output is correct |
22 |
Correct |
535 ms |
67244 KB |
Output is correct |
23 |
Correct |
545 ms |
68980 KB |
Output is correct |
24 |
Correct |
459 ms |
67504 KB |
Output is correct |
25 |
Correct |
446 ms |
66772 KB |
Output is correct |
26 |
Correct |
459 ms |
66808 KB |
Output is correct |
27 |
Correct |
505 ms |
66716 KB |
Output is correct |
28 |
Correct |
541 ms |
78552 KB |
Output is correct |
29 |
Correct |
620 ms |
78624 KB |
Output is correct |
30 |
Correct |
538 ms |
78772 KB |
Output is correct |
31 |
Correct |
568 ms |
78656 KB |
Output is correct |
32 |
Correct |
506 ms |
67368 KB |
Output is correct |
33 |
Correct |
565 ms |
68828 KB |
Output is correct |
34 |
Correct |
365 ms |
61556 KB |
Output is correct |
35 |
Correct |
580 ms |
72460 KB |
Output is correct |
36 |
Correct |
542 ms |
69120 KB |
Output is correct |
37 |
Correct |
597 ms |
71384 KB |
Output is correct |
38 |
Correct |
584 ms |
69868 KB |
Output is correct |
39 |
Correct |
535 ms |
74896 KB |
Output is correct |
40 |
Correct |
640 ms |
79100 KB |
Output is correct |
41 |
Correct |
558 ms |
69572 KB |
Output is correct |
42 |
Correct |
467 ms |
67772 KB |
Output is correct |
43 |
Correct |
650 ms |
77740 KB |
Output is correct |
44 |
Correct |
532 ms |
70648 KB |
Output is correct |
45 |
Correct |
508 ms |
74164 KB |
Output is correct |
46 |
Correct |
518 ms |
73652 KB |
Output is correct |
47 |
Correct |
519 ms |
78772 KB |
Output is correct |
48 |
Correct |
501 ms |
78552 KB |
Output is correct |
49 |
Correct |
506 ms |
78804 KB |
Output is correct |
50 |
Correct |
524 ms |
78636 KB |
Output is correct |
51 |
Correct |
591 ms |
78216 KB |
Output is correct |
52 |
Correct |
607 ms |
78276 KB |
Output is correct |