#include <bits/stdc++.h>
#include "werewolf.h"
using namespace std;
#define ll long long
#define y1 zck_is_king
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define REP(i,n) for (int i = 0; i<n; ++i)
#define RREP(i,n) for (int i = n-1; i>=0; --i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) cout<<__LINE__<<": "<<#__VA_ARGS__<<"- ",_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cout<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cout<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif
const int iinf = 1e9+10;
const ll inf = 1ll<<60;
const ll mod = 1e9+7 ;
void GG(){cout<<"0\n"; exit(0);}
ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
ll re=1;
while (n>0){
if (n&1) re = re*a %mo;
a = a*a %mo;
n>>=1;
}
return re;
}
ll inv (ll b, ll mo = mod){
if (b==1) return b;
return (mo-mo/b) * inv(mo%b,mo) % mo;
}
const int maxn = 2e5+5;
int n;
vector<int> g[maxn];
struct dsu{
int par[maxn], sz[maxn];
// vector<int> tree[maxn];
vector<vector<int> > tree;
int L[maxn], R[maxn];
vector<int> ord;
int IT;
int find(int x) {return x == par[x]? x : par[x] = find(par[x]); }
// int findrng(int x, int l, int r) {
// if (x == par[x] || par[x] > r || par[x] < l) return x;
// return findrng(x,l,r);
// }
void mrg(int a, int b) { // b is the new parent
a = find(a); b = find(b);
if (a == b) return;
// if (sz[a] > sz[b]) swap(a,b);
par[a]=b; tree[b].pb(a);
// sz[b] += sz[a];
}
// void buildtree(){
// REP(i,n) {
// tree[par[i]].pb(i);
// }
// }
bool seen[maxn];
void dfs(int v) {
seen[v] = 1;
ord.pb(v);
L[v] = R[v] = IT++;
for (int u : tree[v]) {
dfs(u);
R[v] = R[u];
}
}
// void rundfs() {
// REP(i,n) {
// if (!seen[i]) dfs(i);
// }
// }
dsu(){
tree.resize(n);
REP(i,maxn) par[i] = i, sz[i] = 1;
IT = 0;
}
};
vector<int> ret;
vector<int> rbhere[maxn], lbhere[maxn]; // which queries have respective bounds here
int sub1[maxn], sub2[maxn]; // which subtree do you govern?
int seg[maxn];
void MO(int e, int v) {
for (++e; e<maxn; e+=e&-e) seg[e] += v;
}
int QU(int e) {
int re=0;
for (++e; e>0; e-=e&-e) re += seg[e];
return re;
}
struct qq{
// int cnt; // count under this
int l, r, i, dir;
};
vector<qq> go[maxn];
vector<int> check_validity(int _n, vector<int> mx, vector<int> my, vector<int> S, vector<int> E, vector<int> LB, vector<int> RB) {
n = _n;
// return {1,0,0};
// cout<<"yo"<<endl;
// return {0,0,0};
// bug("hi");
REP(i ,SZ(mx)) {
g[mx[i]].pb(my[i]);
g[my[i]].pb(mx[i]);
}
int q = SZ(S);
ret.resize(q);
REP(i,q) {
rbhere[RB[i]].pb(i);
lbhere[LB[i]].pb(i);
}
dsu LT, RT;
// build first tree from left
REP(i, n) {
for (int v : g[i]) {
if ( v<i)
LT.mrg(v, i); // order matters here! i is the new root
}
for (int y : rbhere[i]) {
sub1[y] = LT.find(E[y]);
}
}
// return {};
LT.dfs(n-1);
for (int i = n-1; i>=0; --i) {
for (int v : g[i]) {
if (v > i)
RT.mrg(v,i);
}
for (int y : lbhere[i]) {
sub2[y] = RT.find(S[y]);
// cout<<"tree 2: "<<y<<' '<<S[y]<<' '<<sub2[y]<<endl;
}
}
RT.dfs(0);
// cout<<"Tree 2: "<<endl;
// REP(i,n) cout<<RT.ord[i]<<' ';
// cout<<endl;
// vector<qq> ev;
REP(i, q) {
int lw = LT.L[sub1[i]], rw = LT.R[sub1[i]];
int qlw = RT.L[sub2[i]], qrw = RT.R[sub2[i]];
if (lw-1>=0) go[lw-1].pb({qlw, qrw, i, -1});
go[rw].pb({qlw, qrw, i, 1});
}
REP(i, n) {
int pos = RT.L[LT.ord[i]];
// cout<<"pos: "<<pos<<' '<<LT.ord[i]<<endl;
MO(pos, 1);
for (qq e : go[i]) {
ret[e.i] += e.dir * (QU(e.r) - QU(e.l-1));
}
}
REP(i, q) {
ret[i] = min(ret[i], 1);
}
return ret;
}
//#undef BALBIT
//signed main(){
// IOS();
//
//
//}
//#enidf
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
25760 KB |
Output is correct |
2 |
Correct |
16 ms |
25744 KB |
Output is correct |
3 |
Correct |
17 ms |
25716 KB |
Output is correct |
4 |
Correct |
16 ms |
25748 KB |
Output is correct |
5 |
Correct |
20 ms |
25732 KB |
Output is correct |
6 |
Correct |
15 ms |
25744 KB |
Output is correct |
7 |
Correct |
16 ms |
25740 KB |
Output is correct |
8 |
Correct |
16 ms |
25744 KB |
Output is correct |
9 |
Correct |
16 ms |
25712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
25760 KB |
Output is correct |
2 |
Correct |
16 ms |
25744 KB |
Output is correct |
3 |
Correct |
17 ms |
25716 KB |
Output is correct |
4 |
Correct |
16 ms |
25748 KB |
Output is correct |
5 |
Correct |
20 ms |
25732 KB |
Output is correct |
6 |
Correct |
15 ms |
25744 KB |
Output is correct |
7 |
Correct |
16 ms |
25740 KB |
Output is correct |
8 |
Correct |
16 ms |
25744 KB |
Output is correct |
9 |
Correct |
16 ms |
25712 KB |
Output is correct |
10 |
Correct |
22 ms |
26672 KB |
Output is correct |
11 |
Correct |
23 ms |
26716 KB |
Output is correct |
12 |
Correct |
25 ms |
26708 KB |
Output is correct |
13 |
Correct |
23 ms |
26856 KB |
Output is correct |
14 |
Correct |
20 ms |
26764 KB |
Output is correct |
15 |
Correct |
22 ms |
26828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
681 ms |
80428 KB |
Output is correct |
2 |
Correct |
557 ms |
89444 KB |
Output is correct |
3 |
Correct |
576 ms |
89528 KB |
Output is correct |
4 |
Correct |
542 ms |
88440 KB |
Output is correct |
5 |
Correct |
581 ms |
88388 KB |
Output is correct |
6 |
Correct |
660 ms |
88464 KB |
Output is correct |
7 |
Correct |
523 ms |
85560 KB |
Output is correct |
8 |
Correct |
584 ms |
91480 KB |
Output is correct |
9 |
Correct |
493 ms |
88588 KB |
Output is correct |
10 |
Correct |
503 ms |
86224 KB |
Output is correct |
11 |
Correct |
492 ms |
87384 KB |
Output is correct |
12 |
Correct |
499 ms |
87868 KB |
Output is correct |
13 |
Correct |
619 ms |
95236 KB |
Output is correct |
14 |
Correct |
631 ms |
95220 KB |
Output is correct |
15 |
Correct |
560 ms |
95204 KB |
Output is correct |
16 |
Correct |
592 ms |
95256 KB |
Output is correct |
17 |
Correct |
494 ms |
85192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
25760 KB |
Output is correct |
2 |
Correct |
16 ms |
25744 KB |
Output is correct |
3 |
Correct |
17 ms |
25716 KB |
Output is correct |
4 |
Correct |
16 ms |
25748 KB |
Output is correct |
5 |
Correct |
20 ms |
25732 KB |
Output is correct |
6 |
Correct |
15 ms |
25744 KB |
Output is correct |
7 |
Correct |
16 ms |
25740 KB |
Output is correct |
8 |
Correct |
16 ms |
25744 KB |
Output is correct |
9 |
Correct |
16 ms |
25712 KB |
Output is correct |
10 |
Correct |
22 ms |
26672 KB |
Output is correct |
11 |
Correct |
23 ms |
26716 KB |
Output is correct |
12 |
Correct |
25 ms |
26708 KB |
Output is correct |
13 |
Correct |
23 ms |
26856 KB |
Output is correct |
14 |
Correct |
20 ms |
26764 KB |
Output is correct |
15 |
Correct |
22 ms |
26828 KB |
Output is correct |
16 |
Correct |
681 ms |
80428 KB |
Output is correct |
17 |
Correct |
557 ms |
89444 KB |
Output is correct |
18 |
Correct |
576 ms |
89528 KB |
Output is correct |
19 |
Correct |
542 ms |
88440 KB |
Output is correct |
20 |
Correct |
581 ms |
88388 KB |
Output is correct |
21 |
Correct |
660 ms |
88464 KB |
Output is correct |
22 |
Correct |
523 ms |
85560 KB |
Output is correct |
23 |
Correct |
584 ms |
91480 KB |
Output is correct |
24 |
Correct |
493 ms |
88588 KB |
Output is correct |
25 |
Correct |
503 ms |
86224 KB |
Output is correct |
26 |
Correct |
492 ms |
87384 KB |
Output is correct |
27 |
Correct |
499 ms |
87868 KB |
Output is correct |
28 |
Correct |
619 ms |
95236 KB |
Output is correct |
29 |
Correct |
631 ms |
95220 KB |
Output is correct |
30 |
Correct |
560 ms |
95204 KB |
Output is correct |
31 |
Correct |
592 ms |
95256 KB |
Output is correct |
32 |
Correct |
494 ms |
85192 KB |
Output is correct |
33 |
Correct |
656 ms |
89232 KB |
Output is correct |
34 |
Correct |
308 ms |
67832 KB |
Output is correct |
35 |
Correct |
679 ms |
91660 KB |
Output is correct |
36 |
Correct |
678 ms |
89424 KB |
Output is correct |
37 |
Correct |
722 ms |
90768 KB |
Output is correct |
38 |
Correct |
620 ms |
89940 KB |
Output is correct |
39 |
Correct |
572 ms |
96252 KB |
Output is correct |
40 |
Correct |
618 ms |
93876 KB |
Output is correct |
41 |
Correct |
515 ms |
89024 KB |
Output is correct |
42 |
Correct |
495 ms |
86788 KB |
Output is correct |
43 |
Correct |
665 ms |
96348 KB |
Output is correct |
44 |
Correct |
571 ms |
90504 KB |
Output is correct |
45 |
Correct |
504 ms |
95552 KB |
Output is correct |
46 |
Correct |
550 ms |
95344 KB |
Output is correct |
47 |
Correct |
548 ms |
95536 KB |
Output is correct |
48 |
Correct |
527 ms |
95356 KB |
Output is correct |
49 |
Correct |
515 ms |
95412 KB |
Output is correct |
50 |
Correct |
547 ms |
95336 KB |
Output is correct |
51 |
Correct |
552 ms |
92344 KB |
Output is correct |
52 |
Correct |
559 ms |
92440 KB |
Output is correct |