QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#293932#7682. Redundant Towersucup-team087#AC ✓1934ms315756kbC++2018.3kb2023-12-29 23:46:232023-12-29 23:46:24

Judging History

你现在查看的是最新测评结果

  • [2023-12-29 23:46:24]
  • 评测
  • 测评结果:AC
  • 用时:1934ms
  • 内存:315756kb
  • [2023-12-29 23:46:23]
  • 提交

answer

#ifndef LOCAL
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#endif

#include <bits/stdc++.h>
using namespace std;

using ll=long long;
//#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define si(x) int(x.size())
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

#define mp make_pair
#define mt make_tuple
#define one(x) memset(x,-1,sizeof(x))
#define zero(x) memset(x,0,sizeof(x))
#ifdef LOCAL
void dmpr(ostream&os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ";
	dmpr(os,args...);
}
#define dmp2(...) dmpr(cerr,__LINE__,##__VA_ARGS__)
#else
#define dmp2(...) void(0)
#endif

using uint=unsigned;
using ull=unsigned long long;

template<class t,size_t n>
ostream& operator<<(ostream&os,const array<t,n>&a){
	return os<<vc<t>(all(a));
}

template<int i,class T>
void print_tuple(ostream&,const T&){
}

template<int i,class T,class H,class ...Args>
void print_tuple(ostream&os,const T&t){
	if(i)os<<",";
	os<<get<i>(t);
	print_tuple<i+1,T,Args...>(os,t);
}

template<class ...Args>
ostream& operator<<(ostream&os,const tuple<Args...>&t){
	os<<"{";
	print_tuple<0,tuple<Args...>,Args...>(os,t);
	return os<<"}";
}

ll read(){
	ll i;
	cin>>i;
	return i;
}

vi readvi(int n,int off=0){
	vi v(n);
	rep(i,n)v[i]=read()+off;
	return v;
}

pi readpi(int off=0){
	int a,b;cin>>a>>b;
	return pi(a+off,b+off);
}

template<class t>
void print_single(t x,int suc=1){
	cout<<x;
	if(suc==1)
		cout<<"\n";
	if(suc==2)
		cout<<" ";
}

template<class t,class u>
void print_single(const pair<t,u>&p,int suc=1){
	print_single(p.a,2);
	print_single(p.b,suc);
}

template<class T>
void print_single(const vector<T>&v,int suc=1){
	rep(i,v.size())
		print_single(v[i],i==int(v.size())-1?suc:2);
}

template<class T>
void print_offset(const vector<T>&v,ll off,int suc=1){
	rep(i,v.size())
		print_single(v[i]+off,i==int(v.size())-1?suc:2);
}

template<class T,size_t N>
void print_single(const array<T,N>&v,int suc=1){
	rep(i,N)
		print_single(v[i],i==int(N)-1?suc:2);
}

template<class T>
void print(const T&t){
	print_single(t);
}

template<class T,class ...Args>
void print(const T&t,const Args&...args){
	print_single(t,2);
	print(args...);
}

string readString(){
	string s;
	cin>>s;
	return s;
}

template<class T>
T sq(const T& t){
	return t*t;
}

void YES(bool ex=true){
	cout<<"YES\n";
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}
void NO(bool ex=true){
	cout<<"NO\n";
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}
void Yes(bool ex=true){
	cout<<"Yes\n";
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}
void No(bool ex=true){
	cout<<"No\n";
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}
//#define CAPITAL
/*
void yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<"\n";
	#else
	cout<<"Yes"<<"\n";
	#endif
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}
void no(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<"\n";
	#else
	cout<<"No"<<"\n";
	#endif
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}*/
void possible(bool ex=true){
	#ifdef CAPITAL
	cout<<"POSSIBLE"<<"\n";
	#else
	cout<<"Possible"<<"\n";
	#endif
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}
void impossible(bool ex=true){
	#ifdef CAPITAL
	cout<<"IMPOSSIBLE"<<"\n";
	#else
	cout<<"Impossible"<<"\n";
	#endif
	if(ex)exit(0);
	#ifdef LOCAL
	cout.flush();
	#endif
}

