#include<bits/stdc++.h>
#include "werewolf.h"
using namespace std;
struct ZAP
{
int v,ind;
};
vector<int>D[200009];
vector<int>S[4009];
bool Nawiazanie[4009];
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[4009][4009];
bool help[200009];
int n,m,q,SQRT=223,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 |
15 ms |
34136 KB |
Output is correct |
2 |
Correct |
17 ms |
34044 KB |
Output is correct |
3 |
Correct |
14 ms |
34140 KB |
Output is correct |
4 |
Correct |
14 ms |
34212 KB |
Output is correct |
5 |
Correct |
16 ms |
34108 KB |
Output is correct |
6 |
Correct |
17 ms |
34136 KB |
Output is correct |
7 |
Correct |
14 ms |
34140 KB |
Output is correct |
8 |
Correct |
14 ms |
34136 KB |
Output is correct |
9 |
Correct |
17 ms |
34140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
34136 KB |
Output is correct |
2 |
Correct |
17 ms |
34044 KB |
Output is correct |
3 |
Correct |
14 ms |
34140 KB |
Output is correct |
4 |
Correct |
14 ms |
34212 KB |
Output is correct |
5 |
Correct |
16 ms |
34108 KB |
Output is correct |
6 |
Correct |
17 ms |
34136 KB |
Output is correct |
7 |
Correct |
14 ms |
34140 KB |
Output is correct |
8 |
Correct |
14 ms |
34136 KB |
Output is correct |
9 |
Correct |
17 ms |
34140 KB |
Output is correct |
10 |
Correct |
19 ms |
36952 KB |
Output is correct |
11 |
Correct |
18 ms |
36700 KB |
Output is correct |
12 |
Correct |
19 ms |
35928 KB |
Output is correct |
13 |
Correct |
20 ms |
36956 KB |
Output is correct |
14 |
Correct |
21 ms |
36700 KB |
Output is correct |
15 |
Correct |
20 ms |
36440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1448 ms |
163648 KB |
Output is correct |
2 |
Correct |
1122 ms |
279104 KB |
Output is correct |
3 |
Correct |
1197 ms |
284880 KB |
Output is correct |
4 |
Correct |
1310 ms |
273484 KB |
Output is correct |
5 |
Correct |
1393 ms |
262232 KB |
Output is correct |
6 |
Correct |
1452 ms |
217092 KB |
Output is correct |
7 |
Correct |
1448 ms |
261556 KB |
Output is correct |
8 |
Correct |
1084 ms |
279656 KB |
Output is correct |
9 |
Correct |
1158 ms |
279236 KB |
Output is correct |
10 |
Correct |
1296 ms |
295528 KB |
Output is correct |
11 |
Correct |
1331 ms |
238292 KB |
Output is correct |
12 |
Correct |
1458 ms |
221884 KB |
Output is correct |
13 |
Correct |
1149 ms |
279288 KB |
Output is correct |
14 |
Correct |
1136 ms |
278660 KB |
Output is correct |
15 |
Correct |
1130 ms |
278336 KB |
Output is correct |
16 |
Correct |
1135 ms |
278352 KB |
Output is correct |
17 |
Correct |
1503 ms |
271300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
34136 KB |
Output is correct |
2 |
Correct |
17 ms |
34044 KB |
Output is correct |
3 |
Correct |
14 ms |
34140 KB |
Output is correct |
4 |
Correct |
14 ms |
34212 KB |
Output is correct |
5 |
Correct |
16 ms |
34108 KB |
Output is correct |
6 |
Correct |
17 ms |
34136 KB |
Output is correct |
7 |
Correct |
14 ms |
34140 KB |
Output is correct |
8 |
Correct |
14 ms |
34136 KB |
Output is correct |
9 |
Correct |
17 ms |
34140 KB |
Output is correct |
10 |
Correct |
19 ms |
36952 KB |
Output is correct |
11 |
Correct |
18 ms |
36700 KB |
Output is correct |
12 |
Correct |
19 ms |
35928 KB |
Output is correct |
13 |
Correct |
20 ms |
36956 KB |
Output is correct |
14 |
Correct |
21 ms |
36700 KB |
Output is correct |
15 |
Correct |
20 ms |
36440 KB |
Output is correct |
16 |
Correct |
1448 ms |
163648 KB |
Output is correct |
17 |
Correct |
1122 ms |
279104 KB |
Output is correct |
18 |
Correct |
1197 ms |
284880 KB |
Output is correct |
19 |
Correct |
1310 ms |
273484 KB |
Output is correct |
20 |
Correct |
1393 ms |
262232 KB |
Output is correct |
21 |
Correct |
1452 ms |
217092 KB |
Output is correct |
22 |
Correct |
1448 ms |
261556 KB |
Output is correct |
23 |
Correct |
1084 ms |
279656 KB |
Output is correct |
24 |
Correct |
1158 ms |
279236 KB |
Output is correct |
25 |
Correct |
1296 ms |
295528 KB |
Output is correct |
26 |
Correct |
1331 ms |
238292 KB |
Output is correct |
27 |
Correct |
1458 ms |
221884 KB |
Output is correct |
28 |
Correct |
1149 ms |
279288 KB |
Output is correct |
29 |
Correct |
1136 ms |
278660 KB |
Output is correct |
30 |
Correct |
1130 ms |
278336 KB |
Output is correct |
31 |
Correct |
1135 ms |
278352 KB |
Output is correct |
32 |
Correct |
1503 ms |
271300 KB |
Output is correct |
33 |
Correct |
1497 ms |
198500 KB |
Output is correct |
34 |
Correct |
299 ms |
244816 KB |
Output is correct |
35 |
Correct |
1342 ms |
221840 KB |
Output is correct |
36 |
Correct |
1433 ms |
171408 KB |
Output is correct |
37 |
Correct |
1372 ms |
211488 KB |
Output is correct |
38 |
Correct |
1378 ms |
183236 KB |
Output is correct |
39 |
Correct |
1254 ms |
209020 KB |
Output is correct |
40 |
Correct |
1243 ms |
236432 KB |
Output is correct |
41 |
Correct |
1354 ms |
206732 KB |
Output is correct |
42 |
Correct |
1389 ms |
264360 KB |
Output is correct |
43 |
Correct |
1286 ms |
270632 KB |
Output is correct |
44 |
Correct |
1367 ms |
215924 KB |
Output is correct |
45 |
Correct |
1128 ms |
243360 KB |
Output is correct |
46 |
Correct |
1137 ms |
283700 KB |
Output is correct |
47 |
Correct |
1089 ms |
283128 KB |
Output is correct |
48 |
Correct |
1136 ms |
282940 KB |
Output is correct |
49 |
Correct |
1159 ms |
283196 KB |
Output is correct |
50 |
Correct |
1208 ms |
283456 KB |
Output is correct |
51 |
Correct |
1315 ms |
284992 KB |
Output is correct |
52 |
Correct |
1283 ms |
292464 KB |
Output is correct |