Submission #727224

# Submission time Handle Problem Language Result Execution time Memory
727224 2023-04-20T08:48:32 Z myrcella Werewolf (IOI18_werewolf) C++17
100 / 100
717 ms 82144 KB
//by szh
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}

#include "werewolf.h"

const int maxn = 4e5+10;

int n;
int st[maxn][20];
vector <pii> edge;
int f[maxn],idx[maxn],node[maxn],lc[maxn],rc[maxn];
int dfn = 0;
pii rg[maxn],qs[maxn];
int w[maxn];

int tree[maxn];

void update(int x) {
	x++;
	while (x<maxn) {
		tree[x]++;
		x += lowbit(x);
	}
	return;
}

int query(int x) {
	x++;
	int ret = 0;
	while (x>0) {
		ret += tree[x];
		x-=lowbit(x);
	}
	return ret;
}

struct QQ{
	int val;
	int ss;
	pii range;
	int id;
} q[maxn];

bool cmpq(QQ x,QQ y) {
	return x.ss<y.ss;
}

int ans[maxn];

bool cmp1(pii x,pii y) {
	return min(x.fi,x.se) > min(y.fi,y.se);
}

bool cmp2(pii x,pii y) {
	return max(x.fi,x.se) < max(y.fi,y.se);
}

int getf(int x) {
	if (f[x]==x) return x;
	return f[x] = getf(f[x]);
}

void dfs(int u) {
	rep(i,1,20) {
		if (st[u][i-1]==-1) break;
		st[u][i] = st[st[u][i-1]][i-1];
	}
	if (u<n) idx[u] = rg[u].fi = rg[u].se = dfn++;
	else {
		dfs(lc[u]),dfs(rc[u]);
		rg[u] = {rg[lc[u]].fi,rg[rc[u]].se};
		assert(rg[lc[u]].se+1==rg[rc[u]].fi);
	}
	
}

