#include "werewolf.h"
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
const int N=2e5+50,lg=19;
struct DSU{
int par[N+50],in[N+50],out[N+50],nc,a[N+50],Par[N+50][lg+1],sajz[N+50];
vector<int>E[N+50];
void Init(){for(int i=0;i<=N;i++)par[i]=i,nc=0,sajz[i]=1;}
int FS(int u){if(par[u]==u) return u;return par[u]=FS(par[u]);}
void US(int u,int v){par[FS(u)]=FS(v);}//{if(sajz[u]>sajz[v]) swap(u,v);par[v]=u;sajz[v]+=sajz[u];}
void AddEdge(int u,int v){if(u!=v){E[u].pb(v),E[v].pb(u);}}
void DFS(int u,int parent){
//printf("%i %i\n",u-1,parent-1);
in[u]=++nc;a[nc]=u;Par[u][0]=parent;
for(int i=1;i<=lg;i++) Par[u][i]=Par[Par[u][i-1]][i-1];
for(auto i:E[u]) if(i!=parent) DFS(i,u);
out[u]=nc;
}
int NadjiL(int u,int x){for(int i=lg;i>=0;i--) if(Par[u][i] && Par[u][i]<=x) u=Par[u][i];return u;}
int NadjiR(int u,int x){for(int i=lg;i>=0;i--) if(Par[u][i]>=x) u=Par[u][i];return u;}
}dsu[2];
int ind[N+50];
vector<int>E[N+50];
vector<array<int,5> >Qs;
vector<array<int,5> >ev[N+50];
int T[N+50];
void Update(int i,int qval){for(;i<=N;i+=i&-i)T[i]+=qval;}
int Get(int i){int res=0;for(;i>=1;i-=i&-i)res+=T[i];return res;}
std::vector<int> check_validity(int n, std::vector<int> X, std::vector<int> Y,std::vector<int> U, std::vector<int> V,std::vector<int> L, std::vector<int> R) {
int q=U.size();
for(int i=0;i<q;i++) U[i]++,V[i]++,L[i]++,R[i]++;
for(int i=0;i<X.size();i++){
X[i]++,Y[i]++;
int u=X[i],v=Y[i];
E[u].pb(v);E[v].pb(u);
}
dsu[0].Init(),dsu[1].Init();
for(int i=1;i<=n;i++){
for(auto j:E[i]) if(j<i && dsu[0].FS(j)!=dsu[0].FS(i)) {dsu[0].AddEdge(dsu[0].FS(j),i);dsu[0].US(j,i);}
//for(int j=1;j<=n;j++) printf("%i %i\n",dsu[0].par[j]-1,j-1);printf("\n");
}
dsu[0].DFS(n,0);
//printf("\n");
for(int i=n;i>=1;i--) for(auto j:E[i]) if(j>i && dsu[1].FS(j)!=dsu[1].FS(i)) {dsu[1].AddEdge(dsu[1].FS(j),i);dsu[1].US(j,i);}
dsu[1].DFS(1,0);
//for(int i=1;i<=n;i++) printf("%i ",dsu[0].a[i]-1);printf("\n");
//for(int i=1;i<=n;i++) printf("%i %i\n",dsu[0].in[i],dsu[0].out[i]);printf("\n");
for(int i=1;i<=n;i++) ind[dsu[1].a[i]]=i;
vector<int>res(q,0);
for(int I=0;I<q;I++){
int u=U[I],v=V[I],l=L[I],r=R[I];
int v1=dsu[0].NadjiL(v,r),u1=dsu[1].NadjiR(u,l);
Qs.pb({dsu[0].in[v1],dsu[0].out[v1],dsu[1].in[u1],dsu[1].out[u1],I});
ev[dsu[0].in[v1]-1].pb({dsu[1].in[u1],dsu[1].out[u1],I,-1});
ev[dsu[0].out[v1]].pb({dsu[1].in[u1],dsu[1].out[u1],I,1});
}
for(int i=1;i<=n;i++){
Update(ind[dsu[0].a[i]],1);
for(auto j:ev[i]){
int bul=j[3];
res[j[2]]+=bul*(Get(j[1])-Get(j[0]-1));
}
}
for(int i=0;i<q;i++) if(res[i]) res[i]=1;
return res;
}
Compilation message
werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:37:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i=0;i<X.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
22360 KB |
Output is correct |
2 |
Correct |
10 ms |
22364 KB |
Output is correct |
3 |
Correct |
9 ms |
22360 KB |
Output is correct |
4 |
Correct |
9 ms |
22324 KB |
Output is correct |
5 |
Correct |
10 ms |
22360 KB |
Output is correct |
6 |
Correct |
9 ms |
22360 KB |
Output is correct |
7 |
Correct |
12 ms |
22360 KB |
Output is correct |
8 |
Correct |
10 ms |
22364 KB |
Output is correct |
9 |
Correct |
10 ms |
22384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
22360 KB |
Output is correct |
2 |
Correct |
10 ms |
22364 KB |
Output is correct |
3 |
Correct |
9 ms |
22360 KB |
Output is correct |
4 |
Correct |
9 ms |
22324 KB |
Output is correct |
5 |
Correct |
10 ms |
22360 KB |
Output is correct |
6 |
Correct |
9 ms |
22360 KB |
Output is correct |
7 |
Correct |
12 ms |
22360 KB |
Output is correct |
8 |
Correct |
10 ms |
22364 KB |
Output is correct |
9 |
Correct |
10 ms |
22384 KB |
Output is correct |
10 |
Correct |
13 ms |
23644 KB |
Output is correct |
11 |
Correct |
14 ms |
23612 KB |
Output is correct |
12 |
Correct |
15 ms |
23640 KB |
Output is correct |
13 |
Correct |
14 ms |
23888 KB |
Output is correct |
14 |
Correct |
13 ms |
23852 KB |
Output is correct |
15 |
Correct |
15 ms |
23896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
421 ms |
112536 KB |
Output is correct |
2 |
Correct |
372 ms |
114904 KB |
Output is correct |
3 |
Correct |
351 ms |
113668 KB |
Output is correct |
4 |
Correct |
338 ms |
112536 KB |
Output is correct |
5 |
Correct |
345 ms |
112144 KB |
Output is correct |
6 |
Correct |
352 ms |
112088 KB |
Output is correct |
7 |
Correct |
366 ms |
111572 KB |
Output is correct |
8 |
Correct |
354 ms |
114900 KB |
Output is correct |
9 |
Correct |
315 ms |
113628 KB |
Output is correct |
10 |
Correct |
289 ms |
111840 KB |
Output is correct |
11 |
Correct |
310 ms |
112308 KB |
Output is correct |
12 |
Correct |
332 ms |
112344 KB |
Output is correct |
13 |
Correct |
418 ms |
113948 KB |
Output is correct |
14 |
Correct |
425 ms |
113764 KB |
Output is correct |
15 |
Correct |
409 ms |
113776 KB |
Output is correct |
16 |
Correct |
417 ms |
113752 KB |
Output is correct |
17 |
Correct |
386 ms |
111832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
22360 KB |
Output is correct |
2 |
Correct |
10 ms |
22364 KB |
Output is correct |
3 |
Correct |
9 ms |
22360 KB |
Output is correct |
4 |
Correct |
9 ms |
22324 KB |
Output is correct |
5 |
Correct |
10 ms |
22360 KB |
Output is correct |
6 |
Correct |
9 ms |
22360 KB |
Output is correct |
7 |
Correct |
12 ms |
22360 KB |
Output is correct |
8 |
Correct |
10 ms |
22364 KB |
Output is correct |
9 |
Correct |
10 ms |
22384 KB |
Output is correct |
10 |
Correct |
13 ms |
23644 KB |
Output is correct |
11 |
Correct |
14 ms |
23612 KB |
Output is correct |
12 |
Correct |
15 ms |
23640 KB |
Output is correct |
13 |
Correct |
14 ms |
23888 KB |
Output is correct |
14 |
Correct |
13 ms |
23852 KB |
Output is correct |
15 |
Correct |
15 ms |
23896 KB |
Output is correct |
16 |
Correct |
421 ms |
112536 KB |
Output is correct |
17 |
Correct |
372 ms |
114904 KB |
Output is correct |
18 |
Correct |
351 ms |
113668 KB |
Output is correct |
19 |
Correct |
338 ms |
112536 KB |
Output is correct |
20 |
Correct |
345 ms |
112144 KB |
Output is correct |
21 |
Correct |
352 ms |
112088 KB |
Output is correct |
22 |
Correct |
366 ms |
111572 KB |
Output is correct |
23 |
Correct |
354 ms |
114900 KB |
Output is correct |
24 |
Correct |
315 ms |
113628 KB |
Output is correct |
25 |
Correct |
289 ms |
111840 KB |
Output is correct |
26 |
Correct |
310 ms |
112308 KB |
Output is correct |
27 |
Correct |
332 ms |
112344 KB |
Output is correct |
28 |
Correct |
418 ms |
113948 KB |
Output is correct |
29 |
Correct |
425 ms |
113764 KB |
Output is correct |
30 |
Correct |
409 ms |
113776 KB |
Output is correct |
31 |
Correct |
417 ms |
113752 KB |
Output is correct |
32 |
Correct |
386 ms |
111832 KB |
Output is correct |
33 |
Correct |
458 ms |
113368 KB |
Output is correct |
34 |
Correct |
196 ms |
67096 KB |
Output is correct |
35 |
Correct |
480 ms |
115372 KB |
Output is correct |
36 |
Correct |
456 ms |
113116 KB |
Output is correct |
37 |
Correct |
470 ms |
114812 KB |
Output is correct |
38 |
Correct |
428 ms |
113372 KB |
Output is correct |
39 |
Correct |
421 ms |
117728 KB |
Output is correct |
40 |
Correct |
508 ms |
120540 KB |
Output is correct |
41 |
Correct |
381 ms |
113208 KB |
Output is correct |
42 |
Correct |
369 ms |
111840 KB |
Output is correct |
43 |
Correct |
440 ms |
118644 KB |
Output is correct |
44 |
Correct |
400 ms |
114908 KB |
Output is correct |
45 |
Correct |
378 ms |
117788 KB |
Output is correct |
46 |
Correct |
388 ms |
117348 KB |
Output is correct |
47 |
Correct |
431 ms |
113916 KB |
Output is correct |
48 |
Correct |
424 ms |
113768 KB |
Output is correct |
49 |
Correct |
444 ms |
114020 KB |
Output is correct |
50 |
Correct |
404 ms |
113772 KB |
Output is correct |
51 |
Correct |
442 ms |
120796 KB |
Output is correct |
52 |
Correct |
451 ms |
120792 KB |
Output is correct |