Submission #511080

# Submission time Handle Problem Language Result Execution time Memory
511080 2022-01-15T05:40:23 Z Register City (JOI17_city) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "Encoder.h"
using namespace std;
const int N=(1<<18)+10,M=1<<8;
int n,tot,sz[N],dfi[N],dfo[N];
vector<int> e[N];
int sz(int x) {return dfo[x]-dfi[x]+1;}
int id(int x) {return (x-1)/M;}
void dfs0(int x,int fa){
	sz[x]=1;
	for(int i=0;i<e[x].size();i++) if(y==fa) {e.erase(e.begin()+i);break;}
	for(int y:e[x]) dfs0(y,x),sz[x]+=sz[y];
	sort(e[i].begin,e[i].end(),[&](int x,int y){return sz[x]<sz[y];});
}
void dfs1(int x,int fa){
	dfi[x]=++tot;
	for(int y:e[x]) dfs1(y,x);
	dfo[x]=tot;
	if(sz(x)>M){
		int k=id(dfo[x]);
		Code(x,(1<<27)+M*(k-1)*k/2+dfi[x]);
	}
}
void dfs2(int x,int fa,int ri){
	if(sz(x)>M) ri=id(dfo[x]);
	else Code(x,(ri==id(dfo[x]))<<26|dfi[x]<<8|(sz(x)-1));
	for(int y:e[x]) dfs2(y,x,ri);
}
void Encode(int nn,int u[],int v[]){
	n=nn;
	for(int i=0;i+1<n;i++) e[u[i]].push_back(v[i]),e[v[i]].push_back(u[i]);
	dfs0(0,-1);dfs1(0,-1);dfs2(0,-1,0);
}
#include <bits/stdc++.h>
#include "Device.h"
using namespace std;
const int M=256;
void InitDevice(){}
int id(int x) {return (x-1)/M;}
void calc(int&b,int&d,int&k,int x){
	if(x>>27&1){
		b=1;x-=(1<<27);k=0;
		int l=1,r=1000;
		while(l<=r){
			int mid=l+r>>1;
			if(M*mid*(mid-1)/2<x) k=mid,l=mid+1;
			else r=mid-1;
		}
		d=x-M*k*(k-1)/2;
	}else b=0,d=(x>>8),k=x-(d<<8);
}
int Answer(long long x,long long y){
	int s=x,t=y,bs,ds,ks,bt,dt,kt;
	calc(bs,ds,ks,s);calc(bt,dt,kt,t);
	if(bs&&bt){
		if(ds<dt&&kt<=ks) return 1;
		else if(dt<ds&&ks<=kt) return 0;
		return 2;
	}else if(!bs&&!bt){
		if(ds>>18&1) ds-=(1<<18);
		if(dt>>18&1) dt-=(1<<18);
		int rs=ds+ks,rt=dt+kt;
		if(ds<dt&&rt<=rs) return 1;
		else if(dt<ds&&rs<=rt) return 0;
		return 2;
	}else{
		bool fl=1,ri=0;
		if(bt) swap(ds,dt),swap(ks,kt),fl=0;
		if(dt>>18&1) ri=1,dt-=(1<<18);
		if(ds>dt||ks<id(dt+kt)) return 2;
		if(ks>id(dt+kt)||ri) return fl;
		return 2;
	}
}

Compilation message

Encoder.cpp:7:13: error: 'int sz(int)' redeclared as different kind of entity
    7 | int sz(int x) {return dfo[x]-dfi[x]+1;}
      |             ^
Encoder.cpp:5:11: note: previous declaration 'int sz [262154]'
    5 | int n,tot,sz[N],dfi[N],dfo[N];
      |           ^~
Encoder.cpp: In function 'void dfs0(int, int)':
Encoder.cpp:11:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |  for(int i=0;i<e[x].size();i++) if(y==fa) {e.erase(e.begin()+i);break;}
      |              ~^~~~~~~~~~~~
Encoder.cpp:11:36: error: 'y' was not declared in this scope
   11 |  for(int i=0;i<e[x].size();i++) if(y==fa) {e.erase(e.begin()+i);break;}
      |                                    ^
Encoder.cpp:11:46: error: request for member 'erase' in 'e', which is of non-class type 'std::vector<int> [262154]'
   11 |  for(int i=0;i<e[x].size();i++) if(y==fa) {e.erase(e.begin()+i);break;}
      |                                              ^~~~~
Encoder.cpp:11:54: error: request for member 'begin' in 'e', which is of non-class type 'std::vector<int> [262154]'
   11 |  for(int i=0;i<e[x].size();i++) if(y==fa) {e.erase(e.begin()+i);break;}
      |                                                      ^~~~~
Encoder.cpp:13:9: error: 'i' was not declared in this scope
   13 |  sort(e[i].begin,e[i].end(),[&](int x,int y){return sz[x]<sz[y];});
      |         ^
Encoder.cpp: In function 'void dfs1(int, int)':
Encoder.cpp:19:9: error: 'sz' cannot be used as a function
   19 |  if(sz(x)>M){
      |         ^
Encoder.cpp: In function 'void dfs2(int, int, int)':
Encoder.cpp:25:9: error: 'sz' cannot be used as a function
   25 |  if(sz(x)>M) ri=id(dfo[x]);
      |         ^
Encoder.cpp:26:50: error: 'sz' cannot be used as a function
   26 |  else Code(x,(ri==id(dfo[x]))<<26|dfi[x]<<8|(sz(x)-1));
      |                                                  ^

Device.cpp: In function 'void calc(int&, int&, int&, int)':
Device.cpp:12:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   12 |    int mid=l+r>>1;
      |            ~^~