#include <bits/stdc++.h>
#include "werewolf.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int N, M, Q;
int P[404040], NL[404040], NR[404040], num;
int H[202020], W[202020];
int HS[202020], HE[202020];
int WS[202020], WE[202020];
vector<int> ans, C[404040];
vector<pii> Point;
struct Data{
int t, u, v, w;
};
vector<Data> A;
int Find(int u){
if (u == P[u]) return u;
return P[u] = Find(P[u]);
}
void Union(int u, int v){
int pu = Find(u);
int pv = Find(v);
if (pu == pv) return;
P[pu] = P[pv] = num;
NL[num] = NL[pu];
NR[num] = NR[pv];
C[num].push_back(pu);
C[num].push_back(pv);
num++;
}
void dfsH(int u){
if (C[u].empty()){
H[u] = num++;
return;
}
dfsH(C[u][0]);
dfsH(C[u][1]);
C[u].clear();
}
void dfsW(int u){
if (C[u].empty()){
W[u] = num++;
return;
}
dfsW(C[u][0]);
dfsW(C[u][1]);
C[u].clear();
}
struct Node{
Node *lc, *rc;
int val;
Node();
} *PST[202020], *NIL;
Node :: Node(){
lc = NIL, rc = NIL;
val = 0;
}
void update(Node* pre, Node* now, int s, int e, int t){
now->val = pre->val + 1;
if (s == e) return;
int mid = (s+e)/2;
if (t <= mid){
now->lc = new Node();
update(pre->lc, now->lc, s, mid, t);
now->rc = pre->rc;
}
else{
now->lc = pre->lc;
now->rc = new Node();
update(pre->rc, now->rc, mid+1, e, t);
}
}
int query(Node* now, int s, int e, int ts, int te){
if (e < ts || te < s) return 0;
if (ts <= s && e <= te) return now->val;
int mid = (s+e)/2;
return query(now->lc, s, mid, ts, te) + query(now->rc, mid+1, e, ts, te);
}
vector<int> check_validity(int n, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) {
N = n, M = X.size(), Q = S.size();
for (int i=0; i<M; i++) A.push_back((Data){0, X[i], Y[i], min(X[i], Y[i])});
for (int i=0; i<Q; i++) A.push_back((Data){1, S[i], i, L[i]});
sort(A.begin(), A.end(), [&](Data a, Data b){
if (a.w == b.w) return a.t < b.t;
return a.w > b.w;
});
num = N+1;
for (int i=0; i<=2*N; i++) P[i] = i, NL[i] = NR[i] = i;
for (int i=0; i<(int)A.size(); i++){
if (A[i].t == 0) Union(A[i].u, A[i].v);
else {
HS[A[i].v] = NL[Find(A[i].u)];
HE[A[i].v] = NR[Find(A[i].u)];
}
}
num=0;
dfsH(2*N-1);
A.clear();
for (int i=0; i<M; i++) A.push_back((Data){0, X[i], Y[i], max(X[i], Y[i])});
for (int i=0; i<Q; i++) A.push_back((Data){1, E[i], i, R[i]});
sort(A.begin(), A.end(), [&](Data a, Data b){
if (a.w == b.w) return a.t < b.t;
return a.w < b.w;
});
num = N+1;
for (int i=0; i<=2*N; i++) P[i] = i, NL[i] = NR[i] = i;
for (int i=0; i<(int)A.size(); i++){
if (A[i].t == 0) Union(A[i].u, A[i].v);
else {
WS[A[i].v] = NL[Find(A[i].u)];
WE[A[i].v] = NR[Find(A[i].u)];
}
}
num=0;
dfsW(2*N-1);
A.clear();
for (int i=0; i<Q; i++){
HS[i] = H[HS[i]], HE[i] = H[HE[i]];
WS[i] = W[WS[i]], WE[i] = W[WE[i]];
}
for (int i=0; i<N; i++) Point.push_back(pii(H[i], W[i]));
sort(Point.begin(), Point.end());
NIL = new Node();
NIL->lc = NIL->rc = NIL;
PST[0] = new Node;
for (int i=1; i<=N; i++) {
PST[i] = new Node;
update(PST[i-1], PST[i], 0, N, Point[i-1].second);
}
for (int i=0; i<Q; i++){
if (query(PST[HE[i]+1], 0, N, WS[i], WE[i]) - query(PST[HS[i]], 0, N, WS[i], WE[i])) ans.push_back(1);
else ans.push_back(0);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9984 KB |
Output is correct |
2 |
Correct |
9 ms |
9984 KB |
Output is correct |
3 |
Correct |
9 ms |
9856 KB |
Output is correct |
4 |
Correct |
9 ms |
9856 KB |
Output is correct |
5 |
Correct |
9 ms |
9856 KB |
Output is correct |
6 |
Correct |
9 ms |
9856 KB |
Output is correct |
7 |
Correct |
10 ms |
9984 KB |
Output is correct |
8 |
Correct |
9 ms |
9856 KB |
Output is correct |
9 |
Correct |
9 ms |
9856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9984 KB |
Output is correct |
2 |
Correct |
9 ms |
9984 KB |
Output is correct |
3 |
Correct |
9 ms |
9856 KB |
Output is correct |
4 |
Correct |
9 ms |
9856 KB |
Output is correct |
5 |
Correct |
9 ms |
9856 KB |
Output is correct |
6 |
Correct |
9 ms |
9856 KB |
Output is correct |
7 |
Correct |
10 ms |
9984 KB |
Output is correct |
8 |
Correct |
9 ms |
9856 KB |
Output is correct |
9 |
Correct |
9 ms |
9856 KB |
Output is correct |
10 |
Correct |
18 ms |
11648 KB |
Output is correct |
11 |
Correct |
17 ms |
11648 KB |
Output is correct |
12 |
Correct |
17 ms |
11648 KB |
Output is correct |
13 |
Correct |
19 ms |
11776 KB |
Output is correct |
14 |
Correct |
18 ms |
11776 KB |
Output is correct |
15 |
Correct |
18 ms |
11772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
959 ms |
163272 KB |
Output is correct |
2 |
Correct |
1006 ms |
174732 KB |
Output is correct |
3 |
Correct |
881 ms |
172740 KB |
Output is correct |
4 |
Correct |
859 ms |
171780 KB |
Output is correct |
5 |
Correct |
870 ms |
171768 KB |
Output is correct |
6 |
Correct |
1365 ms |
171536 KB |
Output is correct |
7 |
Correct |
807 ms |
171604 KB |
Output is correct |
8 |
Correct |
994 ms |
174664 KB |
Output is correct |
9 |
Correct |
771 ms |
172728 KB |
Output is correct |
10 |
Correct |
690 ms |
171932 KB |
Output is correct |
11 |
Correct |
727 ms |
171692 KB |
Output is correct |
12 |
Correct |
750 ms |
171732 KB |
Output is correct |
13 |
Correct |
996 ms |
174624 KB |
Output is correct |
14 |
Correct |
1055 ms |
174748 KB |
Output is correct |
15 |
Correct |
1083 ms |
174668 KB |
Output is correct |
16 |
Correct |
1054 ms |
174700 KB |
Output is correct |
17 |
Correct |
822 ms |
171608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
9984 KB |
Output is correct |
2 |
Correct |
9 ms |
9984 KB |
Output is correct |
3 |
Correct |
9 ms |
9856 KB |
Output is correct |
4 |
Correct |
9 ms |
9856 KB |
Output is correct |
5 |
Correct |
9 ms |
9856 KB |
Output is correct |
6 |
Correct |
9 ms |
9856 KB |
Output is correct |
7 |
Correct |
10 ms |
9984 KB |
Output is correct |
8 |
Correct |
9 ms |
9856 KB |
Output is correct |
9 |
Correct |
9 ms |
9856 KB |
Output is correct |
10 |
Correct |
18 ms |
11648 KB |
Output is correct |
11 |
Correct |
17 ms |
11648 KB |
Output is correct |
12 |
Correct |
17 ms |
11648 KB |
Output is correct |
13 |
Correct |
19 ms |
11776 KB |
Output is correct |
14 |
Correct |
18 ms |
11776 KB |
Output is correct |
15 |
Correct |
18 ms |
11772 KB |
Output is correct |
16 |
Correct |
959 ms |
163272 KB |
Output is correct |
17 |
Correct |
1006 ms |
174732 KB |
Output is correct |
18 |
Correct |
881 ms |
172740 KB |
Output is correct |
19 |
Correct |
859 ms |
171780 KB |
Output is correct |
20 |
Correct |
870 ms |
171768 KB |
Output is correct |
21 |
Correct |
1365 ms |
171536 KB |
Output is correct |
22 |
Correct |
807 ms |
171604 KB |
Output is correct |
23 |
Correct |
994 ms |
174664 KB |
Output is correct |
24 |
Correct |
771 ms |
172728 KB |
Output is correct |
25 |
Correct |
690 ms |
171932 KB |
Output is correct |
26 |
Correct |
727 ms |
171692 KB |
Output is correct |
27 |
Correct |
750 ms |
171732 KB |
Output is correct |
28 |
Correct |
996 ms |
174624 KB |
Output is correct |
29 |
Correct |
1055 ms |
174748 KB |
Output is correct |
30 |
Correct |
1083 ms |
174668 KB |
Output is correct |
31 |
Correct |
1054 ms |
174700 KB |
Output is correct |
32 |
Correct |
822 ms |
171608 KB |
Output is correct |
33 |
Correct |
1365 ms |
172348 KB |
Output is correct |
34 |
Correct |
486 ms |
50512 KB |
Output is correct |
35 |
Correct |
1763 ms |
175176 KB |
Output is correct |
36 |
Correct |
1369 ms |
172404 KB |
Output is correct |
37 |
Correct |
1668 ms |
174268 KB |
Output is correct |
38 |
Correct |
1452 ms |
172944 KB |
Output is correct |
39 |
Correct |
1683 ms |
177848 KB |
Output is correct |
40 |
Correct |
1074 ms |
182636 KB |
Output is correct |
41 |
Correct |
1371 ms |
173808 KB |
Output is correct |
42 |
Correct |
807 ms |
172272 KB |
Output is correct |
43 |
Correct |
1985 ms |
179660 KB |
Output is correct |
44 |
Correct |
1580 ms |
174224 KB |
Output is correct |
45 |
Correct |
1215 ms |
178372 KB |
Output is correct |
46 |
Correct |
1626 ms |
178144 KB |
Output is correct |
47 |
Correct |
1022 ms |
175000 KB |
Output is correct |
48 |
Correct |
1014 ms |
174804 KB |
Output is correct |
49 |
Correct |
965 ms |
174980 KB |
Output is correct |
50 |
Correct |
1050 ms |
174916 KB |
Output is correct |
51 |
Correct |
964 ms |
182828 KB |
Output is correct |
52 |
Correct |
969 ms |
182724 KB |
Output is correct |