#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200000], V[200000];
pair<int,int> x[200000], y[200000];
int numx[200000], num_rev[200000], numy[200000], color[200000], tree[200001];
int find_(int a)
{
return color[a]=a==color[a] ? a:find_(color[a]);
}
void union_(int a, int b)
{
a=find_(a); b=find_(b);
if(V[a].size()<V[b].size()) swap(a,b);
color[b]=a;
for(auto v: V[b]) V[a].push_back(v);
V[b].clear();
}
void update(int n, int v)
{
for(++n;n<=200000;n+=n&-n) tree[n]+=v;
}
int get_cnt(int n)
{
int ret=0;
for(++n;n;n-=n&-n) ret+=tree[n];
return ret;
}
int get_cnt(pair<int,int> S)
{
return get_cnt(S.second)-get_cnt(S.first-1);
}
vector<int> check_validity(int N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R)
{
int M=X.size(), Q=S.size(), j=N-1, k;
vector<tuple<int,int,int>> temp(Q);
vector<int> ret(Q);
for(int i=0;i<M;i++) {
adj[X[i]].push_back(Y[i]);
adj[Y[i]].push_back(X[i]);
}
for(int i=0;i<Q;i++) temp[i]=make_tuple(L[i],S[i],i);
sort(temp.rbegin(),temp.rend());
for(int i=0;i<N;i++) {
V[i].resize(1);
color[V[i][0]=i]=i;
}
for(int i=0;i<Q;i++) {
int l, s, idx;
tie(l,s,idx)=temp[i];
for(;j>=l;j--) for(auto n: adj[j]) if(n>j && find_(j)!=find_(n)) union_(j,n);
s=find_(s);
x[idx]={V[s].front(),V[s].back()};
}
for(;j>=0;j--) for(auto n: adj[j]) if(n>j && find_(j)!=find_(n)) union_(j,n);
j=find_(0);
for(int i=0;i<N;i++) numx[num_rev[i]=V[j][i]]=i;
for(int i=0;i<Q;i++) temp[i]=make_tuple(R[i],E[i],i);
sort(temp.begin(),temp.end());
for(int i=0;i<N;i++) {
V[i].resize(1);
color[V[i][0]=i]=i;
}
for(int i=j=0;i<Q;i++) {
int r, e, idx;
tie(r,e,idx)=temp[i];
for(;j<=r;j++) for(auto n: adj[j]) if(n<j && find_(j)!=find_(n)) union_(j,n);
e=find_(e);
y[idx]={V[e].front(),V[e].back()};
}
for(;j<N;j++) for(auto n: adj[j]) if(n<j && find_(j)!=find_(n)) union_(j,n);
j=find_(0);
for(int i=0;i<N;i++) numy[V[j][i]]=i;
for(int i=0;i<Q;i++) {
L[i]=R[i]=i;
x[i].first=numx[x[i].first];
x[i].second=numx[x[i].second];
y[i].first=numy[y[i].first];
y[i].second=numy[y[i].second];
}
sort(L.begin(),L.end(),[&](int a, int b) {return x[a].first<x[b].first;});
sort(R.begin(),R.end(),[&](int a, int b) {return x[a].second<x[b].second;});
for(int i=j=k=0;i<N;i++) {
for(;j<Q && x[L[j]].first==i;j++) ret[L[j]]-=get_cnt(y[L[j]]);
update(numy[num_rev[i]],1);
for(;k<Q && x[R[k]].second==i;k++) ret[R[k]]+=get_cnt(y[R[k]]);
}
for(int i=0;i<Q;i++) ret[i]=ret[i]>0;
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9848 KB |
Output is correct |
2 |
Correct |
11 ms |
9764 KB |
Output is correct |
3 |
Correct |
11 ms |
9720 KB |
Output is correct |
4 |
Correct |
11 ms |
9816 KB |
Output is correct |
5 |
Correct |
11 ms |
9756 KB |
Output is correct |
6 |
Correct |
10 ms |
9848 KB |
Output is correct |
7 |
Correct |
11 ms |
9720 KB |
Output is correct |
8 |
Correct |
10 ms |
9720 KB |
Output is correct |
9 |
Correct |
11 ms |
9848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9848 KB |
Output is correct |
2 |
Correct |
11 ms |
9764 KB |
Output is correct |
3 |
Correct |
11 ms |
9720 KB |
Output is correct |
4 |
Correct |
11 ms |
9816 KB |
Output is correct |
5 |
Correct |
11 ms |
9756 KB |
Output is correct |
6 |
Correct |
10 ms |
9848 KB |
Output is correct |
7 |
Correct |
11 ms |
9720 KB |
Output is correct |
8 |
Correct |
10 ms |
9720 KB |
Output is correct |
9 |
Correct |
11 ms |
9848 KB |
Output is correct |
10 |
Correct |
17 ms |
10472 KB |
Output is correct |
11 |
Correct |
16 ms |
10488 KB |
Output is correct |
12 |
Correct |
16 ms |
10488 KB |
Output is correct |
13 |
Correct |
19 ms |
10488 KB |
Output is correct |
14 |
Correct |
15 ms |
10488 KB |
Output is correct |
15 |
Correct |
17 ms |
10488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
607 ms |
55932 KB |
Output is correct |
2 |
Correct |
496 ms |
54516 KB |
Output is correct |
3 |
Correct |
523 ms |
56044 KB |
Output is correct |
4 |
Correct |
546 ms |
58436 KB |
Output is correct |
5 |
Correct |
553 ms |
58988 KB |
Output is correct |
6 |
Correct |
597 ms |
60408 KB |
Output is correct |
7 |
Correct |
592 ms |
65272 KB |
Output is correct |
8 |
Correct |
484 ms |
54260 KB |
Output is correct |
9 |
Correct |
493 ms |
55980 KB |
Output is correct |
10 |
Correct |
505 ms |
58348 KB |
Output is correct |
11 |
Correct |
520 ms |
58764 KB |
Output is correct |
12 |
Correct |
534 ms |
60288 KB |
Output is correct |
13 |
Correct |
469 ms |
54004 KB |
Output is correct |
14 |
Correct |
478 ms |
54220 KB |
Output is correct |
15 |
Correct |
508 ms |
52860 KB |
Output is correct |
16 |
Correct |
476 ms |
53864 KB |
Output is correct |
17 |
Correct |
584 ms |
64684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
9848 KB |
Output is correct |
2 |
Correct |
11 ms |
9764 KB |
Output is correct |
3 |
Correct |
11 ms |
9720 KB |
Output is correct |
4 |
Correct |
11 ms |
9816 KB |
Output is correct |
5 |
Correct |
11 ms |
9756 KB |
Output is correct |
6 |
Correct |
10 ms |
9848 KB |
Output is correct |
7 |
Correct |
11 ms |
9720 KB |
Output is correct |
8 |
Correct |
10 ms |
9720 KB |
Output is correct |
9 |
Correct |
11 ms |
9848 KB |
Output is correct |
10 |
Correct |
17 ms |
10472 KB |
Output is correct |
11 |
Correct |
16 ms |
10488 KB |
Output is correct |
12 |
Correct |
16 ms |
10488 KB |
Output is correct |
13 |
Correct |
19 ms |
10488 KB |
Output is correct |
14 |
Correct |
15 ms |
10488 KB |
Output is correct |
15 |
Correct |
17 ms |
10488 KB |
Output is correct |
16 |
Correct |
607 ms |
55932 KB |
Output is correct |
17 |
Correct |
496 ms |
54516 KB |
Output is correct |
18 |
Correct |
523 ms |
56044 KB |
Output is correct |
19 |
Correct |
546 ms |
58436 KB |
Output is correct |
20 |
Correct |
553 ms |
58988 KB |
Output is correct |
21 |
Correct |
597 ms |
60408 KB |
Output is correct |
22 |
Correct |
592 ms |
65272 KB |
Output is correct |
23 |
Correct |
484 ms |
54260 KB |
Output is correct |
24 |
Correct |
493 ms |
55980 KB |
Output is correct |
25 |
Correct |
505 ms |
58348 KB |
Output is correct |
26 |
Correct |
520 ms |
58764 KB |
Output is correct |
27 |
Correct |
534 ms |
60288 KB |
Output is correct |
28 |
Correct |
469 ms |
54004 KB |
Output is correct |
29 |
Correct |
478 ms |
54220 KB |
Output is correct |
30 |
Correct |
508 ms |
52860 KB |
Output is correct |
31 |
Correct |
476 ms |
53864 KB |
Output is correct |
32 |
Correct |
584 ms |
64684 KB |
Output is correct |
33 |
Correct |
576 ms |
56340 KB |
Output is correct |
34 |
Correct |
394 ms |
46456 KB |
Output is correct |
35 |
Correct |
550 ms |
54920 KB |
Output is correct |
36 |
Correct |
623 ms |
57112 KB |
Output is correct |
37 |
Correct |
622 ms |
54852 KB |
Output is correct |
38 |
Correct |
611 ms |
56516 KB |
Output is correct |
39 |
Correct |
643 ms |
55168 KB |
Output is correct |
40 |
Correct |
828 ms |
62280 KB |
Output is correct |
41 |
Correct |
580 ms |
55104 KB |
Output is correct |
42 |
Correct |
638 ms |
57160 KB |
Output is correct |
43 |
Correct |
649 ms |
57452 KB |
Output is correct |
44 |
Correct |
574 ms |
54904 KB |
Output is correct |
45 |
Correct |
513 ms |
54536 KB |
Output is correct |
46 |
Correct |
521 ms |
55412 KB |
Output is correct |
47 |
Correct |
482 ms |
53992 KB |
Output is correct |
48 |
Correct |
513 ms |
53644 KB |
Output is correct |
49 |
Correct |
499 ms |
54244 KB |
Output is correct |
50 |
Correct |
601 ms |
53868 KB |
Output is correct |
51 |
Correct |
653 ms |
62100 KB |
Output is correct |
52 |
Correct |
662 ms |
62280 KB |
Output is correct |