//
#ifndef __SIZEOF_INT128__
#define __SIZEOF_INT128__
#endif
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
template <typename T> using oset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define rep(i, p, k) for(int i(p); i < (k); ++i)
#define per(i, p, k) for(int i(p); i > (k); --i)
#define sz(x) (int)(x).size()
#define sc static_cast
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef __int128_t lll;
//#define int ll
template <typename T = int> using par = std::pair <T, T>;
#define fi first
#define se second
#define test int _number_of_tests(in()); while(_number_of_tests--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb emplace_back
struct Timer {
string name{""};
time_point<high_resolution_clock> end, start{high_resolution_clock::now()};
duration<float, std::milli> dur;
Timer() = default;
Timer(string nm): name(nm) {}
~Timer() {
end = high_resolution_clock::now(); dur= end - start;
cout << "@" << name << "> " << dur.count() << " ms" << '\n';
}
};
template <typename T = int> inline T in()
{
static T x;
std::cin >> x;
return x;
}
std::string yn(bool b)
{
if(b) return "YES\n";
else return "NO\n";
}
template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par);
template <typename T> std::ostream& operator<< (std::ostream& out, const std::vector <T>& wek)
{
for(const auto& i : wek)out << i << ' ';
return out;
}
template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par)
{
out << '{'<<par.first<<", "<<par.second<<"}";
return out;
}
#define show(x) cerr << #x << " = " << x << '\n';
constexpr int maxn = 2e5 + 3;
vector <int> graf[maxn];
int rep[maxn][2];
int find(int w, bool b){
if(!~rep[w][b])return w;
return rep[w][b] = find(rep[w][b], b);
}
vector <int> syn[maxn][2];
int ojc[maxn][20][2];
vector <int> pv[2];
int pro[maxn][2], poo[maxn][2];
void dfs(int w, bool b){
pro[w][b] = sz(pv[b]);
pv[b].pb(w);
for(auto i: syn[w][b])dfs(i, b);
poo[w][b] = sz(pv[b])-1;
}
constexpr int pol = 1<<18;
vector <int> pyt[pol*2];
vector <int> check_validity (int n, vector <int> x, vector <int> y, vector <int> a, vector <int> b, vector <int> l, vector <int> r)
{
int m(sz(x)), q(sz(a));
pv[0].clear();
pv[1].clear();
rep(i, 0, n){
syn[i][0].clear();
syn[i][1].clear();
graf[i].clear();
rep[i][0] = rep[i][1] = -1;
}
rep(i, 0, m){
graf[x[i]].pb(y[i]);
graf[y[i]].pb(x[i]);
}
rep(i, 0, n)ojc[i][0][0] = ojc[i][0][1] = i;
rep(i, 0, n){
set <int> s;
for(auto j: graf[i])if(j < i)s.insert(find(j, 0));
for(auto j: s){
syn[i][0].pb(j);
rep[j][0] = i;
ojc[j][0][0] = i;
}
}
per(i, n-1, -1){
set <int> s;
for(auto j: graf[i])if(j > i)s.insert(find(j, 1));
for(auto j: s){
syn[i][1].pb(j);
rep[j][1] = i;
ojc[j][0][1] = i;
}
}
rep(b, 0, 2)rep(k, 1, 20)rep(i, 0, n)ojc[i][k][b] = ojc[ojc[i][k-1][b]][k-1][b];
dfs(0, 1);
dfs(n-1, 0);
// cout <<pv[0] << '\n' << pv[1] << '\n';
vector <int> odp(q);
vector <pair <int, int>> py0(q);
vector <vector <int>> zac(n), kon(n);
vector <bool> act(q);
rep(i, 0, q){
int k(19);
while(a[i] != ojc[a[i]][0][1] && ojc[a[i]][0][1] >= l[i]){
while(k && ojc[a[i]][k][1] < l[i])--k;
a[i] = ojc[a[i]][k][1];
}
k = 19;
while(b[i] != ojc[b[i]][0][0] && ojc[b[i]][0][0] <= r[i]){
while(k && ojc[b[i]][k][0] > r[i])--k;
b[i] = ojc[b[i]][k][0];
}
int p1(pro[a[i]][1]), k1(poo[a[i]][1]), p0(pro[b[i]][0]), k0(poo[b[i]][0]);
py0[i] = {p0, k0};
zac[p1].pb(i);
kon[k1].pb(i);
}
rep(i, 0, n){
for(auto j: zac[i]){
act[j] = 1;
int a(py0[j].first + pol-1), b(py0[j].second + pol+1);
while(a+1 != b){
if(a % 2 == 0)pyt[a+1].pb(j);
if(b % 2 == 1)pyt[b-1].pb(j);
a /= 2; b /= 2;
}
}
int g(pro[pv[1][i]][0] + pol);
while(g > 0){
for(auto j: pyt[g])if(act[j])odp[j] = 1;
pyt[g].clear();
g /= 2;
}
for(auto j: kon[i])act[j] = 0;
}
return odp;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
34140 KB |
Output is correct |
2 |
Correct |
8 ms |
33900 KB |
Output is correct |
3 |
Correct |
8 ms |
34140 KB |
Output is correct |
4 |
Correct |
8 ms |
33884 KB |
Output is correct |
5 |
Correct |
10 ms |
34140 KB |
Output is correct |
6 |
Correct |
8 ms |
33984 KB |
Output is correct |
7 |
Correct |
8 ms |
33884 KB |
Output is correct |
8 |
Correct |
8 ms |
34096 KB |
Output is correct |
9 |
Correct |
7 ms |
33904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
34140 KB |
Output is correct |
2 |
Correct |
8 ms |
33900 KB |
Output is correct |
3 |
Correct |
8 ms |
34140 KB |
Output is correct |
4 |
Correct |
8 ms |
33884 KB |
Output is correct |
5 |
Correct |
10 ms |
34140 KB |
Output is correct |
6 |
Correct |
8 ms |
33984 KB |
Output is correct |
7 |
Correct |
8 ms |
33884 KB |
Output is correct |
8 |
Correct |
8 ms |
34096 KB |
Output is correct |
9 |
Correct |
7 ms |
33904 KB |
Output is correct |
10 |
Correct |
12 ms |
34648 KB |
Output is correct |
11 |
Correct |
12 ms |
34652 KB |
Output is correct |
12 |
Correct |
13 ms |
34856 KB |
Output is correct |
13 |
Correct |
12 ms |
34908 KB |
Output is correct |
14 |
Correct |
11 ms |
34940 KB |
Output is correct |
15 |
Correct |
12 ms |
34904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
375 ms |
111180 KB |
Output is correct |
2 |
Correct |
400 ms |
123296 KB |
Output is correct |
3 |
Correct |
398 ms |
129604 KB |
Output is correct |
4 |
Correct |
370 ms |
127244 KB |
Output is correct |
5 |
Correct |
350 ms |
125004 KB |
Output is correct |
6 |
Correct |
403 ms |
122904 KB |
Output is correct |
7 |
Correct |
369 ms |
124484 KB |
Output is correct |
8 |
Correct |
364 ms |
131484 KB |
Output is correct |
9 |
Correct |
338 ms |
127248 KB |
Output is correct |
10 |
Correct |
291 ms |
118608 KB |
Output is correct |
11 |
Correct |
315 ms |
116784 KB |
Output is correct |
12 |
Correct |
368 ms |
119880 KB |
Output is correct |
13 |
Correct |
466 ms |
132612 KB |
Output is correct |
14 |
Correct |
432 ms |
131136 KB |
Output is correct |
15 |
Correct |
455 ms |
132420 KB |
Output is correct |
16 |
Correct |
439 ms |
131656 KB |
Output is correct |
17 |
Correct |
370 ms |
123976 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
34140 KB |
Output is correct |
2 |
Correct |
8 ms |
33900 KB |
Output is correct |
3 |
Correct |
8 ms |
34140 KB |
Output is correct |
4 |
Correct |
8 ms |
33884 KB |
Output is correct |
5 |
Correct |
10 ms |
34140 KB |
Output is correct |
6 |
Correct |
8 ms |
33984 KB |
Output is correct |
7 |
Correct |
8 ms |
33884 KB |
Output is correct |
8 |
Correct |
8 ms |
34096 KB |
Output is correct |
9 |
Correct |
7 ms |
33904 KB |
Output is correct |
10 |
Correct |
12 ms |
34648 KB |
Output is correct |
11 |
Correct |
12 ms |
34652 KB |
Output is correct |
12 |
Correct |
13 ms |
34856 KB |
Output is correct |
13 |
Correct |
12 ms |
34908 KB |
Output is correct |
14 |
Correct |
11 ms |
34940 KB |
Output is correct |
15 |
Correct |
12 ms |
34904 KB |
Output is correct |
16 |
Correct |
375 ms |
111180 KB |
Output is correct |
17 |
Correct |
400 ms |
123296 KB |
Output is correct |
18 |
Correct |
398 ms |
129604 KB |
Output is correct |
19 |
Correct |
370 ms |
127244 KB |
Output is correct |
20 |
Correct |
350 ms |
125004 KB |
Output is correct |
21 |
Correct |
403 ms |
122904 KB |
Output is correct |
22 |
Correct |
369 ms |
124484 KB |
Output is correct |
23 |
Correct |
364 ms |
131484 KB |
Output is correct |
24 |
Correct |
338 ms |
127248 KB |
Output is correct |
25 |
Correct |
291 ms |
118608 KB |
Output is correct |
26 |
Correct |
315 ms |
116784 KB |
Output is correct |
27 |
Correct |
368 ms |
119880 KB |
Output is correct |
28 |
Correct |
466 ms |
132612 KB |
Output is correct |
29 |
Correct |
432 ms |
131136 KB |
Output is correct |
30 |
Correct |
455 ms |
132420 KB |
Output is correct |
31 |
Correct |
439 ms |
131656 KB |
Output is correct |
32 |
Correct |
370 ms |
123976 KB |
Output is correct |
33 |
Correct |
418 ms |
120072 KB |
Output is correct |
34 |
Correct |
206 ms |
78036 KB |
Output is correct |
35 |
Correct |
463 ms |
120924 KB |
Output is correct |
36 |
Correct |
387 ms |
119632 KB |
Output is correct |
37 |
Correct |
488 ms |
120800 KB |
Output is correct |
38 |
Correct |
438 ms |
119984 KB |
Output is correct |
39 |
Correct |
513 ms |
127652 KB |
Output is correct |
40 |
Correct |
513 ms |
135500 KB |
Output is correct |
41 |
Correct |
428 ms |
115528 KB |
Output is correct |
42 |
Correct |
302 ms |
113976 KB |
Output is correct |
43 |
Correct |
469 ms |
124700 KB |
Output is correct |
44 |
Correct |
446 ms |
116880 KB |
Output is correct |
45 |
Correct |
407 ms |
129000 KB |
Output is correct |
46 |
Correct |
474 ms |
130844 KB |
Output is correct |
47 |
Correct |
474 ms |
133160 KB |
Output is correct |
48 |
Correct |
468 ms |
131908 KB |
Output is correct |
49 |
Correct |
480 ms |
132144 KB |
Output is correct |
50 |
Correct |
521 ms |
132676 KB |
Output is correct |
51 |
Correct |
453 ms |
135096 KB |
Output is correct |
52 |
Correct |
454 ms |
133960 KB |
Output is correct |