#include<bits/stdc++.h>
#include "werewolf.h"
using namespace std;
const int nax = 2e5 + 10;
int rep1[nax], rep2[nax];
pair<int,int> x_co[nax * 2], y_co[nax * 2];
int tt;
int cnt[nax];
struct DSU {
int par[nax], sz[nax];
DSU() {
for(int i=0; i<nax; ++i) {
sz[i] = 1, par[i] = i;
}
}
int find(int v) {
return par[v] = (par[v]==v) ? v : find(par[v]);
}
void unite(int u, int v) {
if(sz[u] < sz[v]) swap(u, v);
par[v] = u;
sz[u] += sz[v];
}
bool same(int u, int v) {
return find(u) == find(v);
}
};
struct KRT {
DSU T;
vector<int>tree[nax * 2];
int N;
int r[nax];
KRT() {
for(int i=0; i<nax; ++i) {
r[i] = i;
}
}
void add_edge(int u, int v) {
if(T.same(u, v)) return;
u = T.find(u), v = T.find(v);
tree[N].push_back(r[u]);
tree[N].push_back(r[v]);
T.unite(u, v);
r[T.find(u)] = N++;
}
int get_rep(int v) {
return r[T.find(v)];
}
} krt1, krt2;
struct BIT {
int bit[nax];
void add(int p) {
while(p<nax) {
bit[p]++;
p += p & -p;
}
}
int get(int p) {
int ret = 0;
while(p) {
ret += bit[p];
p -= p & -p;
}
return ret;
}
int get(int l, int r) {
int ret = get(r);
if(l) ret -= get(l-1);
return ret;
}
};
void DFS(int v, KRT *krt, pair<int,int> *co, int N) {
co[v].first = tt;
tt += v < N;
for(int u : krt->tree[v]) {
DFS(u, krt, co, N);
}
co[v].second = tt-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 Q = S.size();
int M = X.size();
vector<pair<int,int>>edges;
for(int i=0; i<M; ++i) {
edges.emplace_back(X[i], Y[i]);
}
//build KRT1
krt1.N = N;
sort(edges.begin(), edges.end(), [&] (auto x, auto y) {
return min(x.first, x.second) > min(y.first, y.second);
});
vector<int>whosL[nax];
for(int i=0; i<Q; ++i) {
whosL[L[i]].push_back(i);
}
for(int i=0; i<Q; ++i) {
rep1[i] = S[i];
}
int at = 0;
for(int i=N-1; i>=0; --i) {
if(at < M && min(edges[at].first, edges[at].second)==i) {
krt1.add_edge(edges[at].first, edges[at].second);
++at;
++i;
continue;
}
for(int j : whosL[i]) {
rep1[j] = krt1.get_rep(S[j]);
}
}
//build KRT2
krt2.N = N;
sort(edges.begin(), edges.end(), [&] (auto x, auto y) {
return max(x.first, x.second) < max(y.first, y.second);
});
vector<int>whosR[nax];
for(int i=0; i<Q; ++i) {
whosR[R[i]].push_back(i);
}
for(int i=0; i<Q; ++i) {
rep2[i] = E[i];
}
at = 0;
for(int i=0; i<N; ++i) {
if(at < M && max(edges[at].first, edges[at].second)==i) {
krt2.add_edge(edges[at].first, edges[at].second);
++at;
--i;
continue;
}
for(int j : whosR[i]) {
rep2[j] = krt2.get_rep(E[j]);
}
}
//rename nodes in KRT1
tt = 0;
DFS(krt1.N-1, &krt1, x_co, N);
//rename nodes in KRT2
tt = 0;
DFS(krt2.N-1, &krt2, y_co, N);
//get all points
vector<int>x_to_y[nax];
for(int i=0; i<N; ++i) {
x_to_y[x_co[i].first].push_back(y_co[i].first);
}
vector<int>left_queries[nax], right_queries[nax];
for(int i=0; i<Q; ++i) {
left_queries[x_co[rep1[i]].first].push_back(i);
right_queries[x_co[rep1[i]].second].push_back(i);
}
//sweep line
BIT b;
for(int i=0; i<N; ++i) {
//handle left side of queries
for(int j : left_queries[i]) {
cnt[j] -= b.get(y_co[rep2[j]].first+1, y_co[rep2[j]].second+1);
}
//add points
for(int y : x_to_y[i]) {
b.add(y+1);
}
//handle right side of queries
for(int j : right_queries[i]) {
cnt[j] += b.get(y_co[rep2[j]].first+1, y_co[rep2[j]].second+1);
}
}
//conclusion
vector<int>ans(Q);
for(int i=0; i<Q; ++i) {
ans[i] = cnt[i] > 0;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
48084 KB |
Output is correct |
2 |
Correct |
29 ms |
48112 KB |
Output is correct |
3 |
Correct |
27 ms |
48056 KB |
Output is correct |
4 |
Correct |
27 ms |
48084 KB |
Output is correct |
5 |
Correct |
28 ms |
47980 KB |
Output is correct |
6 |
Correct |
26 ms |
48104 KB |
Output is correct |
7 |
Correct |
26 ms |
48212 KB |
Output is correct |
8 |
Correct |
28 ms |
48104 KB |
Output is correct |
9 |
Correct |
26 ms |
48084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
48084 KB |
Output is correct |
2 |
Correct |
29 ms |
48112 KB |
Output is correct |
3 |
Correct |
27 ms |
48056 KB |
Output is correct |
4 |
Correct |
27 ms |
48084 KB |
Output is correct |
5 |
Correct |
28 ms |
47980 KB |
Output is correct |
6 |
Correct |
26 ms |
48104 KB |
Output is correct |
7 |
Correct |
26 ms |
48212 KB |
Output is correct |
8 |
Correct |
28 ms |
48104 KB |
Output is correct |
9 |
Correct |
26 ms |
48084 KB |
Output is correct |
10 |
Correct |
33 ms |
49024 KB |
Output is correct |
11 |
Correct |
33 ms |
49016 KB |
Output is correct |
12 |
Correct |
38 ms |
48824 KB |
Output is correct |
13 |
Correct |
34 ms |
49056 KB |
Output is correct |
14 |
Correct |
31 ms |
49108 KB |
Output is correct |
15 |
Correct |
32 ms |
48972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
605 ms |
98000 KB |
Output is correct |
2 |
Correct |
424 ms |
102472 KB |
Output is correct |
3 |
Correct |
411 ms |
106568 KB |
Output is correct |
4 |
Correct |
431 ms |
105036 KB |
Output is correct |
5 |
Correct |
445 ms |
105176 KB |
Output is correct |
6 |
Correct |
495 ms |
105916 KB |
Output is correct |
7 |
Correct |
479 ms |
102756 KB |
Output is correct |
8 |
Correct |
390 ms |
110780 KB |
Output is correct |
9 |
Correct |
368 ms |
105128 KB |
Output is correct |
10 |
Correct |
407 ms |
103116 KB |
Output is correct |
11 |
Correct |
388 ms |
103224 KB |
Output is correct |
12 |
Correct |
443 ms |
103716 KB |
Output is correct |
13 |
Correct |
440 ms |
112452 KB |
Output is correct |
14 |
Correct |
408 ms |
112436 KB |
Output is correct |
15 |
Correct |
412 ms |
112472 KB |
Output is correct |
16 |
Correct |
420 ms |
112440 KB |
Output is correct |
17 |
Correct |
441 ms |
102696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
48084 KB |
Output is correct |
2 |
Correct |
29 ms |
48112 KB |
Output is correct |
3 |
Correct |
27 ms |
48056 KB |
Output is correct |
4 |
Correct |
27 ms |
48084 KB |
Output is correct |
5 |
Correct |
28 ms |
47980 KB |
Output is correct |
6 |
Correct |
26 ms |
48104 KB |
Output is correct |
7 |
Correct |
26 ms |
48212 KB |
Output is correct |
8 |
Correct |
28 ms |
48104 KB |
Output is correct |
9 |
Correct |
26 ms |
48084 KB |
Output is correct |
10 |
Correct |
33 ms |
49024 KB |
Output is correct |
11 |
Correct |
33 ms |
49016 KB |
Output is correct |
12 |
Correct |
38 ms |
48824 KB |
Output is correct |
13 |
Correct |
34 ms |
49056 KB |
Output is correct |
14 |
Correct |
31 ms |
49108 KB |
Output is correct |
15 |
Correct |
32 ms |
48972 KB |
Output is correct |
16 |
Correct |
605 ms |
98000 KB |
Output is correct |
17 |
Correct |
424 ms |
102472 KB |
Output is correct |
18 |
Correct |
411 ms |
106568 KB |
Output is correct |
19 |
Correct |
431 ms |
105036 KB |
Output is correct |
20 |
Correct |
445 ms |
105176 KB |
Output is correct |
21 |
Correct |
495 ms |
105916 KB |
Output is correct |
22 |
Correct |
479 ms |
102756 KB |
Output is correct |
23 |
Correct |
390 ms |
110780 KB |
Output is correct |
24 |
Correct |
368 ms |
105128 KB |
Output is correct |
25 |
Correct |
407 ms |
103116 KB |
Output is correct |
26 |
Correct |
388 ms |
103224 KB |
Output is correct |
27 |
Correct |
443 ms |
103716 KB |
Output is correct |
28 |
Correct |
440 ms |
112452 KB |
Output is correct |
29 |
Correct |
408 ms |
112436 KB |
Output is correct |
30 |
Correct |
412 ms |
112472 KB |
Output is correct |
31 |
Correct |
420 ms |
112440 KB |
Output is correct |
32 |
Correct |
441 ms |
102696 KB |
Output is correct |
33 |
Correct |
558 ms |
108380 KB |
Output is correct |
34 |
Correct |
305 ms |
83424 KB |
Output is correct |
35 |
Correct |
578 ms |
112592 KB |
Output is correct |
36 |
Correct |
633 ms |
107640 KB |
Output is correct |
37 |
Correct |
535 ms |
111504 KB |
Output is correct |
38 |
Correct |
553 ms |
108496 KB |
Output is correct |
39 |
Correct |
566 ms |
119700 KB |
Output is correct |
40 |
Correct |
498 ms |
113884 KB |
Output is correct |
41 |
Correct |
508 ms |
108700 KB |
Output is correct |
42 |
Correct |
447 ms |
103848 KB |
Output is correct |
43 |
Correct |
536 ms |
116276 KB |
Output is correct |
44 |
Correct |
513 ms |
109756 KB |
Output is correct |
45 |
Correct |
438 ms |
115772 KB |
Output is correct |
46 |
Correct |
456 ms |
115652 KB |
Output is correct |
47 |
Correct |
458 ms |
112644 KB |
Output is correct |
48 |
Correct |
478 ms |
112440 KB |
Output is correct |
49 |
Correct |
473 ms |
112548 KB |
Output is correct |
50 |
Correct |
454 ms |
112428 KB |
Output is correct |
51 |
Correct |
443 ms |
111372 KB |
Output is correct |
52 |
Correct |
456 ms |
111244 KB |
Output is correct |