#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
struct ST{
vector<int> t;
int n;
ST(int ns){
n = ns;
t.resize(4 * n);
}
int get(int v, int tl, int tr, int& l, int& r){
if (l > tr || r < tl) return 0;
if (l <= tl && tr <= r) return t[v];
int tm = (tl + tr) / 2, vv = 2 * v;
return max(get(vv, tl, tm, l, r), get(vv + 1, tm + 1, tr, l, r));
}
int get(int l, int r){
return get(1, 1, n, l, r);
}
void upd(int v, int tl, int tr, int& p, int& k){
if (tl == tr){
t[v] = k;
return;
}
int tm = (tl + tr) / 2, vv = 2 * v;
if (p <= tm){
upd(vv, tl, tm, p, k);
}
else {
upd(vv + 1, tm + 1, tr, p, k);
}
t[v] = max(t[vv], t[vv + 1]);
}
void upd(int x, int y){
upd(1, 1, n, x, y);
}
};
struct dsu{
vector<vector<int>> g;
vector<int> p;
int n;
dsu(int ns){
n = ns;
p.resize(n + 1);
for (int i = 1; i <= n; i++){
p[i] = i;
}
tin.resize(n + 1);
tout.resize(n + 1);
g.resize(n + 1);
}
int get(int v){
if (p[v] != v){
p[v] = get(p[v]);
}
return p[v];
}
void unite(int x, int y){
x = get(x); y = get(y);
if (x == y) return;
p[y] = x;
g[x].pb(y);
}
vector<int> all = {0}, tin, tout;
int timer = 0;
void dfs(int v, int pr){
all.pb(v);
tin[v] = ++timer;
for (int i: g[v]){
if (i == pr) continue;
dfs(i, v);
}
tout[v] = timer;
}
};
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 = (int) x.size(), q = (int) s.size();
vector<int> g[n + 1];
for (int i = 0; i < m; i++){
x[i]++; y[i]++;
g[x[i]].pb(y[i]);
g[y[i]].pb(x[i]);
}
for (int i = 0; i < q; i++){
s[i]++; e[i]++;
l[i]++; r[i]++;
}
vector<int> d[n + 1], p1(q);
for (int i = 0; i < q; i++){
d[l[i]].pb(i);
}
dsu T1(n);
for (int i = n; i > 0; i--){
for (int j: g[i]){
if (j > i){
T1.unite(i, j);
}
}
for (int j: d[i]){
p1[j] = T1.get(s[j]);
}
}
for (int i = 1; i <= n; i++) d[i].clear();
for (int i = 0; i < q; i++){
d[r[i]].pb(i);
}
vector<int> p2(q);
dsu T2(n);
for (int i = 1; i <= n; i++){
for (int j: g[i]){
if (j < i){
T2.unite(i, j);
}
}
for (int j: d[i]){
p2[j] = T2.get(e[j]);
}
}
T1.dfs(1, 0);
T2.dfs(n, 0);
// Точки
vector<int> u(n + 1), v(n + 1);
for (int i = 1; i <= n; i++){
u[T1.all[i]] = i;
v[T2.all[i]] = i;
}
vector<int> st[n + 1];
for (int i = 1; i <= n; i++){
st[u[i]].pb(v[i]);
}
pair<pii, pii> rect[q];
for (int i = 0; i < q; i++){
rect[i] = {{T1.tin[p1[i]], T1.tout[p1[i]]}, {T2.tin[p2[i]], T2.tout[p2[i]]}};
}
vector<int> end[n + 1];
for (int i = 0; i < q; i++){
end[rect[i].ff.ss].pb(i);
}
vector<int> out(q);
ST T(n);
for (int i = 1; i <= n; i++){
for (int j: st[i]){
T.upd(j, i);
}
for (int j: end[i]){
out[j] = (T.get(rect[j].ss.ff, rect[j].ss.ss) >= rect[j].ff.ff);
}
}
return out;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
6 ms |
1980 KB |
Output is correct |
11 |
Correct |
4 ms |
1624 KB |
Output is correct |
12 |
Correct |
4 ms |
1628 KB |
Output is correct |
13 |
Correct |
4 ms |
1728 KB |
Output is correct |
14 |
Correct |
4 ms |
1628 KB |
Output is correct |
15 |
Correct |
7 ms |
1884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
398 ms |
87120 KB |
Output is correct |
2 |
Correct |
409 ms |
90488 KB |
Output is correct |
3 |
Correct |
362 ms |
90352 KB |
Output is correct |
4 |
Correct |
375 ms |
90448 KB |
Output is correct |
5 |
Correct |
382 ms |
90576 KB |
Output is correct |
6 |
Correct |
413 ms |
90948 KB |
Output is correct |
7 |
Correct |
349 ms |
89168 KB |
Output is correct |
8 |
Correct |
347 ms |
90372 KB |
Output is correct |
9 |
Correct |
332 ms |
89584 KB |
Output is correct |
10 |
Correct |
324 ms |
89720 KB |
Output is correct |
11 |
Correct |
327 ms |
90036 KB |
Output is correct |
12 |
Correct |
416 ms |
90324 KB |
Output is correct |
13 |
Correct |
337 ms |
94540 KB |
Output is correct |
14 |
Correct |
331 ms |
94892 KB |
Output is correct |
15 |
Correct |
361 ms |
94576 KB |
Output is correct |
16 |
Correct |
348 ms |
94620 KB |
Output is correct |
17 |
Correct |
360 ms |
89088 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
6 ms |
1980 KB |
Output is correct |
11 |
Correct |
4 ms |
1624 KB |
Output is correct |
12 |
Correct |
4 ms |
1628 KB |
Output is correct |
13 |
Correct |
4 ms |
1728 KB |
Output is correct |
14 |
Correct |
4 ms |
1628 KB |
Output is correct |
15 |
Correct |
7 ms |
1884 KB |
Output is correct |
16 |
Correct |
398 ms |
87120 KB |
Output is correct |
17 |
Correct |
409 ms |
90488 KB |
Output is correct |
18 |
Correct |
362 ms |
90352 KB |
Output is correct |
19 |
Correct |
375 ms |
90448 KB |
Output is correct |
20 |
Correct |
382 ms |
90576 KB |
Output is correct |
21 |
Correct |
413 ms |
90948 KB |
Output is correct |
22 |
Correct |
349 ms |
89168 KB |
Output is correct |
23 |
Correct |
347 ms |
90372 KB |
Output is correct |
24 |
Correct |
332 ms |
89584 KB |
Output is correct |
25 |
Correct |
324 ms |
89720 KB |
Output is correct |
26 |
Correct |
327 ms |
90036 KB |
Output is correct |
27 |
Correct |
416 ms |
90324 KB |
Output is correct |
28 |
Correct |
337 ms |
94540 KB |
Output is correct |
29 |
Correct |
331 ms |
94892 KB |
Output is correct |
30 |
Correct |
361 ms |
94576 KB |
Output is correct |
31 |
Correct |
348 ms |
94620 KB |
Output is correct |
32 |
Correct |
360 ms |
89088 KB |
Output is correct |
33 |
Correct |
433 ms |
90988 KB |
Output is correct |
34 |
Correct |
174 ms |
39112 KB |
Output is correct |
35 |
Correct |
485 ms |
91716 KB |
Output is correct |
36 |
Correct |
432 ms |
91468 KB |
Output is correct |
37 |
Correct |
414 ms |
91460 KB |
Output is correct |
38 |
Correct |
504 ms |
91492 KB |
Output is correct |
39 |
Correct |
477 ms |
93272 KB |
Output is correct |
40 |
Correct |
443 ms |
97692 KB |
Output is correct |
41 |
Correct |
402 ms |
90532 KB |
Output is correct |
42 |
Correct |
370 ms |
89680 KB |
Output is correct |
43 |
Correct |
465 ms |
94712 KB |
Output is correct |
44 |
Correct |
421 ms |
90756 KB |
Output is correct |
45 |
Correct |
350 ms |
91716 KB |
Output is correct |
46 |
Correct |
364 ms |
91280 KB |
Output is correct |
47 |
Correct |
353 ms |
94280 KB |
Output is correct |
48 |
Correct |
366 ms |
94608 KB |
Output is correct |
49 |
Correct |
347 ms |
94884 KB |
Output is correct |
50 |
Correct |
354 ms |
94064 KB |
Output is correct |
51 |
Correct |
416 ms |
95632 KB |
Output is correct |
52 |
Correct |
423 ms |
95312 KB |
Output is correct |