#include "werewolf.h"
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
const int MAXN = 4e5+10;
vector<int> eL[MAXN];
vector<int> eR[MAXN];
vector<pii> queryL[MAXN];
vector<pii> queryR[MAXN];
vector<int> add[MAXN];
vector<pii> query[MAXN];
vector<int> qid[MAXN];
vector<vector<int> > graphL;
vector<vector<int> > graphR;
int Lv[MAXN];
int Rv[MAXN];
int par[MAXN];
int id[MAXN];
int inL[MAXN];
int outL[MAXN];
int inR[MAXN];
int outR[MAXN];
int cal[MAXN];
int tree[MAXN*4];
int seq;
int root(int x){
if(par[x]==x)return x;
return par[x] = root(par[x]);
}
void dfsL(int here){
inL[here] = seq;
seq++;
for(int i=0;i<(int)graphL[here].size();i++){
dfsL(graphL[here][i]);
}
outL[here] = seq-1;
return;
}
void dfsR(int here){
inR[here] = seq;
seq++;
for(int i=0;i<(int)graphR[here].size();i++){
dfsR(graphR[here][i]);
}
outR[here] = seq-1;
return;
}
inline void update(int tmp){
while(tmp){
tree[tmp]++;
tmp>>=1;
}
}
inline int getans(int L,int R){
int res = 0;
while(L<=R){
if(L&1){
res += tree[L];
L++;
}
if(!(R&1)){
res += tree[R];
R--;
}
L>>=1; R>>=1;
}
return res;
}
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 = (int)X.size();
int Q = (int)L.size();
int x,y;
for(int i=0;i<M;i++){
x = X[i];
y = Y[i];
if(x>y)swap(x,y);
eR[x].push_back(y);
eL[y].push_back(x);
}
for(int i=0;i<Q;i++){
queryL[R[i]].push_back(pii(E[i],i));
queryR[L[i]].push_back(pii(S[i],i));
}
int NN = (N<<1);
graphL = vector<vector<int> > (NN);
graphR = vector<vector<int> > (NN);
int num = N-1;
for(int i=0;i<N;i++){
par[i] = i;
id[i] = i;
}
int cur,idx;
int curid;
for(int i=0;i<N;i++){
for(int j=0;j<(int)eL[i].size();j++){
curid = root(eL[i][j]);
if(curid^i){
par[curid] = i;
num++;
graphL[num].push_back(id[i]);
graphL[num].push_back(id[curid]);
id[i] = num;
}
}
for(int j=0;j<(int)queryL[i].size();j++){
cur = queryL[i][j].f;
idx = queryL[i][j].s;
cur = root(cur);
Lv[idx] = id[cur];
}
}
num = N-1;
for(int i=0;i<N;i++){
par[i] = i;
id[i] = i;
}
for(int i=N-1;i>=0;i--){
for(int j=0;j<(int)eR[i].size();j++){
curid = root(eR[i][j]);
if(curid^i){
par[curid] = i;
num++;
graphR[num].push_back(id[i]);
graphR[num].push_back(id[curid]);
id[i] = num;
}
}
for(int j=0;j<(int)queryR[i].size();j++){
cur = queryR[i][j].f;
idx = queryR[i][j].s;
cur = root(cur);
Rv[idx] = id[cur];
}
}
seq = 0;
dfsL(((N-1)<<1));
seq = 0;
dfsR(((N-1)<<1));
int la,ra,lb,rb;
for(int i=0;i<Q;i++){
la = inL[Lv[i]];
ra = outL[Lv[i]];
lb = inR[Rv[i]];
rb = outR[Rv[i]];
if(la){
query[la-1].push_back(pii(lb,rb));
qid[la-1].push_back((i<<1));
}
query[ra].push_back(pii(lb,rb));
qid[ra].push_back((i<<1)|1);
}
for(int i=0;i<N;i++){
add[inL[i]].push_back(inR[i]);
}
int base = 1;
for(;base<NN;base<<=1);
int sz = 0;
for(int i=0;i<NN;i++){
sz = (int)add[i].size();
for(int j=0;j<sz;j++){
update(base+add[i][j]);
}
sz = (int)query[i].size();
for(int j=0;j<sz;j++){
idx = qid[i][j];
cur = getans(base+query[i][j].f,base+query[i][j].s);
if(idx&1){
cal[(idx>>1)]+=cur;
}
else {
cal[(idx>>1)]-=cur;
}
}
}
vector<int> ans;
ans = vector<int> (Q);
for(int i=0;i<Q;i++){
if(cal[i])ans[i] = 1;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
66148 KB |
Output is correct |
2 |
Correct |
39 ms |
66148 KB |
Output is correct |
3 |
Correct |
44 ms |
66032 KB |
Output is correct |
4 |
Correct |
40 ms |
66092 KB |
Output is correct |
5 |
Correct |
39 ms |
66064 KB |
Output is correct |
6 |
Correct |
39 ms |
66112 KB |
Output is correct |
7 |
Correct |
41 ms |
66152 KB |
Output is correct |
8 |
Correct |
39 ms |
66140 KB |
Output is correct |
9 |
Correct |
41 ms |
66100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
66148 KB |
Output is correct |
2 |
Correct |
39 ms |
66148 KB |
Output is correct |
3 |
Correct |
44 ms |
66032 KB |
Output is correct |
4 |
Correct |
40 ms |
66092 KB |
Output is correct |
5 |
Correct |
39 ms |
66064 KB |
Output is correct |
6 |
Correct |
39 ms |
66112 KB |
Output is correct |
7 |
Correct |
41 ms |
66152 KB |
Output is correct |
8 |
Correct |
39 ms |
66140 KB |
Output is correct |
9 |
Correct |
41 ms |
66100 KB |
Output is correct |
10 |
Correct |
46 ms |
67524 KB |
Output is correct |
11 |
Correct |
45 ms |
67560 KB |
Output is correct |
12 |
Correct |
45 ms |
67420 KB |
Output is correct |
13 |
Correct |
48 ms |
67672 KB |
Output is correct |
14 |
Correct |
46 ms |
67660 KB |
Output is correct |
15 |
Correct |
46 ms |
67556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
844 ms |
153800 KB |
Output is correct |
2 |
Correct |
744 ms |
157084 KB |
Output is correct |
3 |
Correct |
715 ms |
152756 KB |
Output is correct |
4 |
Correct |
710 ms |
151352 KB |
Output is correct |
5 |
Correct |
700 ms |
151484 KB |
Output is correct |
6 |
Correct |
747 ms |
152840 KB |
Output is correct |
7 |
Correct |
686 ms |
148740 KB |
Output is correct |
8 |
Correct |
706 ms |
157024 KB |
Output is correct |
9 |
Correct |
692 ms |
151492 KB |
Output is correct |
10 |
Correct |
642 ms |
148172 KB |
Output is correct |
11 |
Correct |
617 ms |
149640 KB |
Output is correct |
12 |
Correct |
660 ms |
149680 KB |
Output is correct |
13 |
Correct |
733 ms |
161276 KB |
Output is correct |
14 |
Correct |
747 ms |
161196 KB |
Output is correct |
15 |
Correct |
772 ms |
161040 KB |
Output is correct |
16 |
Correct |
732 ms |
161148 KB |
Output is correct |
17 |
Correct |
707 ms |
148536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
66148 KB |
Output is correct |
2 |
Correct |
39 ms |
66148 KB |
Output is correct |
3 |
Correct |
44 ms |
66032 KB |
Output is correct |
4 |
Correct |
40 ms |
66092 KB |
Output is correct |
5 |
Correct |
39 ms |
66064 KB |
Output is correct |
6 |
Correct |
39 ms |
66112 KB |
Output is correct |
7 |
Correct |
41 ms |
66152 KB |
Output is correct |
8 |
Correct |
39 ms |
66140 KB |
Output is correct |
9 |
Correct |
41 ms |
66100 KB |
Output is correct |
10 |
Correct |
46 ms |
67524 KB |
Output is correct |
11 |
Correct |
45 ms |
67560 KB |
Output is correct |
12 |
Correct |
45 ms |
67420 KB |
Output is correct |
13 |
Correct |
48 ms |
67672 KB |
Output is correct |
14 |
Correct |
46 ms |
67660 KB |
Output is correct |
15 |
Correct |
46 ms |
67556 KB |
Output is correct |
16 |
Correct |
844 ms |
153800 KB |
Output is correct |
17 |
Correct |
744 ms |
157084 KB |
Output is correct |
18 |
Correct |
715 ms |
152756 KB |
Output is correct |
19 |
Correct |
710 ms |
151352 KB |
Output is correct |
20 |
Correct |
700 ms |
151484 KB |
Output is correct |
21 |
Correct |
747 ms |
152840 KB |
Output is correct |
22 |
Correct |
686 ms |
148740 KB |
Output is correct |
23 |
Correct |
706 ms |
157024 KB |
Output is correct |
24 |
Correct |
692 ms |
151492 KB |
Output is correct |
25 |
Correct |
642 ms |
148172 KB |
Output is correct |
26 |
Correct |
617 ms |
149640 KB |
Output is correct |
27 |
Correct |
660 ms |
149680 KB |
Output is correct |
28 |
Correct |
733 ms |
161276 KB |
Output is correct |
29 |
Correct |
747 ms |
161196 KB |
Output is correct |
30 |
Correct |
772 ms |
161040 KB |
Output is correct |
31 |
Correct |
732 ms |
161148 KB |
Output is correct |
32 |
Correct |
707 ms |
148536 KB |
Output is correct |
33 |
Correct |
884 ms |
154444 KB |
Output is correct |
34 |
Correct |
352 ms |
97536 KB |
Output is correct |
35 |
Correct |
875 ms |
157584 KB |
Output is correct |
36 |
Correct |
871 ms |
154412 KB |
Output is correct |
37 |
Correct |
875 ms |
156796 KB |
Output is correct |
38 |
Correct |
849 ms |
154880 KB |
Output is correct |
39 |
Correct |
708 ms |
162984 KB |
Output is correct |
40 |
Correct |
770 ms |
155484 KB |
Output is correct |
41 |
Correct |
733 ms |
153064 KB |
Output is correct |
42 |
Correct |
668 ms |
149096 KB |
Output is correct |
43 |
Correct |
877 ms |
160008 KB |
Output is correct |
44 |
Correct |
757 ms |
154316 KB |
Output is correct |
45 |
Correct |
708 ms |
163372 KB |
Output is correct |
46 |
Correct |
720 ms |
163228 KB |
Output is correct |
47 |
Correct |
718 ms |
160884 KB |
Output is correct |
48 |
Correct |
717 ms |
160736 KB |
Output is correct |
49 |
Correct |
735 ms |
160800 KB |
Output is correct |
50 |
Correct |
737 ms |
160648 KB |
Output is correct |
51 |
Correct |
725 ms |
153064 KB |
Output is correct |
52 |
Correct |
751 ms |
152984 KB |
Output is correct |