constexpr ll ten(int n){
	return n==0?1:ten(n-1)*10;
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

int topbit(signed t){
	return t==0?-1:31-__builtin_clz(t);
}
int topbit(ll t){
	return t==0?-1:63-__builtin_clzll(t);
}
int topbit(ull t){
	return t==0?-1:63-__builtin_clzll(t);
}
int botbit(signed a){
	return a==0?32:__builtin_ctz(a);
}
int botbit(ll a){
	return a==0?64:__builtin_ctzll(a);
}
int botbit(ull a){
	return a==0?64:__builtin_ctzll(a);
}
int popcount(signed t){
	return __builtin_popcount(t);
}
int popcount(ll t){
	return __builtin_popcountll(t);
}
int popcount(ull t){
	return __builtin_popcountll(t);
}
int bitparity(ll t){
	return __builtin_parityll(t);
}
bool ispow2(int i){
	return i&&(i&-i)==i;
}
ll mask(int i){
	return (ll(1)<<i)-1;
}
ull umask(int i){
	return (ull(1)<<i)-1;
}
ll minp2(ll n){
	if(n<=1)return 1;
	else return ll(1)<<(topbit(n-1)+1);
}

bool inc(int a,int b,int c){
	return a<=b&&b<=c;
}

template<class t> void mkuni(vc<t>&v){
	sort(all(v));
	v.erase(unique(all(v)),v.ed);
}

ll rand_int(ll l, ll r) { //[l, r]
	//#ifdef LOCAL
	static mt19937_64 gen;
	/*#else
	static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
	#endif*/
	return uniform_int_distribution<ll>(l, r)(gen);
}

ll rand_int(ll k){ //[0,k)
	return rand_int(0,k-1);
}

template<class t>
void myshuffle(vc<t>&a){
	rep(i,si(a))swap(a[i],a[rand_int(0,i)]);
}

template<class t,class u>
int lwb(const vc<t>&v,const u&a){
	return lower_bound(all(v),a)-v.bg;
}
template<class t,class u>
bool bis(const vc<t>&v,const u&a){
	return binary_search(all(v),a);
}

vvc<int> readGraph(int n,int m){
	vvc<int> g(n);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		//sc.read(a,b);
		a--;b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	return g;
}

vvc<int> readTree(int n){
	return readGraph(n,n-1);
}

template<class t>
vc<t> presum(const vc<t>&a){
	vc<t> s(si(a)+1);
	rep(i,si(a))s[i+1]=s[i]+a[i];
	return s;
}
vc<ll> presum(const vi&a){
	vc<ll> s(si(a)+1);
	rep(i,si(a))s[i+1]=s[i]+a[i];
	return s;
}
//BIT で数列を管理するときに使う (CF850C)
template<class t>
vc<t> predif(vc<t> a){
	gnr(i,1,si(a))a[i]-=a[i-1];
	return a;
}
template<class t>
vvc<ll> imos(const vvc<t>&a){
	int n=si(a),m=si(a[0]);
	vvc<ll> b(n+1,vc<ll>(m+1));
	rep(i,n)rep(j,m)
		b[i+1][j+1]=b[i+1][j]+b[i][j+1]-b[i][j]+a[i][j];
	return b;
}

//verify してないや
void transvvc(int&n,int&m){
	swap(n,m);
}
template<class t,class... Args>
void transvvc(int&n,int&m,vvc<t>&a,Args&...args){
	assert(si(a)==n);
	vvc<t> b(m,vi(n));
	rep(i,n){
		assert(si(a[i])==m);
		rep(j,m)b[j][i]=a[i][j];
	}
	a.swap(b);
	transvvc(n,m,args...);
}
//CF854E
void rotvvc(int&n,int&m){
	swap(n,m);
}
template<class t,class... Args>
void rotvvc(int&n,int&m,vvc<t>&a,Args&...args){
	assert(si(a)==n);
	vvc<t> b(m,vi(n));
	rep(i,n){
		assert(si(a[i])==m);
		rep(j,m)b[m-1-j][i]=a[i][j];
	}
	a.swap(b);
	rotvvc(n,m,args...);
}

//ソートして i 番目が idx[i]
//CF850C
template<class t>
vi sortidx(const vc<t>&a){
	int n=si(a);
	vi idx(n);iota(all(idx),0);
	sort(all(idx),[&](int i,int j){return a[i]<a[j];});
	return idx;
}
//vs[i]=a[idx[i]]
//例えば sortidx で得た idx を使えば単にソート列になって返ってくる
//CF850C
template<class t>
vc<t> a_idx(const vc<t>&a,const vi&idx){
	int n=si(a);
	assert(si(idx)==n);
	vc<t> vs(n);
	rep(i,n)vs[i]=a[idx[i]];
	return vs;
}
//CF850C
vi invperm(const vi&p){
	int n=si(p);
	vi q(n);
	rep(i,n)q[p[i]]=i;
	return q;
}

template<class t,class s=t>
s SUM(const vc<t>&a){
	return accumulate(all(a),s(0));
}
template<class t,size_t K,class s=t>
s SUM(const array<t,K>&a){
	return accumulate(all(a),s(0));
}

template<class t>
t MAX(const vc<t>&a){
	return *max_element(all(a));
}

template<class t>
pair<t,int> MAXi(const vc<t>&a){
	auto itr=max_element(all(a));
	return mp(*itr,itr-a.bg);
}

template<class A>
auto MIN(const A&a){
	return *min_element(all(a));
}

template<class t>
pair<t,int> MINi(const vc<t>&a){
	auto itr=min_element(all(a));
	return mp(*itr,itr-a.bg);
}

vi vid(int n){
	vi res(n);iota(all(res),0);
	return res;
}

template<class S>
void soin(S&s){
	sort(all(s));
}

template<class S,class F>
void soin(S&s,F&&f){
	sort(all(s),forward<F>(f));
}

template<class S>
S soout(S s){
	soin(s);
	return s;
}

template<class S>
void rein(S&s){
	reverse(all(s));
}

template<class S>
S reout(S s){
	rein(s);
	return s;
}

template<class t,class u>
pair<t,u>&operator+=(pair<t,u>&a,pair<t,u> b){
	a.a+=b.a;a.b+=b.b;return a;}
template<class t,class u>
pair<t,u>&operator-=(pair<t,u>&a,pair<t,u> b){
	a.a-=b.a;a.b-=b.b;return a;}
template<class t,class u>
pair<t,u> operator+(pair<t,u> a,pair<t,u> b){return mp(a.a+b.a,a.b+b.b);}
template<class t,class u>
pair<t,u> operator-(pair<t,u> a,pair<t,u> b){return mp(a.a-b.a,a.b-b.b);}
template<class t,class u>
istream&operator>>(istream&is,pair<t,u>&a){
	return is>>a.a>>a.b;
}

template<class t>
t gpp(vc<t>&vs){
	assert(si(vs));
	t res=move(vs.back());
	vs.pop_back();
	return res;
}

template<class t,class u>
void pb(vc<t>&a,const vc<u>&b){
	a.insert(a.ed,all(b));
}

template<class t,class...Args>
vc<t> cat(vc<t> a,Args&&...b){
	(pb(a,forward<Args>(b)),...);
	return a;
}

template<class t,class u>
vc<t>& operator+=(vc<t>&a,u x){
	for(auto&v:a)v+=x;
	return a;
}

template<class t,class u>
vc<t> operator+(vc<t> a,u x){
	return a+=x;
}

template<class t>
vc<t> operator+(const vc<t>&a,const vc<t>&b){
	vc<t> c(max(si(a),si(b)));
	rep(i,si(a))c[i]+=a[i];
	rep(i,si(b))c[i]+=b[i];
	return c;
}

template<class t,class u>
vc<t>& operator-=(vc<t>&a,u x){
	for(auto&v:a)v-=x;
	return a;
}

template<class t,class u>
vc<t>& operator-(vc<t> a,u x){
	return a-=x;
}

template<class t,class u>
void remval(vc<t>&a,const u&v){
	a.erase(remove(all(a),v),a.ed);
}
//消した要素の個数を返してくれる
//UCUP 2-8-F
template<class t,class F>
int remif(vc<t>&a,F f){
	auto itr=remove_if(all(a),f);
	int res=a.ed-itr;
	a.erase(itr,a.ed);
	return res;
}

template<class VS,class u>
void fila(VS&vs,const u&a){
	fill(all(vs),a);
}

template<class t,class u>
int findid(const vc<t>&vs,const u&a){
	auto itr=find(all(vs),a);
	if(itr==vs.ed)return -1;
	else return itr-vs.bg;
}

template<class t>
void rtt(vc<t>&vs,int i){
	rotate(vs.bg,vs.bg+i,vs.ed);
}

//連結成分と頂点を一緒くたにした場合の木が tr で得られる
//連結成分たくさんとか多重辺ありとかでも動くはずだが,未確認
//連結成分 x の頂点リスト -> tr[n+x]
//孤立点は連結成分として処理されない
//s に biconnected components の個数が入る
//es にその biconnected componenents の辺のリストが入る
//辺の端点はもともとのグラフの頂点番号を使う
//VERIFY
//Petrozavodsk Camp 2020S Day2 C
//TCO2020 Wildcard Hard
//CF CodeTON Round I
template<class E>
struct articulation{
	const int n;
	const vvc<E>&g;
	vi vis,ord,low;
	int head,s;
	vvc<int> tr;
	vvc<pi> es;
	void ae(int a,int b){
		if(a==-1||b==-1)return;
		tr[a].pb(b);
		tr[b].pb(a);
	}
	void dfs(int v){
		assert(vis[v]==0);
		vis[v]=1;
		ord[v]=low[v]=head++;
		for(auto to:g[v]){
			if(vis[to]==0){
				dfs(to);
				chmin(low[v],low[to]);
			}else{
				chmin(low[v],ord[to]);
			}
		}
	}
	void dfs2(int v,int z){
		assert(vis[v]==1);
		vis[v]=2;
		ae(v,z);
		for(auto to:g[v])if(vis[to]==1){
			if(low[to]<ord[v]){
				dfs2(to,z);
			}else{
				int w=si(tr);
				tr.eb();
				es.eb();
				s++;
				ae(v,w);
				dfs2(to,w);
			}
		}else if(vis[to]==2){
			es[z-n].eb(v,to);
		}
		vis[v]=3;
	}
	articulation(const vvc<E>&gg):n(si(gg)),g(gg),
		vis(n,0),ord(n,-1),low(n,-1),head(0),s(0),tr(n){
		rep(i,n)if(vis[i]==0){
			dfs(i);
			dfs2(i,-1);
		}
	}
	//連結成分 i の辺情報を頂点番号を座標圧縮した上で返す
	pair<vi,vc<pi>> getg(int i){
		vi vs=tr[n+i];
		sort(all(vs));
		vc<pi> res=es[i];
		for(auto&[a,b]:res){
			a=lwb(vs,a);
			b=lwb(vs,b);
		}
		return mp(vs,res);
	}
};

bool dbg=false;

int R;

int sqR(int v){
	chmax(v,-(R+1));
	chmin(v,(R+1));
	return sq(v);
}

bool connected(pi a,pi b){
	return sqR(a.a-b.a)+sqR(a.b-b.b)<=sq(R);
}

const int K=4;
const int S=K*8;
struct N{
	int n=0,lcnt=0,ans=0;
	pi pos[S];
	vc<pi> g[S];
	int attach[S];
	void init(pi v){
		pos[0]=v;
		attach[0]=0;
		n=1;
		ans=1;
	}
	void toggle(){
		n^=1;
		ans^=1;
	}
	void ae(int a,int b,int c){
		g[a].eb(b,c);
		g[b].eb(a,c);
	}
	void copy_from(const N&x){
		n=x.n;
		lcnt=x.lcnt;
		ans=x.ans;
		rep(i,n)pos[i]=x.pos[i];
		rep(i,n){
			g[i].clear();
			g[i].insert(g[i].ed,all(x.g[i]));
		}
		rep(i,n)attach[i]=x.attach[i];
	}
	void checkdup(){
		rep(i,n){
			soin(g[i]);
			rep(j,si(g[i])-1)assert(g[i][j].a<g[i][j+1].a);
		}
	}
};

void mg(const N&l,const N&r,N&dst){
	if(l.n==0)return dst.copy_from(r);
	if(r.n==0)return dst.copy_from(l);
	
	static pi pos[S*2];
	static vc<pi> g[S*2];
	static int attach[S*2];
	int n=l.n+r.n;
	
	rep(i,l.n){
		pos[i]=l.pos[i];
		g[i].clear();
		for(auto [j,c]:l.g[i])
			g[i].eb(j,c);
		attach[i]=l.attach[i];
	}
	rep(i,r.n){
		pos[l.n+i]=r.pos[i];
		g[l.n+i].clear();
		for(auto [j,c]:r.g[i])
			g[l.n+i].eb(l.n+j,c);
		attach[l.n+i]=r.attach[i];
	}
	
	rng(i,max(l.n-(R-1),0),l.n)rng(j,l.n,min(l.n+(R-1),n)){
		if(connected(pos[i],pos[j])){
			g[i].eb(j,0);
			g[j].eb(i,0);
		}
	}
	
	static int vis[S*2],ord[S*2],low[S*2];
	int head,s;
	static vi tr[S*4];
	static int es[S*4],wei[S*4];
	auto ae=[&](int a,int b){
		if(a==-1||b==-1)return;
		tr[a].pb(b);
		tr[b].pb(a);
	};
	auto dfs=[&](auto self,int v)->void{
		assert(vis[v]==0);
		vis[v]=1;
		ord[v]=low[v]=head++;
		for(auto [to,num]:g[v]){
			if(vis[to]==0){
				self(self,to);
				chmin(low[v],low[to]);
			}else{
				chmin(low[v],ord[to]);
			}
		}
	};
	auto dfs2=[&](auto self,int v,int z)->void{
		assert(vis[v]==1);
		vis[v]=2;
		ae(v,z);
		for(auto [to,num]:g[v])if(vis[to]==1){
			if(low[to]<ord[v]){
				self(self,to,z);
			}else{
				int w=s++;
				tr[w].clear();
				es[w]=0;
				wei[w]=0;
				ae(v,w);
				self(self,to,w);
			}
		}else if(vis[to]==2){
			es[z]++;
			wei[z]+=num;
		}
		vis[v]=3;
	};
	rep(i,n)vis[i]=0;
	rep(i,n)ord[i]=-1;
	rep(i,n)low[i]=-1;
	head=0;
	s=n;
	rep(i,n)tr[i].clear();
	rep(i,n)if(vis[i]==0){
		dfs(dfs,i);
		dfs2(dfs2,i,-1);
	}
	
	dst.lcnt=l.lcnt+r.lcnt;
	
	rng(i,n,s)if(es[i]>=2){
		dst.lcnt+=wei[i];
		wei[i]=0;
	}
	
	int xmin=inf,xmax=-inf;
	rep(i,n){
		chmin(xmin,pos[i].a);
		chmax(xmax,pos[i].a);
	}
	
	static bool use[S*4];
	rep(i,s)use[i]=false;
	auto good=[&](int i){
		return i<n&&(pos[i].a<=xmin+(R-2)||xmax-(R-2)<=pos[i].a);
	};
	auto dfs3=[&](auto self,int v,int p)->bool{
		use[v]=good(v);
		for(auto to:tr[v])if(to!=p)
			use[v]|=self(self,to,v);
		return use[v];
	};
	rep(i,n)if(!use[i]&&good(i)){
		dfs3(dfs3,i,-1);
	}
	dst.ans=dst.lcnt;
	rep(i,n)if(si(tr[i])+attach[i]<=1&&!use[i])dst.lcnt++;
	rep(i,n)if(si(tr[i])+attach[i]<=1)dst.ans++;
	
	rep(i,s)if(use[i]){
		int c=remif(tr[i],[&](int v){return !use[v];});
		if(i<n){
			attach[i]+=c;
		}
	}
	static bool alive[S*2];
	rep(i,n)alive[i]=use[i]&&(good(i)||si(tr[i])>=3);
	rng(i,n,s)if(use[i]&&si(tr[i])>=3){
		for(auto j:tr[i])alive[j]=true;
	}
	
	static int idx[S*2];
	dst.n=0;
	rep(i,n)if(alive[i]){
		int j=dst.n++;
		idx[i]=j;
		dst.pos[j]=pos[i];
		dst.g[j].clear();
		dst.attach[j]=attach[i];
	}else{
		idx[i]=-1;
	}
	rng(i,n,s)if(use[i]&&si(tr[i])>=3){
		int pre=tr[i].back();
		for(auto j:tr[i]){
			assert(alive[pre]);
			assert(alive[j]);
			dst.ae(idx[pre],idx[j],0);
			pre=j;
		}
	}
	auto getnext=[&](int u,int v){
		if(tr[v][0]==u)return tr[v][1];
		else return tr[v][0];
	};
	rep(i,n)if(alive[i]){
		for(auto to:tr[i])if(si(tr[to])==2){
			int u=i,v=to,sum=0;
			while(1){
				if(v<n){
					if(alive[v])break;
					sum+=(attach[v]==0);
				}else{
					sum+=wei[v];
				}
				assert(si(tr[v])==2);
				int nx=getnext(u,v);
				u=v;
				v=nx;
			}
			assert(alive[i]);
			assert(alive[v]);
			if(idx[i]<idx[v])dst.ae(idx[i],idx[v],sum);
		}
	}
}

const int vmax=20;
const int nqmax=15;
const int Rmax=5;
vi getvals(int n){
	set<int> s;
	while(si(s)<n){
		s.insert(rand_int(0,vmax));
	}
	vi res(all(s));
	myshuffle(res);
	return res;
}

void slv(){
	int n;
	if(!dbg){
		cin>>n;
		if(n<0)dbg=true;
	}
	if(dbg){
		n=rand_int(1,nqmax);
	}
	
	if(dbg){
		R=rand_int(2,Rmax);
	}else{
		cin>>R;
	}
	
	vc<pi> raw(n);
	if(dbg){
		vi xs=getvals(n);
		vi ys=getvals(n);
		rep(i,n)raw[i]=pi(xs[i],ys[i]);
	}else{
		rep(i,n)cin>>raw[i];
	}
	vi idx=sortidx(raw);
	vi xdi=invperm(idx);
	
	vc<bool> avail(n,true);
	
	int s=minp2(n);
	vc<N> buf(s*2);
	rep(i,n){
		buf[s+i].init(raw[idx[i]]);
	}
	
	auto upd=[&](int i){
		mg(buf[i*2],buf[i*2+1],buf[i]);
	};
	gnr(i,1,s)upd(i);
	
	int q;
	if(dbg){
		q=rand_int(1,nqmax);
	}else{
		cin>>q;
	}
	int last=0;
	rep(_,q){
		int k;
		if(dbg){
			k=rand_int(n);
		}else{
			cin>>k;
			k^=last;
			k--;
		}
		if(!inc(0,k,n-1))exit(0);
		assert(inc(0,k,n-1));
		dmp(k);
		
		if(dbg){
			avail[k]=!avail[k];
		}
		
		k=xdi[k];
		k+=s;
		buf[k].toggle();
		while(k>>=1)upd(k);
		
		print(buf[1].ans);
		last=buf[1].ans;
		
		if(dbg){
			vc<pi> ls;
			rep(i,n)if(avail[i])ls.pb(raw[i]);
			vvc<int> g(si(ls));
			rep(i,si(ls))rng(j,i+1,si(ls))if(connected(ls[i],ls[j])){
				g[i].pb(j);
				g[j].pb(i);
			}
			articulation<int> art(g);
			int god=0;
			rep(i,si(ls))if(si(art.tr[i])<=1)god++;
			
			dmp2(god,buf[1].ans);
			assert(god==buf[1].ans);
		}
	}
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	slv();
	
	if(dbg){
		while(1)slv();
	}else{
		//int t;cin>>t;rep(_,t)
	}
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3612kb

input:

5 3
3 2
4 1
5 4
1 3
2 5
6
1
6
0
3
0
1

output:

4
3
2
2
2
3

result:

ok 6 numbers

Test #2:

score: 0
Accepted
time: 41ms
memory: 3676kb

input:

20 2
13 9
7 15
10 6
15 12
12 11
14 18
18 19
6 4
2 16
3 10
1 8
4 14
8 3
9 17
19 1
11 13
16 2
20 5
17 20
5 7
100000
1
18
23
3
29
1
19
31
19
22
26
4
26
9
3
11
5
7
12
2
30
26
6
25
1
0
24
29
6
28
12
4
29
5
13
8
14
25
8
29
13
7
10
15
2
12
1
13
4
14
5
10
12
25
30
0
7
1
28
1
4
10
14
14
12
13
11
9
4
22
15
23...

output:

19
20
19
18
17
18
17
16
17
16
15
14
13
12
13
12
11
10
11
12
11
10
11
12
11
12
13
12
13
14
13
12
11
12
13
12
13
12
13
14
13
12
11
10
9
10
9
10
9
10
9
10
11
10
11
12
11
12
11
10
11
10
9
8
9
8
7
6
5
4
5
6
5
6
7
8
9
10
11
12
11
12
11
10
9
10
11
10
11
12
11
12
13
12
13
14
13
14
13
12
11
10
11
10
9
10
11
...

result:

ok 100000 numbers

Test #3:

score: 0
Accepted
time: 69ms
memory: 3708kb

input:

20 3
19 1
17 19
14 15
8 13
7 2
11 20
13 10
20 7
10 14
4 8
2 12
5 9
18 16
6 3
16 6
1 4
3 17
12 18
9 11
15 5
100000
1
19
1
22
0
3
2
29
21
23
24
7
21
11
11
31
1
11
30
7
10
15
15
4
7
30
1
10
2
4
13
9
31
12
8
12
24
1
11
4
1
11
7
8
26
26
9
27
4
0
8
21
28
24
13
7
12
0
4
13
14
1
10
5
13
0
3
11
10
0
28
13
10...

output:

18
19
18
18
19
18
19
18
17
16
15
16
15
15
15
14
13
14
15
14
14
13
12
13
12
11
12
11
11
12
13
12
11
12
13
12
11
10
11
10
9
10
9
8
9
10
9
8
7
6
7
8
9
8
9
8
7
8
9
10
9
8
7
8
7
6
7
6
7
8
7
8
7
6
5
6
7
8
9
8
7
8
9
8
9
8
9
9
10
11
10
9
8
8
9
10
9
8
9
8
9
8
9
10
9
10
11
12
11
10
11
10
11
10
9
10
11
10
9
10...

result:

ok 100000 numbers

Test #4:

score: 0
Accepted
time: 135ms
memory: 3676kb

input:

20 4
11 16
12 9
20 8
9 5
10 13
15 7
17 11
5 4
13 19
19 10
18 2
7 15
8 3
4 20
3 17
6 12
16 6
2 18
1 14
14 1
100000
1
15
7
10
2
31
4
2
3
2
31
1
24
7
9
28
1
30
13
26
24
7
15
12
15
3
14
30
8
6
13
10
22
10
24
25
5
0
15
1
12
24
26
15
13
0
13
1
5
25
24
0
5
14
25
5
24
14
11
10
27
14
13
12
2
13
25
29
10
2
3
...

output:

14
13
13
12
11
10
11
11
11
11
12
11
11
12
12
11
12
11
11
10
11
12
11
12
12
11
10
9
10
9
8
7
8
9
8
9
10
10
9
10
10
9
10
11
11
10
9
8
9
9
8
9
9
10
9
9
10
10
9
8
9
8
10
10
10
11
12
12
11
10
11
10
9
10
11
10
9
8
9
8
9
10
10
11
10
9
8
9
9
10
11
10
11
10
9
8
9
8
9
8
7
6
5
6
5
6
7
8
9
10
9
10
11
10
9
10
11...

result:

ok 100000 numbers

Test #5:

score: 0
Accepted
time: 182ms
memory: 3636kb

input:

20 5
1 20
20 15
16 9
5 2
10 18
9 10
17 5
7 12
14 4
12 16
8 11
18 14
6 3
19 8
15 7
2 6
3 13
13 19
4 1
11 17
100000
1
19
7
22
1
1
17
12
4
31
29
7
1
29
4
8
30
28
0
0
30
4
15
30
13
25
3
15
5
11
2
0
3
25
12
5
9
27
7
14
9
14
8
31
8
5
7
6
7
25
6
12
15
0
6
2
25
6
14
9
7
0
2
25
6
11
14
8
5
7
26
4
13
25
23
15...

output:

18
19
18
16
16
16
15
14
13
12
12
11
12
12
12
14
13
12
11
12
13
12
13
12
13
14
13
12
13
12
11
10
9
10
11
12
11
10
11
12
11
12
11
10
11
10
9
8
9
10
11
10
9
9
9
10
11
11
12
11
10
9
8
9
9
8
7
7
8
8
7
7
8
7
7
8
9
8
9
10
9
10
11
10
10
9
10
12
13
12
11
12
13
12
13
12
13
14
13
12
13
12
11
10
11
10
11
10
9
8...

result:

ok 100000 numbers

Test #6:

score: 0
Accepted
time: 51ms
memory: 3564kb

input:

50 2
29 14
34 42
4 15
7 8
16 5
19 31
3 32
44 50
22 35
39 26
1 16
2 29
5 48
40 21
35 2
8 18
14 22
38 17
21 13
37 44
48 23
12 19
46 43
28 34
9 38
10 37
49 25
42 41
23 3
50 4
43 1
24 40
6 36
17 46
47 20
31 7
27 24
41 9
25 10
13 47
18 33
32 6
20 27
11 12
26 28
36 30
33 39
15 11
30 49
45 45
100000
1
48
6...

output:

49
50
49
48
47
46
45
44
43
42
41
40
39
38
39
38
37
36
35
34
35
36
35
34
33
32
31
32
31
30
31
32
31
32
31
32
31
32
31
30
31
32
31
30
31
32
31
30
31
30
29
28
27
28
27
26
25
24
23
22
21
20
19
20
19
18
19
20
21
22
23
22
23
24
25
26
25
26
27
28
29
28
29
28
27
28
27
28
29
30
29
28
27
26
27
28
27
26
25
26
...

result:

ok 100000 numbers

Test #7:

score: 0
Accepted
time: 78ms
memory: 3592kb

input:

50 3
6 18
21 19
40 21
1 35
37 16
28 2
13 15
31 8
4 49
30 3
41 5
33 23
32 43
23 37
2 33
8 12
45 42
11 28
20 22
39 38
24 31
5 44
12 24
50 41
49 46
18 50
27 40
16 14
47 32
26 45
43 6
9 30
36 1
48 34
15 10
38 48
17 17
19 25
35 7
14 26
10 36
29 39
46 11
7 9
44 13
22 47
42 29
25 20
3 4
34 27
100000
1
48
5...

output:

49
50
49
48
47
46
45
44
43
42
41
40
39
38
37
36
35
34
33
32
31
32
31
30
29
28
29
28
27
26
27
28
29
30
29
30
29
28
29
30
29
28
29
28
27
28
27
26
27
26
27
28
29
30
29
30
29
28
27
28
29
30
31
32
31
32
33
32
31
30
31
32
33
32
33
32
31
30
29
28
27
28
29
30
31
32
31
32
33
32
31
30
29
30
29
28
27
28
27
26
...

result:

ok 100000 numbers

Test #8:

score: 0
Accepted
time: 129ms
memory: 3632kb

input:

50 4
49 43
41 49
10 19
45 22
11 23
8 37
35 40
29 18
1 20
48 10
13 30
47 25
26 8
22 26
12 5
15 15
6 11
18 33
9 45
46 28
28 29
14 12
31 3
32 48
33 47
39 32
40 44
2 41
17 9
30 7
19 14
37 50
42 17
16 13
7 6
5 46
21 36
38 16
27 35
34 21
43 42
20 31
25 24
36 38
4 2
24 4
23 1
3 39
44 27
50 34
100000
1
46
3...

output:

47
48
47
46
45
44
43
42
41
40
40
39
40
40
39
38
39
38
39
38
37
36
35
34
35
34
33
34
35
34
34
35
34
35
34
35
34
33
34
35
34
35
34
33
34
35
35
36
36
37
36
35
34
35
34
33
34
33
33
32
32
31
30
29
28
29
30
31
32
31
30
31
31
30
31
30
29
30
29
28
28
29
28
29
30
29
28
27
28
27
28
27
26
25
26
27
26
27
26
27
...

result:

ok 100000 numbers

Test #9:

score: 0
Accepted
time: 181ms
memory: 3604kb

input:

50 5
35 38
34 18
48 41
28 40
17 49
36 45
45 25
10 34
41 27
11 4
37 9
8 28
9 20
38 3
33 8
26 46
50 13
18 26
24 36
27 35
22 44
30 19
43 33
32 22
39 16
6 17
15 14
29 23
21 39
14 2
7 15
20 31
47 48
12 47
31 5
40 7
2 10
3 50
46 42
19 32
25 12
23 37
16 6
44 11
49 29
13 24
1 43
42 21
4 30
5 1
100000
1
42
5...

output:

43
44
43
42
42
40
39
40
39
39
38
38
37
37
36
35
34
35
35
35
34
35
34
33
33
32
33
32
31
30
30
29
28
27
26
24
23
22
23
24
24
23
24
25
24
25
26
28
27
28
27
28
27
26
25
26
27
26
27
28
29
29
28
27
27
28
27
28
28
29
28
27
28
27
26
25
26
25
26
27
27
28
29
28
27
26
26
27
28
29
28
27
28
27
26
27
28
29
28
27
...

result:

ok 100000 numbers

Test #10:

score: 0
Accepted
time: 82ms
memory: 5508kb

input:

1000 2
363 487
540 561
634 850
775 637
151 524
816 148
566 512
514 613
962 283
849 199
565 918
736 388
570 593
409 2
96 153
687 121
161 979
549 715
672 656
219 684
171 127
589 548
493 567
141 651
187 328
298 452
406 438
568 790
554 65
302 45
81 70
839 740
557 538
920 746
471 36
340 951
484 989
941 8...

output:

998
999
998
997
996
995
994
993
992
991
990
989
988
987
986
985
984
983
982
981
980
979
978
977
976
975
974
973
972
971
970
969
968
967
966
965
964
963
962
961
960
959
958
957
956
955
954
953
952
951
950
949
948
947
946
945
944
943
942
941
940
939
938
937
936
935
934
933
932
931
930
929
928
927
926
...

result:

ok 100000 numbers

Test #11:

score: 0
Accepted
time: 114ms
memory: 5508kb

input:

1000 3
517 150
194 215
148 477
212 14
174 203
861 91
673 370
784 563
418 869
479 416
154 815
409 873
768 699
357 969
220 990
923 578
333 376
472 598
803 141
434 942
961 310
22 536
636 133
59 767
250 993
58 489
354 828
260 31
838 549
71 443
102 791
494 723
127 348
864 750
110 819
165 190
382 864
537 ...

output:

999
1000
999
998
997
996
995
994
993
992
991
990
989
988
987
986
985
984
983
982
981
980
979
978
977
976
975
974
973
972
971
970
969
968
967
966
965
964
963
962
961
960
959
958
957
956
955
954
953
952
951
950
949
948
947
946
945
944
943
942
941
940
939
938
937
936
935
934
933
932
931
930
929
928
927...

result:

ok 100000 numbers

Test #12:

score: 0
Accepted
time: 132ms
memory: 5544kb

input:

1000 4
457 784
65 423
237 242
432 156
689 853
944 457
671 118
631 408
746 95
312 231
279 13
596 361
8 355
187 144
827 951
50 635
260 114
540 915
209 722
166 362
668 552
373 708
675 802
601 521
591 484
2 496
426 124
826 883
44 235
904 931
651 606
205 392
731 704
383 210
58 675
998 837
431 959
261 108...

output:

999
1000
999
998
997
996
995
994
993
992
991
990
989
988
987
986
985
984
983
982
981
980
979
978
977
976
975
974
973
972
971
970
969
970
969
968
967
966
965
964
963
962
961
960
959
958
957
956
955
954
953
952
951
950
949
948
947
946
945
944
943
942
941
940
939
938
937
936
935
934
933
932
931
930
929...

result:

ok 100000 numbers

Test #13:

score: 0
Accepted
time: 181ms
memory: 5560kb

input:

1000 5
824 740
70 49
569 650
658 101
621 410
968 515
762 861
18 598
681 553
163 916
994 72
507 450
972 205
975 936
572 428
264 717
609 104
599 226
564 623
415 439
814 204
802 127
329 52
562 679
557 262
179 719
403 113
804 41
558 631
847 386
983 880
214 958
243 531
202 81
649 301
149 203
727 710
44 2...

output:

997
998
997
996
995
994
993
992
991
990
989
988
987
986
985
984
983
982
981
980
979
978
977
976
975
974
973
972
971
970
969
968
967
966
965
966
965
964
963
962
961
960
959
958
957
956
955
954
953
952
951
950
949
948
947
946
945
944
945
944
943
942
943
942
941
940
939
938
937
936
937
936
935
934
933
...

result:

ok 100000 numbers

Test #14:

score: 0
Accepted
time: 315ms
memory: 303812kb

input:

100000 2
91296 50114
28944 8403
70352 98320
16429 29251
26200 13702
50779 35655
38633 52428
31032 38699
60664 37630
45533 30053
99857 36803
55392 50705
76406 88062
84487 52498
50872 77265
28942 85013
15654 10854
82071 14053
77888 85979
19240 98837
30632 45191
28143 6136
46776 58542
8008 78078
23122 ...

output:

99999
100000
99999
99998
99997
99996
99995
99994
99993
99992
99991
99990
99989
99988
99987
99986
99985
99984
99983
99982
99981
99980
99979
99978
99977
99976
99975
99974
99973
99972
99971
99970
99969
99968
99967
99966
99965
99964
99963
99962
99961
99960
99959
99958
99957
99956
99955
99954
99953
99952...

result:

ok 100000 numbers

Test #15:

score: 0
Accepted
time: 300ms
memory: 303792kb

input:

100000 2
40560 7110
65376 22740
79341 32718
8432 31878
32867 68436
51787 12631
53305 26133
73360 2964
93665 18883
60487 30092
63815 44811
42338 80369
13114 10887
62660 51217
99123 50052
35641 59216
82791 29814
55738 39348
7152 64607
74930 89533
38299 81094
2855 5163
42764 99905
34965 51842
82772 347...

output:

99999
100000
99999
99998
99997
99996
99995
99994
99993
99992
99991
99990
99989
99988
99987
99986
99985
99984
99983
99982
99981
99980
99979
99978
99977
99976
99975
99974
99973
99972
99971
99970
99969
99968
99967
99966
99965
99964
99963
99962
99961
99960
99959
99958
99957
99956
99955
99954
99953
99952...

result:

ok 100000 numbers

Test #16:

score: 0
Accepted
time: 383ms
memory: 303868kb

input:

100000 3
6413 65888
45012 67622
11794 6947
39451 78496
64989 90093
92404 55323
39346 13584
64808 28427
21872 41493
33788 67947
35928 16790
7984 58715
64503 78840
33040 36007
68881 32140
40439 31240
47878 89378
17674 79425
23552 93823
17861 67728
87146 68837
62962 74497
50615 11106
11006 91830
95877 ...

output:

99999
100000
99999
99998
99997
99996
99995
99994
99993
99992
99991
99990
99989
99988
99987
99986
99985
99984
99983
99982
99981
99980
99979
99978
99977
99978
99977
99976
99975
99974
99973
99972
99971
99970
99969
99968
99967
99966
99965
99964
99963
99962
99961
99960
99959
99958
99957
99956
99955
99954...

result:

ok 100000 numbers

Test #17:

score: 0
Accepted
time: 394ms
memory: 303880kb

input:

100000 3
25893 78634
73849 99870
37670 20958
62533 38840
71946 30495
82362 37584
89551 25312
90590 72229
5773 36576
30946 53042
94834 17820
23893 66515
52066 43325
24261 95063
88191 20001
92823 78683
3297 90692
49301 69272
81881 3306
78029 28796
55207 17177
45139 417
14576 12092
75757 31504
63979 53...

output:

99999
100000
99999
99998
99997
99996
99995
99994
99993
99992
99991
99990
99989
99988
99987
99986
99985
99984
99983
99982
99981
99980
99979
99978
99977
99976
99975
99974
99973
99972
99971
99970
99969
99968
99967
99966
99965
99964
99963
99962
99961
99960
99959
99958
99957
99956
99955
99954
99953
99952...

result:

ok 100000 numbers

Test #18:

score: 0
Accepted
time: 492ms
memory: 303840kb

input:

100000 4
46193 32830
41091 8689
52130 3939
99646 73315
8655 8774
19596 83824
71756 64126
76757 38981
72712 13228
97831 97977
39222 1464
20922 66822
80416 71024
99803 20310
74450 74062
76103 62964
41231 31085
12629 93669
71731 77085
15081 28041
84247 81861
96759 5288
43573 53886
55822 68307
19224 329...

output:

99999
100000
99999
99998
99997
99996
99995
99994
99993
99992
99991
99990
99989
99988
99987
99986
99985
99984
99983
99982
99981
99980
99979
99978
99977
99976
99975
99974
99973
99972
99971
99970
99969
99968
99967
99966
99965
99964
99963
99962
99961
99960
99959
99958
99957
99956
99955
99954
99953
99952...

result:

ok 100000 numbers

Test #19:

score: 0
Accepted
time: 489ms
memory: 303784kb

input:

100000 4
56720 21488
15848 55832
98829 25714
17970 17220
88325 19138
8069 74430
72674 26443
46604 31030
50344 89159
86334 72007
19619 7362
78205 92195
38714 43467
60573 239
69882 97307
61334 16976
87104 63944
82180 77836
95387 55348
57540 12388
33894 4720
79497 7034
85865 51109
68821 43934
16274 649...

output:

99999
100000
99999
99998
99997
99996
99995
99994
99993
99992
99991
99990
99989
99988
99987
99986
99985
99984
99983
99982
99981
99980
99979
99978
99977
99976
99975
99974
99973
99972
99971
99970
99969
99968
99967
99966
99965
99964
99963
99962
99961
99960
99959
99958
99957
99956
99955
99954
99953
99952...

result:

ok 100000 numbers

Test #20:

score: 0
Accepted
time: 576ms
memory: 303840kb

input:

100000 5
39903 99245
69198 28614
43068 74408
35388 65387
31120 63757
30534 21462
39717 52278
53523 50480
41141 60787
6288 94932
47534 51766
99095 9557
21732 764
17977 65251
55016 34597
90213 73835
78451 10378
27097 79895
59286 80129
32662 45205
72629 85088
16469 35845
6332 18101
7711 49477
54366 100...

output:

99999
100000
99999
99998
99997
99996
99995
99994
99993
99992
99991
99990
99989
99988
99987
99986
99985
99984
99983
99982
99981
99980
99979
99978
99977
99976
99975
99974
99973
99972
99971
99970
99969
99968
99967
99966
99965
99964
99963
99962
99961
99960
99959
99958
99957
99956
99955
99954
99953
99952...

result:

ok 100000 numbers

Test #21:

score: 0
Accepted
time: 568ms
memory: 303876kb

input:

100000 5
92019 92313
16973 82324
76369 55116
64732 34182
14323 80708
93011 71055
60182 75153
92332 39695
70950 97606
17074 18174
59762 8970
93858 2703
32266 4415
4366 21987
29646 74890
41 30074
5924 82342
37293 25026
15608 30837
46585 722
30348 67534
88022 48191
50771 29840
18359 99097
91855 39268
9...

output:

99999
100000
99999
99998
99997
99996
99995
99994
99993
99992
99991
99990
99989
99988
99987
99986
99985
99984
99983
99982
99981
99980
99979
99978
99977
99976
99975
99974
99973
99972
99971
99970
99969
99968
99967
99966
99965
99964
99963
99962
99961
99960
99959
99958
99957
99956
99955
99954
99953
99952...

result:

ok 100000 numbers

Test #22:

score: 0
Accepted
time: 403ms
memory: 310136kb

input:

100000 2
77207 77207
46937 46937
60884 60884
42545 42545
472 472
10482 10482
54456 54456
63273 63273
63043 63043
73838 73838
37406 37406
39547 39547
26775 26775
29142 29142
88552 88552
66160 66160
33850 33850
39204 39204
7858 7858
70586 70586
73602 73602
95289 95289
80494 80494
82084 82084
37359 373...

output:

4
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
64
66
68
70
72
74
76
78
80
82
84
86
88
90
92
94
96
98
100
102
104
106
108
110
112
114
116
118
120
122
124
126
128
130
132
134
136
138
140
142
144
146
148
150
152
154
156
158
160
162
164
166
168
170
172
174
176...

result:

ok 100000 numbers

Test #23:

score: 0
Accepted
time: 389ms
memory: 309872kb

input:

100000 2
11585 11585
70809 70809
60837 60837
26543 26543
70928 70928
8161 8161
90035 90035
94585 94585
40115 40115
74891 74891
95849 95849
16127 16127
61639 61639
61827 61827
81775 81775
30137 30137
83459 83459
16071 16071
65340 65340
47059 47059
73667 73667
29535 29535
63639 63639
54825 54825
14955...

output:

124
122
124
126
128
130
132
134
136
138
140
142
144
146
148
150
152
154
156
158
160
162
164
166
168
170
172
174
176
178
180
182
184
186
188
190
192
194
196
198
200
202
204
206
208
210
212
214
216
218
220
222
224
226
228
230
232
234
236
238
240
242
244
246
248
250
252
254
256
258
260
262
264
266
268
...

result:

ok 100000 numbers

Test #24:

score: 0
Accepted
time: 367ms
memory: 309868kb

input:

100000 2
31971 31971
52171 52171
23407 23407
12697 12697
27102 27102
7013 7013
79325 79325
72915 72915
37570 37570
45030 45030
31214 31214
73487 73487
65848 65848
42731 42731
14748 14748
96624 96624
38254 38254
34714 34714
26141 26141
9267 9267
38406 38406
49640 49640
50502 50502
94089 94089
96302 9...

output:

1196
1194
1196
1198
1200
1202
1204
1206
1208
1210
1212
1214
1216
1218
1220
1222
1224
1226
1228
1230
1232
1234
1236
1238
1240
1242
1244
1246
1246
1248
1250
1250
1252
1254
1256
1258
1260
1262
1264
1266
1268
1270
1272
1274
1276
1278
1280
1282
1284
1286
1288
1290
1292
1294
1296
1298
1300
1302
1304
1306
...

result:

ok 100000 numbers

Test #25:

score: 0
Accepted
time: 376ms
memory: 308800kb

input:

100000 2
64216 64216
48189 48189
48464 48464
28611 28611
51122 51122
2243 2243
18878 18878
32979 32979
28804 28804
28617 28617
47496 47496
92672 92672
71881 71881
14819 14819
67331 67331
52481 52481
61832 61832
67694 8248
83292 83292
85587 85587
55632 55632
41816 41816
25243 25243
74425 74425
81747 ...

output:

11299
11297
11299
11301
11303
11305
11307
11309
11308
11310
11312
11314
11316
11318
11317
11319
11321
11323
11324
11326
11328
11330
11332
11334
11336
11337
11339
11341
11343
11345
11346
11348
11347
11349
11350
11352
11354
11353
11354
11356
11358
11360
11362
11364
11366
11367
11369
11371
11373
11375
...

result:

ok 100000 numbers

Test #26:

score: 0
Accepted
time: 706ms
memory: 309928kb

input:

100000 3
20317 95007
16826 16767
80427 79976
80647 80191
21059 72251
82421 81942
70218 69749
88429 87982
7962 7967
20859 20789
30591 80659
85567 18726
51980 51693
79065 78644
297 296
17487 17420
11041 68153
35083 35026
21258 21182
33670 33613
8475 8456
82963 82492
47419 37529
63245 10719
9614 72136
...

output:

33538
33539
33538
33540
33542
33541
33540
33542
33544
33546
33545
33547
33546
33548
33550
33549
33548
33547
33549
33551
33553
33552
33551
33553
33555
33557
33559
33558
33560
33562
33564
33563
33565
33567
33569
33571
33570
33572
33574
33573
33575
33574
33576
33578
33577
33579
33581
33580
33582
33584
...

result:

ok 100000 numbers

Test #27:

score: 0
Accepted
time: 692ms
memory: 309964kb

input:

100000 3
69444 69074
61530 61298
40792 40603
11619 11501
57948 433
76548 76094
70488 11712
81619 44664
91904 91320
61968 61733
44773 44572
53614 53392
89479 88936
7517 7413
18421 18250
95920 13129
7006 69626
21613 21472
10709 10578
50324 50187
86961 48178
40146 39962
70310 64597
23052 22928
75161 82...

output:

33621
33619
33618
33617
33619
33621
33623
33625
33624
33626
33625
33624
33626
33628
33627
33629
33628
33630
33629
33631
33630
33629
33631
33633
33632
33634
33633
33635
33637
33636
33638
33640
33642
33641
33643
33645
33647
33646
33648
33650
33652
33654
33656
33655
33657
33659
33658
33657
33656
33655
...

result:

ok 100000 numbers

Test #28:

score: 0
Accepted
time: 681ms
memory: 309136kb

input:

100000 3
13139 13017
2719 2638
92938 92194
56298 55787
4579 4480
66582 66020
35440 84499
96324 38062
9047 25072
61595 15340
77782 18312
28163 27996
42541 42178
79827 14149
33453 33167
13889 13779
8562 8417
71173 70576
85650 84935
34499 26459
53024 52557
42058 41725
47193 37856
13829 92542
93017 9226...

output:

41160
41158
41160
41162
41164
41166
41165
41164
41166
41168
41167
41169
41171
41173
41175
41177
41177
41179
41181
41183
41185
41184
41183
41185
41184
41186
41185
41187
41189
41188
41187
41189
41191
41193
41194
41196
41198
41199
41201
41203
41205
41207
41209
41208
41207
41209
41211
41210
41212
41211
...

result:

ok 100000 numbers

Test #29:

score: 0
Accepted
time: 871ms
memory: 307548kb

input:

100000 5
60163 59847
34650 25470
30480 25469
13501 23993
60201 60648
63866 46172
40003 84583
44918 44635
20260 20160
40726 39091
47869 71308
52746 48299
6414 4733
73632 34745
79070 40509
12858 98305
88241 2161
76016 47237
50246 49905
5679 5656
50909 67788
85373 41205
64108 40765
87808 98165
2719 211...

output:

71494
71492
71491
71490
71489
71488
71490
71489
71488
71487
71486
71485
71484
71483
71482
71481
71480
71479
71481
71480
71479
71478
71477
71476
71475
71477
71476
71475
71474
71473
71472
71471
71473
71475
71474
71473
71472
71471
71470
71469
71468
71467
71469
71468
71467
71466
71468
71467
71466
71465
...

result:

ok 100000 numbers

Test #30:

score: 0
Accepted
time: 926ms
memory: 307548kb

input:

100000 5
60823 60783
31890 76602
47922 72516
73749 58715
74657 74522
3224 3267
61128 61073
97122 19008
47 1053
67685 91215
61215 46895
97835 60270
36972 61653
89917 89712
42827 72692
8179 14885
21718 45021
17420 49132
60345 19598
77918 77771
95487 34627
52999 1392
18331 18372
52870 63575
37302 37376...

output:

71839
71837
71836
71838
71837
71836
71835
71834
71833
71832
71831
71830
71832
71834
71833
71832
71834
71836
71835
71834
71836
71835
71837
71836
71838
71837
71839
71838
71837
71836
71838
71837
71836
71838
71837
71839
71841
71840
71839
71838
71837
71839
71838
71837
71839
71838
71837
71839
71838
71840
...

result:

ok 100000 numbers

Test #31:

score: 0
Accepted
time: 708ms
memory: 305180kb

input:

100000 5
85411 86413
97618 97173
44276 46904
84857 84503
53210 91707
19276 93732
82359 30468
66877 49469
28513 87724
628 71927
41285 11910
24667 11280
77010 69650
2112 45161
9005 9029
66397 86851
88468 90231
54288 12486
53616 92939
46329 17378
64699 67773
78267 28443
84142 83797
92465 17119
45945 90...

output:

91441
91442
91441
91440
91439
91438
91437
91438
91437
91437
91437
91436
91435
91434
91433
91432
91431
91430
91429
91428
91427
91426
91425
91424
91423
91422
91421
91420
91419
91418
91419
91418
91417
91416
91415
91417
91416
91415
91414
91413
91412
91411
91410
91409
91408
91407
91406
91405
91404
91403
...

result:

ok 100000 numbers

Test #32:

score: 0
Accepted
time: 615ms
memory: 310148kb

input:

99997 3
67590 82406
60530 89466
84847 34848
32213 17787
82185 32186
54727 4728
68597 18598
46130 96129
8918 58917
19050 69049
9723 40277
56193 6194
42181 7819
62914 87082
81459 31460
11831 38169
78712 71284
62543 12544
95391 45392
90958 59038
87783 37784
62557 12558
27920 77919
13365 36635
47351 264...

output:

2
99997
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
64
66
68
70
72
74
76
78
80
82
84
86
88
90
92
94
96
98
100
102
104
106
108
110
112
114
116
118
120
122
124
126
128
130
132
134
136
138
140
142
144
146
148
150
152
154
156
158
160
162
164
166
168
170
172
1...

result:

ok 100000 numbers

Test #33:

score: 0
Accepted
time: 1433ms
memory: 313100kb

input:

99997 5
81259 31260
30519 19481
79101 29102
86385 36386
1649 48351
7773 42227
5507 44493
22071 27929
65554 84442
33662 83661
95405 45406
68484 81512
36461 13539
46729 3271
25482 75481
52705 2706
96991 46992
80681 30682
8739 41261
29534 79533
18272 68271
3816 53815
36088 86087
65080 84916
74562 75434...

output:

10
99997
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
64
66
68
70
72
74
76
78
80
82
84
86
88
90
92
94
96
98
100
102
104
106
108
110
112
114
116
118
120
122
124
126
128
130
132
134
136
138
140
142
144
146
148
150
152
154
156
158
160
162
164
166
168
170
172
174
176
...

result:

ok 100000 numbers

Test #34:

score: 0
Accepted
time: 470ms
memory: 303880kb

input:

100000 5
93169 79315
36558 97982
17449 85170
40481 10923
313 24047
80168 48318
89082 90605
33389 24019
40099 16077
15821 27336
81363 74950
6697 98931
36942 78640
35876 12781
28408 47329
48460 60363
43667 49262
91591 89685
41577 28214
36879 34861
30131 42008
44578 31739
48272 32432
42781 27934
45247 ...

output:

99989
99988
99987
99986
99985
99984
99983
99982
99981
99980
99979
99978
99977
99976
99975
99974
99973
99972
99971
99970
99969
99968
99967
99966
99965
99964
99963
99962
99961
99960
99959
99958
99957
99956
99955
99954
99953
99952
99951
99950
99949
99948
99947
99946
99945
99944
99943
99942
99941
99940
...

result:

ok 100000 numbers

Test #35:

score: 0
Accepted
time: 481ms
memory: 303784kb

input:

100000 5
35508 97605
79710 22464
55840 92741
44402 63260
73228 22044
60501 60835
74314 42872
28531 64519
42993 1179
52014 1515
70006 36849
73768 99306
80827 65768
67473 64529
93022 98538
84624 91776
50552 60014
25685 77342
19544 80312
3524 27538
12427 38331
23575 5953
41383 89947
23087 7704
70016 52...

output:

99979
99978
99977
99976
99975
99974
99973
99972
99971
99970
99969
99968
99967
99966
99965
99964
99963
99962
99961
99960
99959
99958
99957
99956
99955
99954
99953
99952
99951
99950
99949
99948
99947
99946
99945
99944
99943
99942
99941
99940
99939
99938
99937
99936
99935
99934
99933
99932
99931
99930
...

result:

ok 100000 numbers

Test #36:

score: 0
Accepted
time: 482ms
memory: 303876kb

input:

100000 5
88304 69827
45437 13125
97677 2746
45620 19581
45898 56692
37174 34580
14814 79854
3082 31451
45935 49011
94633 45452
89567 99435
88946 55080
49892 50209
4616 12615
97647 12010
52235 83918
40267 73847
62065 39641
55847 57332
8229 22583
75602 27915
78390 34363
21577 8604
7632 15102
14218 220...

output:

99761
99760
99759
99758
99757
99756
99755
99754
99753
99752
99751
99750
99749
99748
99747
99746
99745
99744
99743
99742
99741
99740
99739
99738
99737
99736
99735
99734
99733
99732
99731
99730
99729
99728
99727
99726
99725
99724
99723
99722
99721
99720
99719
99718
99717
99716
99715
99714
99713
99712
...

result:

ok 100000 numbers

Test #37:

score: 0
Accepted
time: 541ms
memory: 304668kb

input:

100000 5
39857 15993
78698 40431
30281 25659
26176 30636
40581 98139
28192 129
37619 78336
86105 64900
68516 29065
89231 66934
73351 27061
64512 722
22071 97110
16252 24526
65253 3810
73572 74174
79657 85508
85462 6886
62714 56608
8440 2698
14540 59598
23106 76185
21842 97851
71299 8239
18746 23411
...

output:

97661
97660
97659
97658
97657
97656
97655
97652
97651
97650
97649
97648
97647
97646
97648
97647
97646
97643
97642
97641
97640
97639
97638
97637
97636
97635
97634
97633
97632
97631
97630
97629
97628
97627
97626
97625
97624
97623
97622
97621
97618
97617
97616
97615
97614
97613
97612
97611
97610
97609
...

result:

ok 100000 numbers

Test #38:

score: 0
Accepted
time: 1416ms
memory: 312312kb

input:

100000 5
87155 87156
21603 17815
25128 937
48509 52975
14667 26209
53099 53100
36059 77875
49568 50857
21810 99612
4212 18185
83190 33401
2715 23767
80248 34872
24618 8308
76164 36914
7143 21178
17601 20076
34205 81583
32495 85003
66218 41887
51451 51452
14774 14676
15807 4286
53357 53358
10752 4750...

output:

76659
76658
76657
76654
76651
76653
76650
76652
76649
76648
76645
76644
76643
76640
76639
76641
76640
76637
76634
76633
76630
76632
76631
76628
76630
76627
76629
76626
76625
76624
76621
76618
76615
76614
76613
76610
76609
76611
76608
76607
76606
76603
76600
76602
76604
76601
76603
76605
76604
76606
...

result:

ok 100000 numbers

Test #39:

score: 0
Accepted
time: 1934ms
memory: 314680kb

input:

100000 5
66298 68947
3622 3763
98546 50033
27160 28254
36879 38374
21297 22145
12018 12493
23217 22447
79272 82439
3492 38853
80639 83858
19232 19998
5109 5309
87469 90962
41403 43058
87621 91121
62348 64839
66812 69478
83642 1905
64577 67184
46811 48683
36413 37872
93691 62043
95070 98867
36298 377...

output:

65384
65381
65378
65375
65373
65371
65370
65367
65367
65368
65365
65367
65364
65361
65358
65359
65356
65358
65356
65358
65360
65358
65357
65354
65353
65350
65351
65352
65351
65352
65353
65350
65351
65353
65352
65350
65347
65345
65344
65346
65343
65340
65337
65339
65338
65339
65339
65336
65335
65332
...

result:

ok 100000 numbers

Test #40:

score: 0
Accepted
time: 1691ms
memory: 314496kb

input:

100000 5
83075 88266
29288 31115
57230 60804
65594 80774
39968 42465
63269 67226
21132 22450
31945 33941
12959 13767
77288 82115
89021 94582
65487 69578
87111 92561
44394 84749
40971 26067
92451 98228
8217 8730
39084 41524
87708 93187
40209 42722
65053 69116
754 816
15138 16099
86302 91693
72404 769...

output:

64712
64713
64714
64711
64712
64712
64714
64713
64712
64710
64710
64709
64707
64705
64704
64705
64705
64704
64705
64706
64704
64704
64702
64699
64700
64698
64699
64698
64700
64697
64698
64699
64699
64697
64696
64697
64698
64699
64700
64698
64697
64695
64694
64692
64693
64692
64693
64694
64695
64694
...

result:

ok 100000 numbers

Test #41:

score: 0
Accepted
time: 1864ms
memory: 315756kb

input:

100000 5
39358 39562
89002 89706
28474 28597
69574 69973
83723 84184
77412 77873
84680 85158
68178 68674
61962 62464
82678 83167
59904 60230
37177 37399
45623 45885
42910 43153
56872 57205
38559 38750
28947 29098
45658 46068
1448 1437
53931 54239
20346 20441
79261 79726
31747 31903
77545 77977
73338...

output:

66942
66941
66938
66935
66932
66934
66931
66928
66925
66922
66922
66920
66921
66918
66920
66922
66924
66926
66923
66920
66917
66914
66911
66908
66905
66903
66905
66907
66904
66901
66898
66900
66902
66899
66896
66898
66895
66893
66895
66897
66894
66891
66893
66890
66887
66886
66883
66880
66877
66874
...

result:

ok 100000 numbers

Test #42:

score: 0
Accepted
time: 1787ms
memory: 315456kb

input:

100000 5
86734 86545
9334 10344
31152 30904
86962 86659
40328 39890
13959 14800
39418 40800
53956 53491
11635 11173
46562 46251
30180 30119
29736 29261
30428 31628
53367 54094
73878 73667
22582 22483
47649 47704
94870 94483
66505 66481
82807 82453
68905 68826
24932 25016
7513 7465
97567 97798
68906 ...

output:

68187
68184
68181
68178
68180
68182
68184
68186
68183
68180
68182
68179
68181
68178
68175
68172
68174
68171
68168
68170
68167
68164
68166
68168
68170
68167
68169
68166
68163
68165
68167
68164
68161
68158
68155
68157
68154
68151
68153
68155
68152
68151
68148
68145
68147
68149
68146
68148
68145
68147
...

result:

ok 100000 numbers

Test #43:

score: 0
Accepted
time: 1749ms
memory: 314764kb

input:

100000 5
48674 46860
15661 29382
22627 22416
98370 90631
38623 34327
86151 82229
98346 95211
53670 49358
17729 27314
50410 47728
46547 58550
14205 13397
59818 59587
15140 15078
20152 17584
29229 28433
42885 40733
25170 20315
89277 88481
79076 77076
30779 30405
57541 55033
88796 87519
68800 66324
667...

output:

69967
69964
69963
69960
69957
69956
69953
69952
69954
69956
69958
69960
69957
69956
69953
69952
69954
69956
69955
69952
69949
69946
69943
69940
69937
69939
69936
69933
69935
69937
69934
69931
69928
69927
69924
69921
69918
69915
69917
69919
69916
69913
69915
69912
69911
69913
69912
69909
69906
69903
...

result:

ok 100000 numbers

Test #44:

score: 0
Accepted
time: 1702ms
memory: 314764kb

input:

100000 5
59169 58313
54694 49363
81504 72971
60592 89478
77873 68952
10491 5246
28949 27885
87908 85779
84785 79533
59257 58489
46548 38282
54475 48925
43319 46724
81770 73503
9683 4842
94501 98103
36288 33152
25558 21103
67767 63899
92116 97017
2396 27620
15121 7561
51872 43719
38687 51356
66474 83...

output:

69987
69984
69981
69978
69980
69982
69984
69981
69978
69975
69977
69974
69971
69968
69970
69972
69969
69966
69963
69960
69957
69959
69956
69953
69952
69954
69951
69953
69955
69952
69949
69951
69948
69945
69942
69939
69936
69933
69930
69927
69929
69926
69923
69920
69917
69914
69916
69915
69912
69911
...

result:

ok 100000 numbers

Test #45:

score: 0
Accepted
time: 1236ms
memory: 311480kb

input:

99602 4
90470 40669
50993 1192
87142 37341
4902 54704
20544 70346
83203 66201
64564 84839
6814 56616
35285 14517
93716 43915
93380 43579
37273 12529
83466 33665
8158 57960
68936 80467
1661 48142
16350 66152
30575 19227
77918 28117
4927 44876
68081 18280
8233 41570
1578 51380
75387 74017
22401 27402
...

output:

3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99...

result:

ok 100000 numbers

Test #46:

score: 0
Accepted
time: 1237ms
memory: 311520kb

input:

99802 4
47821 2081
88020 38119
35525 14377
55023 5122
66812 82891
97973 51731
25200 75102
32570 82472
84062 34161
62416 87287
85089 64615
39921 9981
40646 90548
70974 78729
88237 61467
83583 66121
34821 15081
86310 36409
67019 17118
70748 78955
97415 52289
35292 85194
15546 65448
74372 75331
35239 1...

output:

3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99...

result:

ok 100000 numbers

Test #47:

score: 0
Accepted
time: 1218ms
memory: 311504kb

input:

99602 4
97361 52042
4998 54799
60150 10348
77185 72218
71794 21992
87865 61538
23845 25957
68036 18234
30899 80700
89229 60174
87923 61480
50366 564
65003 84401
18756 68557
61888 12086
19655 30147
27107 76908
20244 70045
76853 72550
65516 15714
40204 9599
15812 65613
32398 17405
39409 89210
83768 33...

output:

3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99601
3
99...

result:

ok 100000 numbers

Test #48:

score: 0
Accepted
time: 1259ms
memory: 311468kb

input:

99802 4
9560 59461
96486 46584
49515 99416
19075 68976
44348 5555
89351 60352
23009 72910
66639 83065
82888 32986
76627 73077
68763 80941
90409 59294
38095 87996
42272 7631
43741 93642
65261 84443
17711 67612
18636 31267
23075 72976
28159 78060
66887 82817
75174 25272
88015 61688
98660 48758
12369 3...

output:

3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99801
3
99...

result:

ok 100000 numbers

Test #49:

score: 0
Accepted
time: 1ms
memory: 3540kb

input:

1 2
1 1
1
1

output:

0

result:

ok 1 number(s): "0"

Test #50:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

1 5
1 1
100
1
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1

output:

0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1

result:

ok 100 numbers

Test #51:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

2 5
1 2
2 1
102
2
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0
1
3
0
0

output:

1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0
1
2
1
0

result:

ok 102 numbers

Extra Test:

score: 0
Extra Test Passed