Submission #816852

# Submission time Handle Problem Language Result Execution time Memory
816852 2023-08-09T07:03:21 Z ttamx Werewolf (IOI18_werewolf) C++14
100 / 100
351 ms 91888 KB
#include "werewolf.h"
#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int> p2;
typedef tuple<int,int,int> t3;

const int N=2e5+5;
const int M=4e5+5;
const int K=(1<<19)+5;

int n,m,q;
vector<int> adj[N];
int s[N],e[N],l[N],r[N];
vector<int> ql[N],qr[N];
vector<t3> ql2[N],qr2[N];
int pl[N],pr[N];
p2 ranl[N],ranr[N];
int posx[N],posy[N];
vector<int> num[N];

struct dsu_t{
	int p[M];
	int in[M],out[M],pos[M];
	vector<p2> node;
	void init(){
		for(int i=0;i<2*n;i++){
			p[i]=i;
		}
		node=vector<p2>(n,p2(-1,-1));
	}
	int fp(int u){
		if(u==p[u])return u;
		return p[u]=fp(p[u]);
	}
	void uni(int u,int v){
		u=fp(u),v=fp(v);
		if(u==v)return;
		int np=node.size();
		p[u]=p[v]=np;
		node.emplace_back(u,v);
	}
	void dfs(int u,int &t){
		if(u<n){
			in[u]=out[u]=++t;
			pos[t]=u;
			return;
		}
		auto [l,r]=node[u];
		dfs(l,t);
		dfs(r,t);
		in[u]=min(in[l],in[r]);
		out[u]=max(out[l],out[r]);
	}
	void dfs(){
		int t=0;
		dfs(node.size()-1,t);
	}
}dsu;

struct fenwick{
	int t[N];
	void add(int i,int v){
		while(i<N)t[i]+=v,i+=i&-i;
	}
	int read(int i){
		int res=0;
		while(i>0)res+=t[i],i-=i&-i;
		return res;
	}
}f;

vector<int> check_validity(int _n,vector<int> X,vector<int> Y,vector<int> S,vector<int> E,vector<int> L,vector<int> R) {
	n=_n;
	m=X.size();
	q=S.size();
	for(int i=0;i<m;i++){
		int u=X[i],v=Y[i];
		adj[u].emplace_back(v);
		adj[v].emplace_back(u);
	}
	for(int i=0;i<q;i++){
		s[i]=S[i];
		e[i]=E[i];
		l[i]=L[i];
		r[i]=R[i];
		ql[l[i]].emplace_back(i);
		qr[r[i]].emplace_back(i);
	}
	dsu.init();
	for(int u=n-1;u>=0;u--){
		for(auto v:adj[u]){
			if(v<u)continue;
			dsu.uni(u,v);
		}
		for(auto i:ql[u]){
			pl[i]=dsu.fp(s[i]);
		}
	}
	dsu.dfs();
	for(int i=0;i<n;i++)posx[i]=dsu.in[i];
	for(int i=0;i<q;i++){
		int p=pl[i];
		ranl[i]=p2(dsu.in[p],dsu.out[p]);
	}
	dsu.init();
	for(int u=0;u<n;u++){
		for(auto v:adj[u]){
			if(v>u)continue;
			dsu.uni(u,v);
		}
		for(auto i:qr[u]){
			pr[i]=dsu.fp(e[i]);
		}
	}
	dsu.dfs();
	for(int i=0;i<n;i++)posy[i]=dsu.in[i];
	for(int i=0;i<q;i++){
		int p=pr[i];
		ranr[i]=p2(dsu.in[p],dsu.out[p]);
	}
	for(int i=0;i<n;i++)num[posx[i]].emplace_back(posy[i]);
	vector<int> ans(q);
	for(int i=0;i<q;i++){
		auto [x,y]=ranl[i];
		auto [a,b]=ranr[i];
		ql2[x-1].emplace_back(a,b,i);
		qr2[y].emplace_back(a,b,i);
	}
	for(int i=1;i<=n;i++){
		for(auto x:num[i])f.add(x,1);
		for(auto [a,b,id]:ql2[i])ans[id]-=f.read(b)-f.read(a-1);
		for(auto [a,b,id]:qr2[i])ans[id]+=f.read(b)-f.read(a-1);
	}
	for(int i=0;i<q;i++)ans[i]=ans[i]>0;
	return ans;
}

Compilation message

werewolf.cpp: In member function 'void dsu_t::dfs(int, int&)':
werewolf.cpp:50:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   50 |   auto [l,r]=node[u];
      |        ^
werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:126:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  126 |   auto [x,y]=ranl[i];
      |        ^
werewolf.cpp:127:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  127 |   auto [a,b]=ranr[i];
      |        ^
werewolf.cpp:133:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  133 |   for(auto [a,b,id]:ql2[i])ans[id]-=f.read(b)-f.read(a-1);
      |            ^
werewolf.cpp:134:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  134 |   for(auto [a,b,id]:qr2[i])ans[id]+=f.read(b)-f.read(a-1);
      |            ^
