#include <bits/stdc++.h>
using namespace std;
#define a first
#define b second
#define pb push_back
typedef long long llo;
#include "werewolf.h"
vector<pair<int,int>> pre[200001];
vector<pair<int,int>> pre2[200001];
vector<pair<int,int>> pre3[200001];
vector<pair<int,int>> pre4[200001];
int par[200001];
int ss[200001];
vector<int> adj[200001];
vector<int> adj2[200001];
int find(int no){
if(par[no]==no){
return no;
}
par[no]=find(par[no]);
return par[no];
}
int co=-1;
int st[200001];
int stt[200001];
void dfs(int no){
co++;
st[no]=co;
stt[co]=no;
for(auto j:adj[no]){
dfs(j);
}
}
int co2=-1;
int st2[200001];
int stt2[200001];
void dfs2(int no){
co2++;
st2[no]=co2;
stt2[co2]=no;
for(auto j:adj2[no]){
dfs2(j);
}
}
pair<int,int> ran[200001];
pair<int,int> ran2[200001];
int vis[200001];
vector<int> tree[800001];
void add(int no,int l,int r,int aa,int bb,int i){
if(r<aa or l>bb){
return;
}
if(aa<=l and r<=bb){
tree[no].pb(i);
}
else{
int mid=(l+r)/2;
add(no*2+1,l,mid,aa,bb,i);
add(no*2+2,mid+1,r,aa,bb,i);
}
}
int ans2[200001];
void update(int no,int l,int r,int i){
for(auto j:tree[no]){
if(vis[j]==0){
ans2[j]=1;
}
}
tree[no].clear();
if(l<r){
int mid=(l+r)/2;
if(i<=mid){
update(no*2+1,l,mid,i);
}
else{
update(no*2+2,mid+1,r,i);
}
}
}
//vector<int> pre5[200001];
vector<pair<pair<int,int>,int>> pre5[200001];
vector<int> pre6[200001];
vector<int> check_validity(int n,vector<int> xx,vector<int> yy,
vector<int> ss3,vector<int> ee,
vector<int> l,vector<int> r) {
int m=xx.size();
for(int i=0;i<m;i++){
pre[min(xx[i],yy[i])].pb({xx[i],yy[i]});
pre2[max(xx[i],yy[i])].pb({xx[i],yy[i]});
}
for(int i=0;i<n;i++){
par[i]=i;
ss[i]=1;
}
int q=ss3.size();
for(int i=0;i<q;i++){
pre3[l[i]].pb({ss3[i],i});
pre4[r[i]].pb({ee[i],i});
}
vector<pair<pair<int,int>,int>> qq;
for(int i=n-1;i>=0;i--){
for(auto j:pre[i]){
int x=find(j.a);
int y=find(j.b);
if(x!=y){
// cout<<x<<":"<<y<<endl;
adj[x].pb(y);
par[y]=x;
ss[x]+=ss[y];
}
}
for(auto j:pre3[i]){
qq.pb({{find(j.a),ss[find(j.a)]},j.b});
// cout<<j.a<<"."<<find(j.a)<<"/"<<ss[find(j.a)]<<"/"<<j.b<<endl;
}
}
dfs(find(0));
for(auto j:qq){
ran[j.b]={st[j.a.a],st[j.a.a]+j.a.b-1};
}
/*for(int i=0;i<q;i++){
cout<<ran[i].a<<":"<<ran[i].b<<endl;
for(int j=ran[i].a;j<=ran[i].b;j++){
cout<<stt[j]<<",";
}
cout<<endl;
}*/
for(int i=0;i<n;i++){
par[i]=i;
ss[i]=1;
}
vector<pair<pair<int,int>,int>> qq2;
for(int i=0;i<n;i++){
for(auto j:pre2[i]){
int x=find(j.a);
int y=find(j.b);
if(x!=y){
adj2[x].pb(y);
//cout<<x<<":"<<y<<endl;
par[y]=x;
ss[x]+=ss[y];
}
}
for(auto j:pre4[i]){
qq2.pb({{find(j.a),ss[find(j.a)]},j.b});
}
}
dfs2(find(0));
for(auto j:qq2){
ran2[j.b]={st2[j.a.a],st2[j.a.a]+j.a.b-1};
}
vector<int> ans;
for(int i=0;i<q;i++){
pre5[ran[i].a].pb({ran2[i],i});
pre6[ran[i].b].pb(i);
/*for(int j=ran[i].a;j<=ran[i].b;j++){
vis[stt[j]]+=1;
}
int kk=0;
for(int j=ran2[i].a;j<=ran2[i].b;j++){
vis[stt2[j]]+=1;
if(vis[stt2[j]]==2){
kk=-1;
}
}
ans.pb(kk);
for(int j=ran[i].a;j<=ran[i].b;j++){
vis[stt[j]]-=1;
}
for(int j=ran2[i].a;j<=ran2[i].b;j++){
vis[stt2[j]]-=1;
}*/
}
for(int i=0;i<n;i++){
for(auto j:pre5[i]){
add(0,0,n-1,j.a.a,j.a.b,j.b);
}
update(0,0,n-1,st2[stt[i]]);
for(auto j:pre6[i]){
vis[j]=1;
}
}
for(int i=0;i<q;i++){
ans.pb(ans2[i]);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
56864 KB |
Output is correct |
2 |
Correct |
36 ms |
56832 KB |
Output is correct |
3 |
Correct |
37 ms |
56704 KB |
Output is correct |
4 |
Correct |
36 ms |
56704 KB |
Output is correct |
5 |
Correct |
38 ms |
56824 KB |
Output is correct |
6 |
Correct |
38 ms |
56704 KB |
Output is correct |
7 |
Correct |
37 ms |
56696 KB |
Output is correct |
8 |
Correct |
36 ms |
56704 KB |
Output is correct |
9 |
Correct |
37 ms |
56752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
56864 KB |
Output is correct |
2 |
Correct |
36 ms |
56832 KB |
Output is correct |
3 |
Correct |
37 ms |
56704 KB |
Output is correct |
4 |
Correct |
36 ms |
56704 KB |
Output is correct |
5 |
Correct |
38 ms |
56824 KB |
Output is correct |
6 |
Correct |
38 ms |
56704 KB |
Output is correct |
7 |
Correct |
37 ms |
56696 KB |
Output is correct |
8 |
Correct |
36 ms |
56704 KB |
Output is correct |
9 |
Correct |
37 ms |
56752 KB |
Output is correct |
10 |
Correct |
48 ms |
57720 KB |
Output is correct |
11 |
Correct |
44 ms |
57728 KB |
Output is correct |
12 |
Correct |
43 ms |
57600 KB |
Output is correct |
13 |
Correct |
44 ms |
57720 KB |
Output is correct |
14 |
Correct |
43 ms |
57720 KB |
Output is correct |
15 |
Correct |
45 ms |
57848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
977 ms |
116340 KB |
Output is correct |
2 |
Correct |
1008 ms |
129576 KB |
Output is correct |
3 |
Correct |
938 ms |
127548 KB |
Output is correct |
4 |
Correct |
912 ms |
121720 KB |
Output is correct |
5 |
Correct |
884 ms |
122024 KB |
Output is correct |
6 |
Correct |
958 ms |
120836 KB |
Output is correct |
7 |
Correct |
746 ms |
117624 KB |
Output is correct |
8 |
Correct |
970 ms |
129576 KB |
Output is correct |
9 |
Correct |
876 ms |
123484 KB |
Output is correct |
10 |
Correct |
646 ms |
114984 KB |
Output is correct |
11 |
Correct |
686 ms |
114060 KB |
Output is correct |
12 |
Correct |
803 ms |
118512 KB |
Output is correct |
13 |
Correct |
1081 ms |
131844 KB |
Output is correct |
14 |
Correct |
1053 ms |
131856 KB |
Output is correct |
15 |
Correct |
1064 ms |
131880 KB |
Output is correct |
16 |
Correct |
1064 ms |
131748 KB |
Output is correct |
17 |
Correct |
735 ms |
117240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
56864 KB |
Output is correct |
2 |
Correct |
36 ms |
56832 KB |
Output is correct |
3 |
Correct |
37 ms |
56704 KB |
Output is correct |
4 |
Correct |
36 ms |
56704 KB |
Output is correct |
5 |
Correct |
38 ms |
56824 KB |
Output is correct |
6 |
Correct |
38 ms |
56704 KB |
Output is correct |
7 |
Correct |
37 ms |
56696 KB |
Output is correct |
8 |
Correct |
36 ms |
56704 KB |
Output is correct |
9 |
Correct |
37 ms |
56752 KB |
Output is correct |
10 |
Correct |
48 ms |
57720 KB |
Output is correct |
11 |
Correct |
44 ms |
57728 KB |
Output is correct |
12 |
Correct |
43 ms |
57600 KB |
Output is correct |
13 |
Correct |
44 ms |
57720 KB |
Output is correct |
14 |
Correct |
43 ms |
57720 KB |
Output is correct |
15 |
Correct |
45 ms |
57848 KB |
Output is correct |
16 |
Correct |
977 ms |
116340 KB |
Output is correct |
17 |
Correct |
1008 ms |
129576 KB |
Output is correct |
18 |
Correct |
938 ms |
127548 KB |
Output is correct |
19 |
Correct |
912 ms |
121720 KB |
Output is correct |
20 |
Correct |
884 ms |
122024 KB |
Output is correct |
21 |
Correct |
958 ms |
120836 KB |
Output is correct |
22 |
Correct |
746 ms |
117624 KB |
Output is correct |
23 |
Correct |
970 ms |
129576 KB |
Output is correct |
24 |
Correct |
876 ms |
123484 KB |
Output is correct |
25 |
Correct |
646 ms |
114984 KB |
Output is correct |
26 |
Correct |
686 ms |
114060 KB |
Output is correct |
27 |
Correct |
803 ms |
118512 KB |
Output is correct |
28 |
Correct |
1081 ms |
131844 KB |
Output is correct |
29 |
Correct |
1053 ms |
131856 KB |
Output is correct |
30 |
Correct |
1064 ms |
131880 KB |
Output is correct |
31 |
Correct |
1064 ms |
131748 KB |
Output is correct |
32 |
Correct |
735 ms |
117240 KB |
Output is correct |
33 |
Correct |
1060 ms |
117800 KB |
Output is correct |
34 |
Correct |
493 ms |
119188 KB |
Output is correct |
35 |
Correct |
1128 ms |
128044 KB |
Output is correct |
36 |
Correct |
1024 ms |
125480 KB |
Output is correct |
37 |
Correct |
1121 ms |
127124 KB |
Output is correct |
38 |
Correct |
1090 ms |
125836 KB |
Output is correct |
39 |
Correct |
1161 ms |
130088 KB |
Output is correct |
40 |
Correct |
991 ms |
140928 KB |
Output is correct |
41 |
Correct |
938 ms |
122920 KB |
Output is correct |
42 |
Correct |
724 ms |
119200 KB |
Output is correct |
43 |
Correct |
1195 ms |
133164 KB |
Output is correct |
44 |
Correct |
1025 ms |
124212 KB |
Output is correct |
45 |
Correct |
1051 ms |
133120 KB |
Output is correct |
46 |
Correct |
1096 ms |
131064 KB |
Output is correct |
47 |
Correct |
1065 ms |
140388 KB |
Output is correct |
48 |
Correct |
1138 ms |
139944 KB |
Output is correct |
49 |
Correct |
1116 ms |
140456 KB |
Output is correct |
50 |
Correct |
1117 ms |
140072 KB |
Output is correct |
51 |
Correct |
950 ms |
141160 KB |
Output is correct |
52 |
Correct |
904 ms |
141540 KB |
Output is correct |