Submission #333222

# Submission time Handle Problem Language Result Execution time Memory
333222 2020-12-05T01:20:11 Z YJU Cats or Dogs (JOI18_catdog) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=4e5+5;
const ll K=350;
const ld pi=acos(-1);
const long long INF=(1LL<<28);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()

ll seg[4*N],ti,exist[N],ip[N],nl[N],nr[N],pa[N];
vector<ll> v[N],lis;

void ins(ll id,ll l,ll r,ll to,ll d){
	if(l==r-1){seg[id]+=d;return ;}
	ll mid=(l+r)>>1;
	if(to<mid){
		ins(id*2,l,mid,to,d);
	}else{
		ins(id*2+1,mid,r,to,d);
	}
	seg[id]=seg[id*2]+seg[id*2+1];
}

ll q(ll id,ll l,ll r,ll ql,ll qr){
	if(l>=ql&&r<=qr)return seg[id];
	if(l>=qr||r<=ql)return 0;
	ll mid=(l+r)>>1;
	return q(id*2,l,mid,ql,qr)+q(id*2+1,mid,r,ql,qr);
}

void upd(ll nd,ll ty){
	ll ti=q(1,0,N,nl[nd],nr[nd])+exist[pa[nd]];
	exist[nd]=(ty>0?1:0);
	ans-=ty*(ti-1);
	ins(1,0,n,ip[nd],ty);
}

void initialize(int n,vector<int> a,vector<int> b){
	REP(i,n-1)v[a[i]*2].pb(b[i]*2),v[b[i]*2].pb(a[i]*2),v[a[i]*2-1].pb(b[i]*2-1),v[b[i]*2-1].pb(a[i]*2-1);
	lis.pb(1);ip[1]=ti++;exist[1]=1;
	REP(i,n){
		nl[lis[i]]=ti;
		for(auto j:v[lis[i]]){
			if(exist[j])continue;
			lis.pb(j);ip[j]=ti++;exist[j]=1;
		}
		nr[lis[i]]=ti;
	}
	lis.clear();
	lis.pb(2);ip[2]=ti++;exist[2]=1;
	REP(i,n){
		nl[lis[i]]=ti;
		for(auto j:v[lis[i]]){
			if(exist[j])continue;
			lis.pb(j);ip[j]=ti++;exist[j]=1;
		}
		nr[lis[i]]=ti;
	}
	REP(i,2*n)ins(1,0,N,i,1);
	sum=2;
}

int cat(int id){
	upd(id*2-1,-1);
	++cnt[0];
	if(cnt[0]==0||cnt[1]==0)return 0;
	return sum-1;
}

int dog(int id){
	upd(id*2,-1);
	++cnt[1];
	if(cnt[0]==0||cnt[1]==0)return 0;
	return sum-1;
}

int neighbor(int id){
	if(!exist[id*2])upd(id*2,1),--cnt[1];
	else if(!exist[id*2-1])upd(id*2-1,1),--cnt[0];
	if(cnt[0]==0||cnt[1]==0)return 0;
	return sum-1;
}


Compilation message

catdog.cpp: In function 'void upd(ll, ll)':
catdog.cpp:48:2: error: 'ans' was not declared in this scope; did you mean 'ins'?
   48 |  ans-=ty*(ti-1);
      |  ^~~
      |  ins
catdog.cpp:49:10: error: 'n' was not declared in this scope; did you mean 'nd'?
   49 |  ins(1,0,n,ip[nd],ty);
      |          ^
      |          nd
catdog.cpp: In function 'void initialize(int, std::vector<int>, std::vector<int>)':
catdog.cpp:74:2: error: 'sum' was not declared in this scope
   74 |  sum=2;
      |  ^~~
catdog.cpp: In function 'int cat(int)':
catdog.cpp:79:4: error: 'cnt' was not declared in this scope; did you mean 'cat'?
   79 |  ++cnt[0];
      |    ^~~
      |    cat
catdog.cpp:81:9: error: 'sum' was not declared in this scope
   81 |  return sum-1;
      |         ^~~
catdog.cpp: In function 'int dog(int)':
catdog.cpp:86:4: error: 'cnt' was not declared in this scope; did you mean 'cat'?
   86 |  ++cnt[1];
      |    ^~~
      |    cat
catdog.cpp:88:9: error: 'sum' was not declared in this scope
   88 |  return sum-1;
      |         ^~~
catdog.cpp: In function 'int neighbor(int)':
catdog.cpp:92:32: error: 'cnt' was not declared in this scope; did you mean 'cat'?
   92 |  if(!exist[id*2])upd(id*2,1),--cnt[1];
      |                                ^~~
      |                                cat
catdog.cpp:93:41: error: 'cnt' was not declared in this scope; did you mean 'cat'?
   93 |  else if(!exist[id*2-1])upd(id*2-1,1),--cnt[0];
      |                                         ^~~
      |                                         cat
catdog.cpp:94:5: error: 'cnt' was not declared in this scope; did you mean 'cat'?
   94 |  if(cnt[0]==0||cnt[1]==0)return 0;
      |     ^~~
      |     cat
catdog.cpp:95:9: error: 'sum' was not declared in this scope
   95 |  return sum-1;
      |         ^~~