# Verdict Execution time Memory Grader output
1 Correct 14 ms 28628 KB Output is correct
2 Correct 14 ms 28632 KB Output is correct
3 Correct 13 ms 28568 KB Output is correct
4 Correct 12 ms 28552 KB Output is correct
5 Correct 12 ms 28628 KB Output is correct
6 Correct 13 ms 28628 KB Output is correct
7 Correct 13 ms 28636 KB Output is correct
8 Correct 12 ms 28628 KB Output is correct
9 Correct 13 ms 28556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 28628 KB Output is correct
2 Correct 14 ms 28632 KB Output is correct
3 Correct 13 ms 28568 KB Output is correct
4 Correct 12 ms 28552 KB Output is correct
5 Correct 12 ms 28628 KB Output is correct
6 Correct 13 ms 28628 KB Output is correct
7 Correct 13 ms 28636 KB Output is correct
8 Correct 12 ms 28628 KB Output is correct
9 Correct 13 ms 28556 KB Output is correct
10 Correct 15 ms 29396 KB Output is correct
11 Correct 18 ms 29396 KB Output is correct
12 Correct 16 ms 29340 KB Output is correct
13 Correct 16 ms 29524 KB Output is correct
14 Correct 16 ms 29524 KB Output is correct
15 Correct 19 ms 29644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 329 ms 84076 KB Output is correct
2 Correct 311 ms 86384 KB Output is correct
3 Correct 293 ms 83936 KB Output is correct
4 Correct 286 ms 82656 KB Output is correct
5 Correct 290 ms 82888 KB Output is correct
6 Correct 305 ms 83924 KB Output is correct
7 Correct 299 ms 80492 KB Output is correct
8 Correct 282 ms 86396 KB Output is correct
9 Correct 245 ms 82308 KB Output is correct
10 Correct 241 ms 81076 KB Output is correct
11 Correct 240 ms 81256 KB Output is correct
12 Correct 270 ms 82196 KB Output is correct
13 Correct 275 ms 86640 KB Output is correct
14 Correct 288 ms 86608 KB Output is correct
15 Correct 278 ms 86584 KB Output is correct
16 Correct 314 ms 86616 KB Output is correct
17 Correct 278 ms 80600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 28628 KB Output is correct
2 Correct 14 ms 28632 KB Output is correct
3 Correct 13 ms 28568 KB Output is correct
4 Correct 12 ms 28552 KB Output is correct
5 Correct 12 ms 28628 KB Output is correct
6 Correct 13 ms 28628 KB Output is correct
7 Correct 13 ms 28636 KB Output is correct
8 Correct 12 ms 28628 KB Output is correct
9 Correct 13 ms 28556 KB Output is correct
10 Correct 15 ms 29396 KB Output is correct
11 Correct 18 ms 29396 KB Output is correct
12 Correct 16 ms 29340 KB Output is correct
13 Correct 16 ms 29524 KB Output is correct
14 Correct 16 ms 29524 KB Output is correct
15 Correct 19 ms 29644 KB Output is correct
16 Correct 329 ms 84076 KB Output is correct
17 Correct 311 ms 86384 KB Output is correct
18 Correct 293 ms 83936 KB Output is correct
19 Correct 286 ms 82656 KB Output is correct
20 Correct 290 ms 82888 KB Output is correct
21 Correct 305 ms 83924 KB Output is correct
22 Correct 299 ms 80492 KB Output is correct
23 Correct 282 ms 86396 KB Output is correct
24 Correct 245 ms 82308 KB Output is correct
25 Correct 241 ms 81076 KB Output is correct
26 Correct 240 ms 81256 KB Output is correct
27 Correct 270 ms 82196 KB Output is correct
28 Correct 275 ms 86640 KB Output is correct
29 Correct 288 ms 86608 KB Output is correct
30 Correct 278 ms 86584 KB Output is correct
31 Correct 314 ms 86616 KB Output is correct
32 Correct 278 ms 80600 KB Output is correct
33 Correct 349 ms 85296 KB Output is correct
34 Correct 178 ms 63820 KB Output is correct
35 Correct 336 ms 87188 KB Output is correct
36 Correct 336 ms 84640 KB Output is correct
37 Correct 327 ms 86692 KB Output is correct
38 Correct 351 ms 84992 KB Output is correct
39 Correct 342 ms 91888 KB Output is correct
40 Correct 338 ms 86584 KB Output is correct
41 Correct 295 ms 84868 KB Output is correct
42 Correct 289 ms 82052 KB Output is correct
43 Correct 342 ms 88916 KB Output is correct
44 Correct 341 ms 86096 KB Output is correct
45 Correct 277 ms 89512 KB Output is correct
46 Correct 282 ms 89356 KB Output is correct
47 Correct 291 ms 86684 KB Output is correct
48 Correct 284 ms 86532 KB Output is correct
49 Correct 302 ms 86720 KB Output is correct
50 Correct 293 ms 86584 KB Output is correct
51 Correct 338 ms 84724 KB Output is correct
52 Correct 297 ms 84592 KB Output is correct