#include "werewolf.h"
#include <cstdio>
#include <cstdlib>
#include <vector>
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int par[2][N],p[2][N][25],sz[2][N],tmin[2][N],tmout[2][N],timer,Lg,F,bbb,i;
vector<int>v[N],V[2][N],tree[4*N];
vector<pair<int,int> >e[2];
set<int> P[2][N];
namespace {
int read_int() {
int x;
if (scanf("%d", &x) != 1) {
fprintf(stderr, "Error while reading input\n");
exit(1);
}
return x;
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int find_parent(int u,int t){
if(par[t][u]==u) return u;
return par[t][u]=find_parent(par[t][u],t);
}
void merge(int u,int v,int t){
int p1=find_parent(u,t);
int p2=find_parent(v,t);
if(p1==p2) return;
if(!t)V[t][u].push_back(*P[t][p2].begin()),V[t][*P[t][p2].begin()].push_back(u);
else V[t][u].push_back(*--P[t][p2].end()),V[t][*--P[t][p2].end()].push_back(u),
e[1].push_back({u,*--P[t][p2].end()}),e[1].push_back({*--P[t][p2].end(),u});
if(P[t][p1].size()<P[t][p2].size()) swap(p1,p2);
while(P[t][p2].size()){
int cc=*P[t][p2].begin();
P[t][p1].insert(cc);
par[t][cc]=p1;
P[t][p2].erase(cc);
}
}
void dfs(int u,int t){
timer++;
tmin[t][u]=timer;
for(int j=1;j<Lg;j++){
p[t][u][j]=p[t][p[t][u][j-1]][j-1];
}
for(int i=0;i<V[t][u].size();i++){
if(p[t][u][0]==V[t][u][i]) continue;
if(!t && V[t][u][i]<u) cout<<1/bbb<<endl;
if(t && V[t][u][i]>u) cout<<1/bbb<<endl;
p[t][V[t][u][i]][0]=u;
dfs(V[t][u][i],t);
}
tmout[t][u]=timer;
}
void update(int u,int ind,int l,int r,int val){
if(l>ind || r<ind) return;
if(l==r) {
tree[u].push_back(val);
return;
}
tree[u].push_back(val);
if(tree[u].size()==r-l+1) sort(tree[u].begin(),tree[u].end());
int mid=(l+r)/2;
update(2*u,ind,l,mid,val);
update(2*u+1,ind,mid+1,r,val);
}
int getans(int u,int start,int end,int l,int r,int L,int R){
if(l>end || r<start) return 0;
if(l>=start && r<=end){
int ans=-1;
int le=0;int ri=tree[u].size()-1;
while(le<=ri){
int mid=(le+ri)/2;
if(tree[u][mid]<L){
ans=mid; le=mid+1;
}
else ri=mid-1;
}
int cnt=ans+1;
ans=tree[u].size();
le=0; ri=tree[u].size()-1;
while(le<=ri){
int mid=(le+ri)/2;
if(tree[u][mid]>R){
ans=mid; ri=mid-1;
}
else le=mid+1;
}
cnt+=tree[u].size()-ans;
return cnt;
}
int mid=(l+r)/2;
return getans(2*u,start,end,l,mid,L,R)+getans(2*u+1,start,end,mid+1,r,L,R);
}
int Lca(int u,int m,int t){
for(int i=Lg;i>=0;i--){
if(p[t][u][i] && ((!t && p[t][u][i]>=m)||(t && p[t][u][i]<=m))){
u=p[t][u][i];
}
}
return u;
}
std::vector<int> check_validity(int N, std::vector<int> X, std::vector<int> Y,
std::vector<int> S, std::vector<int> E,
std::vector<int> L, std::vector<int> R) {
int M = X.size();
Lg=log2(N)+1;
for(int i=1;i<=N;i++)
for(int j=0;j<=1;j++)
par[j][i]=i,P[j][i].insert(i);
for(int i=0;i<M;i++){
X[i]++; Y[i]++;
v[X[i]].push_back(Y[i]);
v[Y[i]].push_back(X[i]);
}
for(int i=N;i>=1;i--){
sort(v[i].begin(),v[i].end());
for(int j=0;j<v[i].size();j++){
int nxt=v[i][j];
if(nxt>i){
merge(i,nxt,0);
}
}
}
timer=0;
dfs(1,0);
for(int i=1;i<=N;i++){
reverse(v[i].begin(),v[i].end());
for(int j=0;j<v[i].size();j++){
int nxt=v[i][j];
if(nxt<i){
merge(i,nxt,1);
}
}
}
int Q=S.size();vector<int>Ans(Q);
timer=0;
dfs(N,1);
for(int i=1;i<=N;i++){
update(1,tmin[0][i],1,N,tmin[1][i]);
}
for(int i=0;i<Q;i++){
S[i]++;
E[i]++;
L[i]++;
R[i]++; F=i;
int x=Lca(S[i],L[i],0);
int y=Lca(E[i],R[i],1);
if(tmout[0][x]-tmin[0][x]+1-getans(1,tmin[0][x],tmout[0][x],1,N,tmin[1][y],tmout[1][y])) Ans[i]=1;
else Ans[i]=0;
}
return Ans;
}
Compilation message
werewolf.cpp: In function 'void dfs(int, int)':
werewolf.cpp:51:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int i=0;i<V[t][u].size();i++){
| ~^~~~~~~~~~~~~~~
werewolf.cpp: In function 'void update(int, int, int, int, int)':
werewolf.cpp:67:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
67 | if(tree[u].size()==r-l+1) sort(tree[u].begin(),tree[u].end());
| ~~~~~~~~~~~~~~^~~~~~~
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:124:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
124 | for(int j=0;j<v[i].size();j++){
| ~^~~~~~~~~~~~
werewolf.cpp:135:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
135 | for(int j=0;j<v[i].size();j++){
| ~^~~~~~~~~~~~
werewolf.cpp: At global scope:
werewolf.cpp:14:5: warning: 'int {anonymous}::read_int()' defined but not used [-Wunused-function]
14 | int read_int() {
| ^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
52076 KB |
Output is correct |
2 |
Correct |
31 ms |
52076 KB |
Output is correct |
3 |
Correct |
31 ms |
52076 KB |
Output is correct |
4 |
Correct |
31 ms |
52076 KB |
Output is correct |
5 |
Correct |
32 ms |
52076 KB |
Output is correct |
6 |
Correct |
31 ms |
52096 KB |
Output is correct |
7 |
Correct |
31 ms |
52088 KB |
Output is correct |
8 |
Correct |
32 ms |
52076 KB |
Output is correct |
9 |
Correct |
30 ms |
52204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
52076 KB |
Output is correct |
2 |
Correct |
31 ms |
52076 KB |
Output is correct |
3 |
Correct |
31 ms |
52076 KB |
Output is correct |
4 |
Correct |
31 ms |
52076 KB |
Output is correct |
5 |
Correct |
32 ms |
52076 KB |
Output is correct |
6 |
Correct |
31 ms |
52096 KB |
Output is correct |
7 |
Correct |
31 ms |
52088 KB |
Output is correct |
8 |
Correct |
32 ms |
52076 KB |
Output is correct |
9 |
Correct |
30 ms |
52204 KB |
Output is correct |
10 |
Correct |
45 ms |
54124 KB |
Output is correct |
11 |
Correct |
44 ms |
53996 KB |
Output is correct |
12 |
Correct |
44 ms |
53868 KB |
Output is correct |
13 |
Correct |
42 ms |
54252 KB |
Output is correct |
14 |
Correct |
42 ms |
54252 KB |
Output is correct |
15 |
Correct |
44 ms |
54272 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2618 ms |
178652 KB |
Output is correct |
2 |
Correct |
1841 ms |
186460 KB |
Output is correct |
3 |
Correct |
1810 ms |
181076 KB |
Output is correct |
4 |
Correct |
1812 ms |
178772 KB |
Output is correct |
5 |
Correct |
1840 ms |
178516 KB |
Output is correct |
6 |
Correct |
2223 ms |
178260 KB |
Output is correct |
7 |
Correct |
2517 ms |
178792 KB |
Output is correct |
8 |
Correct |
1800 ms |
186452 KB |
Output is correct |
9 |
Correct |
1396 ms |
181096 KB |
Output is correct |
10 |
Correct |
1533 ms |
178772 KB |
Output is correct |
11 |
Correct |
1648 ms |
178860 KB |
Output is correct |
12 |
Correct |
2015 ms |
178516 KB |
Output is correct |
13 |
Correct |
1605 ms |
189524 KB |
Output is correct |
14 |
Correct |
1587 ms |
189604 KB |
Output is correct |
15 |
Correct |
1493 ms |
189396 KB |
Output is correct |
16 |
Correct |
1519 ms |
189480 KB |
Output is correct |
17 |
Correct |
2530 ms |
178452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
52076 KB |
Output is correct |
2 |
Correct |
31 ms |
52076 KB |
Output is correct |
3 |
Correct |
31 ms |
52076 KB |
Output is correct |
4 |
Correct |
31 ms |
52076 KB |
Output is correct |
5 |
Correct |
32 ms |
52076 KB |
Output is correct |
6 |
Correct |
31 ms |
52096 KB |
Output is correct |
7 |
Correct |
31 ms |
52088 KB |
Output is correct |
8 |
Correct |
32 ms |
52076 KB |
Output is correct |
9 |
Correct |
30 ms |
52204 KB |
Output is correct |
10 |
Correct |
45 ms |
54124 KB |
Output is correct |
11 |
Correct |
44 ms |
53996 KB |
Output is correct |
12 |
Correct |
44 ms |
53868 KB |
Output is correct |
13 |
Correct |
42 ms |
54252 KB |
Output is correct |
14 |
Correct |
42 ms |
54252 KB |
Output is correct |
15 |
Correct |
44 ms |
54272 KB |
Output is correct |
16 |
Correct |
2618 ms |
178652 KB |
Output is correct |
17 |
Correct |
1841 ms |
186460 KB |
Output is correct |
18 |
Correct |
1810 ms |
181076 KB |
Output is correct |
19 |
Correct |
1812 ms |
178772 KB |
Output is correct |
20 |
Correct |
1840 ms |
178516 KB |
Output is correct |
21 |
Correct |
2223 ms |
178260 KB |
Output is correct |
22 |
Correct |
2517 ms |
178792 KB |
Output is correct |
23 |
Correct |
1800 ms |
186452 KB |
Output is correct |
24 |
Correct |
1396 ms |
181096 KB |
Output is correct |
25 |
Correct |
1533 ms |
178772 KB |
Output is correct |
26 |
Correct |
1648 ms |
178860 KB |
Output is correct |
27 |
Correct |
2015 ms |
178516 KB |
Output is correct |
28 |
Correct |
1605 ms |
189524 KB |
Output is correct |
29 |
Correct |
1587 ms |
189604 KB |
Output is correct |
30 |
Correct |
1493 ms |
189396 KB |
Output is correct |
31 |
Correct |
1519 ms |
189480 KB |
Output is correct |
32 |
Correct |
2530 ms |
178452 KB |
Output is correct |
33 |
Correct |
2578 ms |
184608 KB |
Output is correct |
34 |
Correct |
438 ms |
83948 KB |
Output is correct |
35 |
Correct |
2605 ms |
189524 KB |
Output is correct |
36 |
Correct |
2518 ms |
183500 KB |
Output is correct |
37 |
Correct |
2617 ms |
187992 KB |
Output is correct |
38 |
Correct |
2545 ms |
184688 KB |
Output is correct |
39 |
Correct |
1926 ms |
204756 KB |
Output is correct |
40 |
Correct |
2056 ms |
194268 KB |
Output is correct |
41 |
Correct |
2439 ms |
187292 KB |
Output is correct |
42 |
Correct |
2296 ms |
183548 KB |
Output is correct |
43 |
Correct |
2689 ms |
195464 KB |
Output is correct |
44 |
Correct |
2561 ms |
188132 KB |
Output is correct |
45 |
Correct |
1969 ms |
204900 KB |
Output is correct |
46 |
Correct |
2235 ms |
204628 KB |
Output is correct |
47 |
Correct |
1618 ms |
193236 KB |
Output is correct |
48 |
Correct |
1574 ms |
193364 KB |
Output is correct |
49 |
Correct |
1527 ms |
193508 KB |
Output is correct |
50 |
Correct |
1527 ms |
193108 KB |
Output is correct |
51 |
Correct |
1967 ms |
195156 KB |
Output is correct |
52 |
Correct |
1935 ms |
194916 KB |
Output is correct |