std::vector<int> check_validity(int N, std::vector<int> X, std::vector<int> Y, std::vector<int> S, std::vector<int> E, std::vector<int> L, std::vector<int> R) {
	int tot = N;
	memset(st,-1,sizeof(st));
	n = N;
	rep(i,0,SZ(X)) edge.pb({X[i],Y[i]});
	sort(ALL(edge),cmp1);
	rep(i,0,N) f[i] = i;
	for (auto it:edge) {
		int fx = getf(it.fi),fy = getf(it.se);
		if (fx==fy) continue;
		st[fx][0] = st[fy][0] = tot;
		f[tot] = tot;
		w[tot] = min(it.fi,it.se);
		lc[tot] = fx, rc[tot] = fy;
		f[fx] = f[fy] = tot++;
	}
	dfs(tot-1);
	rep(i,0,SZ(S)) {
		int u = S[i];
		for (int j = 19;j>=0;j--) 
			if (st[u][j]!=-1 and w[st[u][j]]>=L[i]) u = st[u][j];
		qs[i] = rg[u];
	}
	rep(i,0,n) node[idx[i]] = i;
	//------
	tot = n;
	memset(st,-1,sizeof(st));
	sort(ALL(edge),cmp2);
	rep(i,0,N) f[i] = i;
	for (auto it:edge) {
		int fx = getf(it.fi),fy = getf(it.se);
		if (fx==fy) continue;
		st[fx][0] = st[fy][0] = tot;
		f[tot] = tot;
		w[tot] = max(it.fi,it.se);
		lc[tot] = fx, rc[tot] = fy;
		f[fx] = f[fy] = tot++;
	}
	dfs(tot-1);
	rep(i,0,SZ(S)) {
		int u = E[i];
		for (int j=19;j>=0;j--)
			if (st[u][j]!=-1 and w[st[u][j]]<=R[i]) u = st[u][j];
		q[i*2].id = q[i*2+1].id = i;
		q[i*2].range = q[i*2+1].range = rg[u];
		q[i*2].ss = qs[i].fi-1, q[i*2+1].ss = qs[i].se;
		q[i*2].val = -1, q[i*2+1].val = 1;
	}
	sort(q,q+SZ(S)*2,cmpq);
	int cur = 0;
	for (auto it:q) {
		while (cur<=it.ss) update(idx[node[cur++]]);
		ans[it.id] += it.val * (query(it.range.se) - query(it.range.fi-1));
	}
	vector <int> ret;
	rep(i,0,SZ(S)) {
		assert(ans[i]>=0);
		ret.pb((ans[i]>0));
	}
	return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 20 ms 39508 KB Output is correct
2 Correct 20 ms 39500 KB Output is correct
3 Correct 22 ms 39536 KB Output is correct
4 Correct 21 ms 39516 KB Output is correct
5 Correct 22 ms 39508 KB Output is correct
6 Correct 21 ms 39512 KB Output is correct
7 Correct 23 ms 39508 KB Output is correct
8 Correct 21 ms 39508 KB Output is correct
9 Correct 23 ms 39504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 39508 KB Output is correct
2 Correct 20 ms 39500 KB Output is correct
3 Correct 22 ms 39536 KB Output is correct
4 Correct 21 ms 39516 KB Output is correct
5 Correct 22 ms 39508 KB Output is correct
6 Correct 21 ms 39512 KB Output is correct
7 Correct 23 ms 39508 KB Output is correct
8 Correct 21 ms 39508 KB Output is correct
9 Correct 23 ms 39504 KB Output is correct
10 Correct 25 ms 40076 KB Output is correct
11 Correct 25 ms 40020 KB Output is correct
12 Correct 26 ms 39988 KB Output is correct
13 Correct 28 ms 40068 KB Output is correct
14 Correct 27 ms 40036 KB Output is correct
15 Correct 31 ms 40140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 515 ms 63924 KB Output is correct
2 Correct 587 ms 75524 KB Output is correct
3 Correct 519 ms 73492 KB Output is correct
4 Correct 451 ms 72612 KB Output is correct
5 Correct 459 ms 72584 KB Output is correct
6 Correct 498 ms 72448 KB Output is correct
7 Correct 527 ms 72388 KB Output is correct
8 Correct 614 ms 75508 KB Output is correct
9 Correct 418 ms 73504 KB Output is correct
10 Correct 365 ms 72612 KB Output is correct
11 Correct 375 ms 72628 KB Output is correct
12 Correct 397 ms 72468 KB Output is correct
13 Correct 642 ms 75564 KB Output is correct
14 Correct 666 ms 75640 KB Output is correct
15 Correct 656 ms 75600 KB Output is correct
16 Correct 646 ms 75676 KB Output is correct
17 Correct 443 ms 72348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 39508 KB Output is correct
2 Correct 20 ms 39500 KB Output is correct
3 Correct 22 ms 39536 KB Output is correct
4 Correct 21 ms 39516 KB Output is correct
5 Correct 22 ms 39508 KB Output is correct
6 Correct 21 ms 39512 KB Output is correct
7 Correct 23 ms 39508 KB Output is correct
8 Correct 21 ms 39508 KB Output is correct
9 Correct 23 ms 39504 KB Output is correct
10 Correct 25 ms 40076 KB Output is correct
11 Correct 25 ms 40020 KB Output is correct
12 Correct 26 ms 39988 KB Output is correct
13 Correct 28 ms 40068 KB Output is correct
14 Correct 27 ms 40036 KB Output is correct
15 Correct 31 ms 40140 KB Output is correct
16 Correct 515 ms 63924 KB Output is correct
17 Correct 587 ms 75524 KB Output is correct
18 Correct 519 ms 73492 KB Output is correct
19 Correct 451 ms 72612 KB Output is correct
20 Correct 459 ms 72584 KB Output is correct
21 Correct 498 ms 72448 KB Output is correct
22 Correct 527 ms 72388 KB Output is correct
23 Correct 614 ms 75508 KB Output is correct
24 Correct 418 ms 73504 KB Output is correct
25 Correct 365 ms 72612 KB Output is correct
26 Correct 375 ms 72628 KB Output is correct
27 Correct 397 ms 72468 KB Output is correct
28 Correct 642 ms 75564 KB Output is correct
29 Correct 666 ms 75640 KB Output is correct
30 Correct 656 ms 75600 KB Output is correct
31 Correct 646 ms 75676 KB Output is correct
32 Correct 443 ms 72348 KB Output is correct
33 Correct 611 ms 73112 KB Output is correct
34 Correct 381 ms 71060 KB Output is correct
35 Correct 676 ms 75864 KB Output is correct
36 Correct 607 ms 73040 KB Output is correct
37 Correct 660 ms 75196 KB Output is correct
38 Correct 643 ms 73528 KB Output is correct
39 Correct 611 ms 78788 KB Output is correct
40 Correct 717 ms 81716 KB Output is correct
41 Correct 545 ms 74536 KB Output is correct
42 Correct 500 ms 73028 KB Output is correct
43 Correct 670 ms 79676 KB Output is correct
44 Correct 598 ms 74960 KB Output is correct
45 Correct 518 ms 79096 KB Output is correct
46 Correct 567 ms 78752 KB Output is correct
47 Correct 651 ms 75724 KB Output is correct
48 Correct 660 ms 75544 KB Output is correct
49 Correct 670 ms 75708 KB Output is correct
50 Correct 682 ms 75536 KB Output is correct
51 Correct 691 ms 82144 KB Output is correct
52 Correct 680 ms 81992 KB Output is correct