#include <bits/stdc++.h>
#include "werewolf.h"
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
struct BIT{
int n;
vector<int> bt;
void init(int x){
n=x;
bt.resize(n+1);
}
void update(int x,int y){
for(;x<=n;x+=(x&-x)){
bt[x]+=y;
}
}
int query(int x){
int ans=0;
for(;x>0;x-=(x&-x)){
ans+=bt[x];
}
return ans;
}
int sum(int l,int r){
return query(r)-query(l-1);
}
};
struct T1{
struct no{
vector<int> ch;
int in,out;
};
vector<no> v;
BIT bt;
int cnt=0;
void init(int x){
v.resize(x);
bt.init(x+1);
}
void add(int x,int y){
v[x].ch.push_back(y);
v[y].ch.push_back(x);
}
void dfs(int r,int f){
cnt++;
v[r].in=cnt;
for(auto h:v[r].ch){
if(h!=f){
dfs(h,r);
}
}
v[r].out=cnt;
}
vector<int> s;
void ap(int r){
s.push_back(r);
bt.update(v[r].in,1);
}
int query(int r){
return bt.sum(v[r].in,v[r].out);
}
void undo(){
while(s.size()){
bt.update(v[s.back()].in,-1);
s.pop_back();
}
}
}t1;
vector<int> ans;
struct T2{
struct no{
vector<int> ch;
int sz=1;
int vis=0;
int mx=-1;
vector<pair<int,int> > qu;
};
vector<no> v;
void init(int x){
v.resize(x);
}
void add(int x,int y){
v[x].ch.push_back(y);
v[y].ch.push_back(x);
}
void aq(int r,pair<int,int> a){
v[r].qu.push_back(a);
}
void cal(int r,int f,int t){
if(!v[r].vis){
for(auto h:v[r].ch){
if(h!=f && h!=v[r].mx){
cal(h,r,1);
}
}
}
if(v[r].mx>=0){
cal(v[r].mx,r,0);
}
t1.ap(r);
for(auto h:v[r].ch){
if(h!=f && h!=v[r].mx){
cal(h,r,0);
}
}
if(!v[r].vis){
for(auto h:v[r].qu){
ans[h.fs]=t1.query(h.sc)>0;
}
v[r].vis=1;
}
if(t){
t1.undo();
}
}
void dfs(int r,int f){
for(auto h:v[r].ch){
if(h!=f){
dfs(h,r);
v[r].sz+=v[h].sz;
if(v[r].mx==-1 || v[h].sz>v[v[r].mx].sz){
v[r].mx=h;
}
}
}
}
}t2;
struct DSU{
vector<int> bo;
void init(int x){
bo.resize(x);
iota(bo.begin(),bo.end(),0);
}
int find(int x){
return bo[x]==x?x:bo[x]=find(bo[x]);
}
pair<int,int> merge(int x,int y){
x=find(x);
y=find(y);
if(x==y){
return {-1,-1};
}
bo[y]=x;
return {x,y};
}
};
vector<int> check_validity(int n, vector<int> x, vector<int> y,
vector<int> s, vector<int> e,
vector<int> l, vector<int> r) {
int q=s.size();
int m=x.size();
vector<vector<int> > ls(n),re(n);
for(int i=0;i<q;i++){
ls[l[i]].push_back(i);
}
for(int i=0;i<q;i++){
re[r[i]].push_back(i);
}
ans.resize(q);
vector<vector<int> > f(n);
for(int i=0;i<m;i++){
f[x[i]].push_back(y[i]);
f[y[i]].push_back(x[i]);
}
t1.init(n);
DSU d1;
d1.init(n);
for(int i=0;i<n;i++){
for(auto z:f[i]){
if(z<i){
auto a=d1.merge(i,z);
if(a.fs>=0){
t1.add(a.fs,a.sc);
}
}
}
for(auto h:re[i]){
e[h]=d1.find(e[h]);
}
}
t1.dfs(n-1,n-1);
t2.init(n);
DSU d2;
d2.init(n);
for(int i=n-1;i>=0;i--){
for(auto z:f[i]){
if(z>i){
auto a=d2.merge(i,z);
if(a.fs>=0){
t2.add(a.fs,a.sc);
}
}
}
for(auto h:ls[i]){
s[h]=d2.find(s[h]);
t2.aq(s[h],{h,e[h]});
}
}
t2.dfs(0,0);
t2.cal(0,0,0);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
1492 KB |
Output is correct |
11 |
Correct |
4 ms |
1492 KB |
Output is correct |
12 |
Correct |
4 ms |
1364 KB |
Output is correct |
13 |
Correct |
4 ms |
1504 KB |
Output is correct |
14 |
Correct |
4 ms |
1516 KB |
Output is correct |
15 |
Correct |
5 ms |
1492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
588 ms |
76004 KB |
Output is correct |
2 |
Correct |
343 ms |
86424 KB |
Output is correct |
3 |
Correct |
360 ms |
83896 KB |
Output is correct |
4 |
Correct |
428 ms |
83244 KB |
Output is correct |
5 |
Correct |
426 ms |
83392 KB |
Output is correct |
6 |
Correct |
528 ms |
84092 KB |
Output is correct |
7 |
Correct |
505 ms |
81312 KB |
Output is correct |
8 |
Correct |
330 ms |
86340 KB |
Output is correct |
9 |
Correct |
349 ms |
82716 KB |
Output is correct |
10 |
Correct |
379 ms |
81476 KB |
Output is correct |
11 |
Correct |
405 ms |
81688 KB |
Output is correct |
12 |
Correct |
421 ms |
82424 KB |
Output is correct |
13 |
Correct |
348 ms |
100032 KB |
Output is correct |
14 |
Correct |
343 ms |
99968 KB |
Output is correct |
15 |
Correct |
340 ms |
100076 KB |
Output is correct |
16 |
Correct |
338 ms |
100092 KB |
Output is correct |
17 |
Correct |
525 ms |
81260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
1492 KB |
Output is correct |
11 |
Correct |
4 ms |
1492 KB |
Output is correct |
12 |
Correct |
4 ms |
1364 KB |
Output is correct |
13 |
Correct |
4 ms |
1504 KB |
Output is correct |
14 |
Correct |
4 ms |
1516 KB |
Output is correct |
15 |
Correct |
5 ms |
1492 KB |
Output is correct |
16 |
Correct |
588 ms |
76004 KB |
Output is correct |
17 |
Correct |
343 ms |
86424 KB |
Output is correct |
18 |
Correct |
360 ms |
83896 KB |
Output is correct |
19 |
Correct |
428 ms |
83244 KB |
Output is correct |
20 |
Correct |
426 ms |
83392 KB |
Output is correct |
21 |
Correct |
528 ms |
84092 KB |
Output is correct |
22 |
Correct |
505 ms |
81312 KB |
Output is correct |
23 |
Correct |
330 ms |
86340 KB |
Output is correct |
24 |
Correct |
349 ms |
82716 KB |
Output is correct |
25 |
Correct |
379 ms |
81476 KB |
Output is correct |
26 |
Correct |
405 ms |
81688 KB |
Output is correct |
27 |
Correct |
421 ms |
82424 KB |
Output is correct |
28 |
Correct |
348 ms |
100032 KB |
Output is correct |
29 |
Correct |
343 ms |
99968 KB |
Output is correct |
30 |
Correct |
340 ms |
100076 KB |
Output is correct |
31 |
Correct |
338 ms |
100092 KB |
Output is correct |
32 |
Correct |
525 ms |
81260 KB |
Output is correct |
33 |
Correct |
503 ms |
87400 KB |
Output is correct |
34 |
Correct |
157 ms |
36756 KB |
Output is correct |
35 |
Correct |
461 ms |
94620 KB |
Output is correct |
36 |
Correct |
499 ms |
86284 KB |
Output is correct |
37 |
Correct |
546 ms |
92668 KB |
Output is correct |
38 |
Correct |
489 ms |
87768 KB |
Output is correct |
39 |
Correct |
489 ms |
91272 KB |
Output is correct |
40 |
Correct |
450 ms |
95236 KB |
Output is correct |
41 |
Correct |
438 ms |
90288 KB |
Output is correct |
42 |
Correct |
405 ms |
83348 KB |
Output is correct |
43 |
Correct |
447 ms |
101504 KB |
Output is correct |
44 |
Correct |
441 ms |
91800 KB |
Output is correct |
45 |
Correct |
433 ms |
88488 KB |
Output is correct |
46 |
Correct |
421 ms |
88568 KB |
Output is correct |
47 |
Correct |
357 ms |
100160 KB |
Output is correct |
48 |
Correct |
333 ms |
100032 KB |
Output is correct |
49 |
Correct |
338 ms |
100208 KB |
Output is correct |
50 |
Correct |
342 ms |
100076 KB |
Output is correct |
51 |
Correct |
412 ms |
93648 KB |
Output is correct |
52 |
Correct |
413 ms |
93640 KB |
Output is correct |