Submission #728210

# Submission time Handle Problem Language Result Execution time Memory
728210 2023-04-22T04:44:29 Z WongChun1234 Werewolf (IOI18_werewolf) C++14
Compilation error
0 ms 0 KB
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
//0: human can reach (max) 1: werewolf (min)
const int N=600050;
int n,ch[2][2][N],val[2][N],par[2][N],pt[2],lift[2][20][N],sz[2][N],tim[2],pre[2][N],bit[N];
int u,v,l0,r0,l1,r1;
vector<pair<int,pair<int,int>>> srt[2];
vector<pair<pair<int,int>,pair<int,int>>> op;
int find(int id,int nde){
	return par[id][nde]==nde?nde:par[id][nde]=find(id,par[id][nde]);
}
void dfs(int id,int nde,int par){
	lift[id][0][nde]=par;
	for (int i=1;i<=19;i++) lift[id][i][nde]=lift[id][i-1][lift[i-1][nde]];
	pre[id][nde]=++tim[id];
	sz[id][nde]=1;
	if (nde>=n){
		dfs(id,ch[id][0][nde],nde);
		dfs(id,ch[id][1][nde],nde);
		sz[id][nde]+=sz[id][ch[id][0][nde]]+sz[id][ch[id][1][nde]];
	}
}
void upd(int id,int val){
	for (;id<N;id+=id&-id) bit[id]+=val;
}
int query(int id){
	int ret=0;
	for (;id;id-=id&-id) ret+=bit[id];
	return ret;
}
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;
	int q=s.size(),m=x.size();
	vector<int> ans(q);
	for (int i=0;i<m;i++){
		srt[0].push_back({min(x[i],y[i]),{x[i],y[i]}});
		srt[1].push_back({max(x[i],y[i]),{x[i],y[i]}});
	}
	sort(srt[0].begin(),srt[0].end(),greater<pair<int,pair<int,int>>>());
	sort(srt[1].begin(),srt[1].end());
	for (int i=0;i<2*n;i++) par[0][i]=par[1][i]=i;
	pt[0]=n,pt[1]=n;
	for (auto i:srt[0]){
		if (find(0,i.second.first)==find(0,i.second.second)) continue;
		ch[0][0][pt[0]]=find(0,i.second.first);
		ch[0][1][pt[0]]=find(0,i.second.second);
		par[0][find(0,i.second.first)]=pt[0];
		par[0][find(0,i.second.second)]=pt[0];
		val[0][pt[0]]=i.first;
		pt[0]++;
	}
	for (auto i:srt[1]){
		if (find(1,i.second.first)==find(1,i.second.second)) continue;
		ch[1][0][pt[1]]=find(1,i.second.first);
		ch[1][1][pt[1]]=find(1,i.second.second);
		par[1][find(1,i.second.first)]=pt[1];
		par[1][find(1,i.second.second)]=pt[1];
		val[1][pt[1]]=i.first;
		pt[1]++;
	}
	dfs(0,2*n-2,2*n-2);
	dfs(1,2*n-2,2*n-2);
	for (int i=0;i<n;i++) op.push_back({{pre[0][i],pre[1][i]},{1,1}});
	for (int i=0;i<q;i++){
		u=s[i],v=e[i];
		for (int j=19;j>=0;j--) if (val[0][lift[0][j][u]]>=l[i]) u=lift[0][j][u];
		for (int j=19;j>=0;j--) if (val[1][lift[1][j][v]]<=r[i]) v=lift[1][j][v];
		l0=pre[0][u],r0=pre[0][u]+sz[0][u]-1;
		l1=pre[1][v],r1=pre[1][v]+sz[1][v]-1;
		op.push_back({{r0,r1},{2,i*2}});
		op.push_back({{r0,l1-1},{2,i*2+1}});
		op.push_back({{l0-1,r1},{2,i*2+1}});
		op.push_back({{l0-1,l1-1},{2,i*2}});
	}
	sort(op.begin(),op.end());
	for (auto i:op){
		if (i.second.first==1){
			upd(i.first.second,1);
		}else if (i.second.first==2){
			if (i.second.second%2) ans[i.second.second/2]-=query(i.first.second);
			else ans[i.second.second/2]+=query(i.first.second);
		}else{
			upd(i.first.second,-1);
		}
	}
	for (int &i:ans) i=!!i;
	return ans;
}

Compilation message

werewolf.cpp: In function 'void dfs(int, int, int)':
werewolf.cpp:15:56: error: invalid types 'int [600050][int [600050]]' for array subscript
   15 |  for (int i=1;i<=19;i++) lift[id][i][nde]=lift[id][i-1][lift[i-1][nde]];
      |                                                        ^