#include<bits/stdc++.h>
#include "werewolf.h"
using namespace std;
struct ZAP
{
int v,ind;
};
vector<int>D[200009];
vector<int>S[2009];
bool Nawiazanie[2009];
vector<ZAP>Q1[200009],Q2[200009];
int spojna[200009];
vector<int>V[200009],V2[200009];
int JakieS[200009];
vector<int>Z1[200009],Z2[200009];
int Z1s[200009],Z2s[200009];
bool CzyNachodzi[2009][2009];
bool help[200009];
int n,m,q,SQRT,h=0;
void Polacz(int a, int b)
{
a=spojna[a];
b=spojna[b];
if(a==b){return;}
if(V2[a].size()<V2[b].size()){swap(a,b);}
for(int u : V[b])
{
V[a].push_back(u);
}
for(int u : V2[b])
{
spojna[u]=a;
V2[a].push_back(u);
}
V[b].clear();
V2[b].clear();
vector<int>Pier;
if(JakieS[a]!=-1){Pier.push_back(JakieS[a]);}
if(JakieS[b]!=-1){Pier.push_back(JakieS[b]);}
if((int)V[a].size()>=SQRT)
{
h++;
for(int i=1;i<=SQRT;i++)
{
S[h].push_back(V[a].back());
V[a].pop_back();
}
Pier.push_back(h);
}
while((int)Pier.size()>1)
{
const int aa=Pier[Pier.size()-2];
const int bb=Pier[Pier.size()-1];
Pier.pop_back();
Pier.pop_back();
h++;
Pier.push_back(h);
Nawiazanie[h]=1;
S[h]={aa,bb};
}
if((int)Pier.size()==0){JakieS[a]=-1;}
else{JakieS[a]=Pier[0];}
}
void Polacz2(int a, int b)
{
a=spojna[a];
b=spojna[b];
if(a==b){return;}
if(V[a].size()<V[b].size()){swap(a,b);}
for(int u : V[b])
{
spojna[u]=a;
V[a].push_back(u);
}
V[b].clear();
}
vector<int>check_validity(int N, vector<int>E1, vector<int>E2, vector<int>AA, vector<int>BB, vector<int>LL, vector<int>RR)
{
n=N;
m=E1.size();
q=AA.size();
vector<int>ODP(q);
SQRT=max(2,(int)sqrt(n));
for(int i=0;i<m;i++)
{
const int a=E1[i],b=E2[i];
D[a].push_back(b);
D[b].push_back(a);
}
for(int i=0;i<q;i++)
{
Q1[RR[i]].push_back({BB[i],i});
Q2[LL[i]].push_back({AA[i],i});
}
memset(JakieS,-1,sizeof(JakieS));
for(int i=0;i<n;i++){spojna[i]=i;V[i]={i};V2[i]={i};}
for(int i=0;i<n;i++)
{
for(int som : D[i])
{
if(som<=i)
Polacz(i,som);
}
for(auto[v,ind] : Q1[i])
{
Z1[ind]=V[spojna[v]];
Z1s[ind]=JakieS[spojna[v]];
}
}
memset(JakieS,-1,sizeof(JakieS));
for(int i=0;i<n;i++){spojna[i]=i;V[i]={i};V2[i]={i};}
for(int i=n-1;i>=0;i--)
{
for(int som : D[i])
{
if(som>=i)
Polacz(i,som);
}
for(auto[v,ind] : Q2[i])
{
Z2[ind]=V[spojna[v]];
Z2s[ind]=JakieS[spojna[v]];
}
}
for(int i=1;i<=h;i++)
{
CzyNachodzi[i][i]=1;
if(Nawiazanie[i]){continue;}
for(int j=i+1;j<=h;j++)
{
if(Nawiazanie[j]){continue;}
for(int u : S[i])
{
help[u]=1;
}
bool cv=0;
for(int u : S[j])
{
if(help[u])
{
cv=1;
break;
}
}
CzyNachodzi[i][j]=cv;
CzyNachodzi[j][i]=cv;
for(int u : S[i])
{
help[u]=0;
}
}
}
/**for(int i=1;i<=h;i++)
{
if(Nawiazanie[i])
{
cout<<"i="<<i<<" a="<<S[i][0]<<" b="<<S[i][1]<<endl;
}
else
{
cout<<"i="<<i<<"| ";
for(int u : S[i])
{
cout<<u<<",";
}
cout<<endl;
}
}**/
for(int i=1;i<=h;i++)
{
for(int j=1;j<i;j++)
{
bool cv;
if(Nawiazanie[i]==0&&Nawiazanie[j]==0){continue;}
if(Nawiazanie[j]==0)
{
cv=(CzyNachodzi[j][S[i][0]]|CzyNachodzi[j][S[i][1]]);
}
else if(Nawiazanie[i]==0)
{
cv=(CzyNachodzi[i][S[j][0]]|CzyNachodzi[i][S[j][1]]);
}
else
{
cv=(CzyNachodzi[S[i][0]][S[j][0]]|CzyNachodzi[S[i][0]][S[j][1]]|
CzyNachodzi[S[i][1]][S[j][0]]|CzyNachodzi[S[i][1]][S[j][1]]);
}
CzyNachodzi[i][j]=cv;
CzyNachodzi[j][i]=cv;
}
}
memset(JakieS,-1,sizeof(JakieS));
for(int i=0;i<n;i++){spojna[i]=i;V[i]={i};}
for(int i=0;i<n;i++)
{
for(int som : D[i])
{
if(som<=i)
Polacz2(i,som);
}
for(auto[v,ind] : Q1[i])
{
int s=spojna[v];
for(int u : Z2[ind])
{
if(spojna[u]==s)
{
ODP[ind]=1;
break;
}
}
}
}
memset(JakieS,-1,sizeof(JakieS));
for(int i=0;i<n;i++){spojna[i]=i;V[i]={i};}
for(int i=n-1;i>=0;i--)
{
for(int som : D[i])
{
if(som>=i)
Polacz2(i,som);
}
for(auto[v,ind] : Q2[i])
{
int s=spojna[v];
for(int u : Z1[ind])
{
if(spojna[u]==s)
{
ODP[ind]=1;
break;
}
}
}
}
for(int i=0;i<q;i++)
{
if(Z1s[i]==-1||Z2s[i]==-1){continue;}
if(CzyNachodzi[Z1s[i]][Z2s[i]])
{
ODP[i]=1;
}
}
for(int i=0;i<q;i++)
{
if(AA[i]<LL[i]||RR[i]<BB[i]){ODP[i]=0;}
}
return ODP;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
34136 KB |
Output is correct |
2 |
Correct |
13 ms |
34304 KB |
Output is correct |
3 |
Correct |
15 ms |
34140 KB |
Output is correct |
4 |
Correct |
15 ms |
34088 KB |
Output is correct |
5 |
Correct |
14 ms |
34140 KB |
Output is correct |
6 |
Correct |
14 ms |
34140 KB |
Output is correct |
7 |
Correct |
14 ms |
34140 KB |
Output is correct |
8 |
Correct |
15 ms |
34136 KB |
Output is correct |
9 |
Correct |
14 ms |
34032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
34136 KB |
Output is correct |
2 |
Correct |
13 ms |
34304 KB |
Output is correct |
3 |
Correct |
15 ms |
34140 KB |
Output is correct |
4 |
Correct |
15 ms |
34088 KB |
Output is correct |
5 |
Correct |
14 ms |
34140 KB |
Output is correct |
6 |
Correct |
14 ms |
34140 KB |
Output is correct |
7 |
Correct |
14 ms |
34140 KB |
Output is correct |
8 |
Correct |
15 ms |
34136 KB |
Output is correct |
9 |
Correct |
14 ms |
34032 KB |
Output is correct |
10 |
Correct |
18 ms |
35676 KB |
Output is correct |
11 |
Correct |
18 ms |
35676 KB |
Output is correct |
12 |
Correct |
19 ms |
35676 KB |
Output is correct |
13 |
Correct |
24 ms |
35676 KB |
Output is correct |
14 |
Correct |
18 ms |
35676 KB |
Output is correct |
15 |
Correct |
26 ms |
36356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1033 ms |
160204 KB |
Output is correct |
2 |
Correct |
906 ms |
446392 KB |
Output is correct |
3 |
Correct |
945 ms |
449608 KB |
Output is correct |
4 |
Correct |
1071 ms |
395056 KB |
Output is correct |
5 |
Correct |
1140 ms |
380312 KB |
Output is correct |
6 |
Correct |
1251 ms |
289928 KB |
Output is correct |
7 |
Correct |
1138 ms |
398520 KB |
Output is correct |
8 |
Correct |
907 ms |
447396 KB |
Output is correct |
9 |
Correct |
877 ms |
367768 KB |
Output is correct |
10 |
Correct |
1006 ms |
404352 KB |
Output is correct |
11 |
Correct |
1008 ms |
327608 KB |
Output is correct |
12 |
Correct |
1142 ms |
305328 KB |
Output is correct |
13 |
Correct |
981 ms |
447776 KB |
Output is correct |
14 |
Correct |
971 ms |
447040 KB |
Output is correct |
15 |
Correct |
1002 ms |
447040 KB |
Output is correct |
16 |
Correct |
1002 ms |
447552 KB |
Output is correct |
17 |
Correct |
1154 ms |
417048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
34136 KB |
Output is correct |
2 |
Correct |
13 ms |
34304 KB |
Output is correct |
3 |
Correct |
15 ms |
34140 KB |
Output is correct |
4 |
Correct |
15 ms |
34088 KB |
Output is correct |
5 |
Correct |
14 ms |
34140 KB |
Output is correct |
6 |
Correct |
14 ms |
34140 KB |
Output is correct |
7 |
Correct |
14 ms |
34140 KB |
Output is correct |
8 |
Correct |
15 ms |
34136 KB |
Output is correct |
9 |
Correct |
14 ms |
34032 KB |
Output is correct |
10 |
Correct |
18 ms |
35676 KB |
Output is correct |
11 |
Correct |
18 ms |
35676 KB |
Output is correct |
12 |
Correct |
19 ms |
35676 KB |
Output is correct |
13 |
Correct |
24 ms |
35676 KB |
Output is correct |
14 |
Correct |
18 ms |
35676 KB |
Output is correct |
15 |
Correct |
26 ms |
36356 KB |
Output is correct |
16 |
Correct |
1033 ms |
160204 KB |
Output is correct |
17 |
Correct |
906 ms |
446392 KB |
Output is correct |
18 |
Correct |
945 ms |
449608 KB |
Output is correct |
19 |
Correct |
1071 ms |
395056 KB |
Output is correct |
20 |
Correct |
1140 ms |
380312 KB |
Output is correct |
21 |
Correct |
1251 ms |
289928 KB |
Output is correct |
22 |
Correct |
1138 ms |
398520 KB |
Output is correct |
23 |
Correct |
907 ms |
447396 KB |
Output is correct |
24 |
Correct |
877 ms |
367768 KB |
Output is correct |
25 |
Correct |
1006 ms |
404352 KB |
Output is correct |
26 |
Correct |
1008 ms |
327608 KB |
Output is correct |
27 |
Correct |
1142 ms |
305328 KB |
Output is correct |
28 |
Correct |
981 ms |
447776 KB |
Output is correct |
29 |
Correct |
971 ms |
447040 KB |
Output is correct |
30 |
Correct |
1002 ms |
447040 KB |
Output is correct |
31 |
Correct |
1002 ms |
447552 KB |
Output is correct |
32 |
Correct |
1154 ms |
417048 KB |
Output is correct |
33 |
Correct |
1068 ms |
264868 KB |
Output is correct |
34 |
Correct |
232 ms |
105436 KB |
Output is correct |
35 |
Correct |
1041 ms |
326596 KB |
Output is correct |
36 |
Correct |
1061 ms |
204936 KB |
Output is correct |
37 |
Correct |
1104 ms |
305564 KB |
Output is correct |
38 |
Correct |
1074 ms |
235688 KB |
Output is correct |
39 |
Correct |
1062 ms |
295492 KB |
Output is correct |
40 |
Runtime error |
473 ms |
524288 KB |
Execution killed with signal 9 |
41 |
Halted |
0 ms |
0 KB |
- |