QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#869978#8618. Have You Seen This Subarray?ucup-team087#TL 200ms100808kbC++2319.4kb2025-01-25 14:14:262025-01-25 14:14:27

Judging History

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

  • [2025-01-25 14:14:27]
  • 评测
  • 测评结果:TL
  • 用时:200ms
  • 内存:100808kb
  • [2025-01-25 14:14:26]
  • 提交

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

bool dbg=false;

#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>;
using vvi=vc<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));
}

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);
}
string rand_string(int n,char lw,char up){
	string s(n,'?');
	rep(i,n)s[i]=rand_int(lw,up);
	return s;
}

int current_run_id,run_batch_size=1000;
int calc_random_limit(){
	return current_run_id/run_batch_size+1;
}
template<class t>
void generate_single(t&a){
	a=rand_int(1,calc_random_limit());
}
void generate_single(string&a){
	int n;generate_single(n);
	a=rand_string(n,'a','b');
}
template<class t,class u>
void generate_single(pair<t,u>&a){
	generate_single(a.a);
	generate_single(a.b);
}
//https://trap.jp/post/1224/
template<class... Args>
void input(Args&... a){
	if(dbg){
		(generate_single(a),...);
	}else{
		#ifdef USE_FAST_IO
		sc.read(a...);
		#else
		(cin >> ... >> a);
		#endif
	}
}
#define INT(...) int __VA_ARGS__;input(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;input(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;input(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;input(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;input(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;input(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;input(__VA_ARGS__)
#define overload3(a,b,c,d,...) d
#define VI2(name,size) vi name(size);rep(i_##name,size)input(name[i_##name]);
#define VI3(name,size,offset) vi name(size);rep(i_##name,size)input(name[i_##name]),name[i_##name]+=offset;
#define VI(...) overload3(__VA_ARGS__,VI3,VI2)(__VA_ARGS__)
#define VPI(name,size) vc<pi> name(size);rep(i_##name,size)input(name[i_##name].a,name[i_##name].b);
#define VVI(name,sizeN,sizeM) vvi name(sizeN,vi(sizeM));\
rep(i_##name,sizeN)rep(j_##name,sizeM)input(name[i_##name][j_##name]);
#define VS(name,size) vc<string> name(size);rep(i_##name,size)input(name[i_##name]);
#define VMI(name,size) vc<mint> name(size);rep(i_##name,size){INT(tmp_##name);name[i_##name]=tmp_##name;};

#define overload5(a,b,c,d,e,f,...) f
#define VVC4(type,name,sizeN,sizeM) vvc<type> name(sizeN,vc<type>(sizeM));
#define VVC5(type,name,sizeN,sizeM,ini) vvc<type> name(sizeN,vc<type>(sizeM,ini));
#define VVC(...) overload5(__VA_ARGS__,VVC5,VVC4)(__VA_ARGS__)

template<class T>
T vvvc(T v){
	return v;
}

template<class T,class...Args>
auto vvvc(int n,T v,Args...args){
	return vector(n,vvvc(v,args...));
}

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<<"}";
}

void printsuc(int suc){
	#ifdef USE_FAST_IO
		if(suc==1)pr.write('\n');
		if(suc==2)pr.write(' ');
	#else
		if(suc==1){
			if(dbg)cout<<endl;
			else{
				#ifdef LOCAL
				cout<<endl;
				#else
				cout<<"\n";
				#endif
			}
		}
		if(suc==2)
			cout<<" ";
	#endif
}

template<class t>
void print_single(t x,int suc=1){
	#ifdef USE_FAST_IO
	pr.write(x);
	#else
	cout<<x;
	#endif
	printsuc(suc);
}

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?3:2);
	printsuc(suc);
}

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?3:2);
	printsuc(suc);
}

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...);
}

template<class T>
void printvv(const vvc<T>&vs){
	for(const auto&row:vs)print(row);
}

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 S> void mkuni(S&v){
	sort(all(v));
	v.erase(unique(all(v)),v.ed);
}

template<class t> bool isuni(vc<t> v){
	int s=si(v);
	mkuni(v);
	return si(v)==s;
}

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

template<class S,class u>
int lwb(const S&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);
}

//VERIFY: yosupo
//KUPC2017J
//AOJDSL1A
//without rank
struct unionfind{
	vi p,s;
	int c;
	unionfind(int n):p(n,-1),s(n,1),c(n){}
	void clear(){
		fill(all(p),-1);
		fill(all(s),1);
		c=si(p);
	}
	int find(int a){
		return p[a]==-1?a:(p[a]=find(p[a]));
	}
	//set b to a child of a
	bool unite(int a,int b){
		a=find(a);
		b=find(b);
		if(a==b)return false;
		p[b]=a;
		s[a]+=s[b];
		c--;
		return true;
	}
	bool same(int a,int b){
		return find(a)==find(b);
	}
	int sz(int a){
		return s[find(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> rand_tree(int n){
	vvc<int> t(n);
	unionfind uf(n);
	while(uf.c>1){
		int a=rand_int(n);
		int b=rand_int(n);
		if(uf.unite(a,b)){
			t[a].pb(b);
			t[b].pb(a);
		}
	}
	return t;
}

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

vi readRooted(int n){
	assert(!dbg);
	vi par(n,-1);
	rng(i,1,n){
		input(par[i]);
		par[i]--;
		assert(inc(0,par[i],i-1));
	}
	return par;
}

void printTree(const vvc<int> t){
	int n=si(t);
	int degsum=0;
	rep(i,n)degsum+=si(t[i]);
	if(degsum==n-1){
		//directed
		rep(i,si(t))for(auto j:t[i]){
			print(i+1,j+1);
		}
	}else if(degsum==2*(n-1)){
		//undirected
		rep(i,si(t))for(auto j:t[i])if(i<j){
			print(i+1,j+1);
		}
	}else{
		assert(false);
	}
}

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,class v>
pair<t,u>&operator*=(pair<t,u>&a,v b){
	a.a*=b;a.b*=b;return a;}
template<class t,class u,class v>
pair<t,u> operator*(pair<t,u> a,v b){return a*=b;}
template<class t,class u>
pair<t,u> operator-(pair<t,u> a){return mp(-a.a,-a.b);}
namespace std{
template<class t,class u>
istream&operator>>(istream&is,pair<t,u>&a){
	return is>>a.a>>a.b;
}
}

template<class t,size_t n>
array<t,n>&operator+=(array<t,n>&a,const array<t,n>&b){
	rep(i,n)a[i]+=b[i];
	return a;
}
template<class t,size_t n>
array<t,n>&operator-=(array<t,n>&a,const array<t,n>&b){
	rep(i,n)a[i]-=b[i];
	return a;
}
template<class t,size_t n,class v>
array<t,n>&operator*=(array<t,n>&a,v b){
	rep(i,n)a[i]*=b;
	return a;
}
template<class t,size_t n>
array<t,n> operator+(array<t,n> a,const array<t,n>&b){return a+=b;}
template<class t,size_t n>
array<t,n> operator-(array<t,n> a,const array<t,n>&b){return a-=b;}
template<class t,size_t n,class v>
array<t,n> operator*(array<t,n> a,v b){return 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+=(vc<t>&a,const vc<t>&b){
	a.resize(max(si(a),si(b)));
	rep(i,si(b))a[i]+=b[i];
	return a;
}

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>
vc<t>& operator-=(vc<t>&a,const vc<t>&b){
	a.resize(max(si(a),si(b)));
	rep(i,si(b))a[i]-=b[i];
	return a;
}
/*
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>
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<<=(vc<t>&a,int k){
	assert(k>=0);
	a.insert(a.bg,k,t(0));
	return a;
}
template<class t>
vc<t> operator<<(vc<t> a,int k){
	return a<<=k;
}

template<class t>
vc<t>& operator>>=(vc<t>&a,int k){
	if(si(a)<=k)a.clear();
	else a.erase(a.bg,a.bg+k);
	return a;
}
template<class t>
vc<t> operator>>(vc<t> a,int k){
	return a>>=k;
}

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 t>
void rempos(vc<t>&a,int i){
	assert(inc(0,i,si(a)-1));
	a.erase(a.bg+i);
}

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);
}

//Multiuni2023-8 C
//f(lw)=false,...,f(n-1)=false,f(n)=true,...,f(up)=true,
//のときに n を返す
template<class F>
int find_min_true(int lw,int up,F f){
	while(up-lw>1){
		const int mid=(lw+up)/2;
		if(f(mid))up=mid;
		else lw=mid;
	}
	return up;
}
//f(lw)=true,f(up)=false
template<class F>
int find_max_true(int lw,int up,F f){
	while(up-lw>1){
		const int mid=(lw+up)/2;
		if(f(mid))lw=mid;
		else up=mid;
	}
	return lw;
}

template<class t> using pqmin=priority_queue<t,vc<t>,greater<t>>;
template<class t> using pqmax=priority_queue<t>;
using T=tuple<int,int,int>;

template<class t,class u>
vc<pair<t,vc<u>>> to_groups(vc<pair<t,u>> a){
	sort(all(a));
	vc<pair<t,vc<u>>> res;
	for(auto [key,val]:a){
		if(res.empty()||res.back().a!=key)res.eb(key,vc<u>());
		res.back().b.pb(val);
	}
	return res;
}

//GCJ 2023 D D
//[l,r)
void common_ranges(vc<pi>&a,const vc<pi>&b){
	static vi buf;buf.clear();
	for(auto [l,r]:a){
		buf.pb(l*2);
		buf.pb(r*2+1);
	}
	for(auto [l,r]:b){
		buf.pb(l*2);
		buf.pb(r*2+1);
	}
	sort(all(buf));
	a.clear();
	int left,cur=0;
	for(auto xk:buf){
		int x=xk>>1,k=xk&1;
		if(k==0){
			cur++;
			if(cur==2)left=x;
		}else{
			if(cur==2&&left<x)a.eb(left,x);
			cur--;
		}
	}
}

void slv(){
	INT(n,m,q);
	vi a=vid(n);
	vc<pair<pi,int>> evs;
	{
		int step=0;
		auto upd=[&](int i){
			evs.eb(pi(a[i],a[i+1]),step);
		};
		rep(i,n-1){
			upd(i);
		}
		rep(_,m){
			step++;
			INT(i,j);
			i--;j--;
			if(0<=i-1)upd(i-1);
			upd(i);
			if(i+1<=j-1)upd(j-1);
			if(j<=n-2)upd(j);
			swap(a[i],a[j]);
			if(0<=i-1)upd(i-1);
			upd(i);
			if(i+1<=j-1)upd(j-1);
			if(j<=n-2)upd(j);
		}
		step++;
		rep(i,n-1){
			upd(i);
		}
	}
	auto buf=to_groups(evs);
	vc<pi> keys(si(buf));
	vvc<pi> vals(si(buf));
	rep(i,si(buf)){
		auto [key,val]=buf[i];
		keys[i]=key;
		int len=si(val);
		assert(len%2==0);
		len/=2;
		vals[i].resize(len);
		rep(j,len)vals[i][j]=pi(val[j*2],val[j*2+1]);
		remif(vals[i],[&](pi lr){return lr.a==lr.b;});
	}
	dmp(keys);
	dmp(vals);
	rep(_,q){
		INT(k);
		VI(b,k,-1);
		if(k==1)print(0);
		else{
			vc<pi> cur{pi(0,m+1)};
			rep(i,k-1){
				pi tar(b[i],b[i+1]);
				if(bis(keys,tar)){
					int j=lwb(keys,tar);
					common_ranges(cur,vals[j]);
				}else{
					assert(0);
					cur.clear();
					break;
				}
			}
			assert(si(cur));
			print(cur[0].a);
		}
	}
}

signed main(signed argc,char*argv[]){
	if(argc>1&&strcmp(argv[1],"D")==0)dbg=true;
	
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	if(dbg){
		while(1){
			if(current_run_id%run_batch_size==0){
				cerr<<"Current Run "<<current_run_id<<endl;
			}
			slv();
			current_run_id++;
		}
	}else{
		//int t;cin>>t;rep(_,t)
		slv();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3712kb

input:

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

output:

1
3
0
2
3

result:

ok 5 number(s): "1 3 0 2 3"

Test #2:

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

input:

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

output:

0
29
44
22
23
18
1
37
3
16
0
16
0
13
0
0

result:

ok 16 numbers

Test #3:

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

input:

500 500 165
5 424
246 385
355 428
43 338
214 378
286 469
6 467
149 333
203 411
7 111
395 483
256 288
69 414
33 429
159 425
22 470
13 425
235 292
291 412
76 224
64 207
198 365
268 314
116 366
338 386
58 265
328 330
146 493
89 288
120 465
187 201
336 499
406 485
195 406
56 485
410 424
125 149
154 216
...

output:

68
77
385
0
391
119
0
443
216
0
0
420
0
136
434
0
163
77
410
122
0
0
436
474
285
0
109
89
13
0
38
0
0
133
48
390
0
0
157
25
402
0
232
272
0
0
374
294
226
0
16
0
151
295
80
17
184
379
333
199
431
0
0
0
10
0
0
0
357
431
165
0
0
408
296
0
0
0
191
0
275
233
184
284
0
107
0
213
193
317
0
0
349
311
82
0
1...

result:

ok 165 numbers

Test #4:

score: 0
Accepted
time: 9ms
memory: 8176kb

input:

5000 5000 188
121 3352
1927 3462
1474 2956
818 3688
2965 3432
2063 2891
946 2028
2270 3486
1809 2413
108 4387
920 4467
198 2766
2950 4940
1447 1580
4703 4722
1285 1768
94 1205
1863 4496
908 4980
2181 3000
1508 3798
2161 4451
952 3285
339 1166
291 3872
3014 4857
1999 2809
2892 4392
1994 3280
557 3600...

output:

619
2857
3580
3942
3094
189
0
3024
3750
3954
51
3815
1731
150
3082
4683
4303
2289
153
629
1512
1245
1028
4033
1158
1279
3758
1929
3077
2317
4291
632
2855
1513
526
1047
675
278
498
1535
2549
2361
3393
4438
458
1618
158
3991
2120
3290
2469
2357
3152
3166
206
2279
2352
3077
4786
0
2682
2822
2598
3157
4...

result:

ok 188 numbers

Test #5:

score: 0
Accepted
time: 198ms
memory: 100108kb

input:

100000 100000 33297
71020 88781
73567 91865
28411 98582
30528 55399
32377 88782
5464 33315
16441 21471
13984 59425
4953 40519
24887 54173
42736 94259
36960 89613
25476 27783
95468 96479
72650 76406
8812 58175
71657 81205
24702 49487
50388 67643
6272 23503
25087 72725
48821 81737
30758 71554
55829 82...

output:

27228
22301
7931
0
75416
1215
0
25576
22641
0
0
17383
24756
30126
15021
32805
65792
88809
22668
0
0
0
0
9889
0
53443
65387
0
80361
74814
86721
0
0
63844
0
33458
19889
75869
79460
33108
72549
68381
3025
0
0
25883
20179
55587
47021
84515
0
33494
15631
0
62931
0
53663
44093
21837
40160
26104
55703
0
0
...

result:

ok 33297 numbers

Test #6:

score: 0
Accepted
time: 171ms
memory: 100176kb

input:

100000 100000 100000
36004 87861
86753 97164
50337 64104
57483 58920
50782 94040
66749 76405
46667 79515
1545 97049
54733 71517
7919 97284
18761 54240
26599 48474
5122 10540
21254 35983
81511 98419
30413 67662
38448 47203
25866 55510
85602 98353
62852 77724
27306 66940
35955 53948
4223 91729
90149 9...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 100000 numbers

Test #7:

score: 0
Accepted
time: 188ms
memory: 99940kb

input:

100000 100000 66652
22994 71513
10658 88662
1807 55418
66243 90922
42557 51157
47642 82097
523 1973
904 95794
3610 35213
47230 91500
20542 36216
33892 71053
29813 84930
16027 99750
15436 93166
90680 93515
36466 89585
15141 69056
81445 88916
9101 96490
13087 52198
21584 55609
32214 99179
72280 75437
...

output:

20955
0
0
45077
0
0
0
0
29096
0
76005
0
0
0
11328
36753
0
41674
36156
446
65729
73462
19985
80899
0
0
0
0
0
60255
8012
0
0
0
0
0
0
28968
0
0
0
0
72218
21749
21058
0
0
0
0
0
0
0
0
24280
0
70613
14938
706
0
0
0
0
0
50017
0
0
0
0
32881
0
32413
0
0
0
0
0
0
52263
47541
0
0
0
6900
0
25846
0
91075
0
0
0
31...

result:

ok 66652 numbers

Test #8:

score: 0
Accepted
time: 191ms
memory: 100084kb

input:

100000 100000 49963
43461 76126
47999 69477
44427 55721
59597 99283
39193 60450
22213 29867
2229 68597
9589 71446
40976 68247
22820 50975
7041 44604
3521 4699
7165 34683
4692 53860
9816 36375
48431 75451
81851 83086
46691 98255
18820 28625
24245 25659
41073 41314
3832 27757
311 49980
8518 88906
1357...

output:

0
5213
0
0
8053
0
0
45209
0
0
44776
40506
46845
0
0
5860
70896
53576
0
854
82107
64134
0
14000
74001
75741
0
11040
688
86138
0
32383
2853
0
50735
0
9101
60076
0
71516
16291
0
0
0
0
0
9763
0
66272
68734
55387
0
0
78727
74088
39997
77565
27790
1605
23307
0
14682
4028
0
50364
43525
0
55936
49424
0
0
18...

result:

ok 49963 numbers

Test #9:

score: 0
Accepted
time: 198ms
memory: 99944kb

input:

100000 100000 18171
29975 72983
27998 93792
31466 82309
25911 66592
20873 50102
20462 54015
24423 32334
5133 50011
43400 83486
16333 32326
19998 49819
71405 85315
23961 31574
10103 82146
72621 84128
385 61995
310 52367
48257 96081
809 62537
19925 32177
64047 67534
11395 56798
58344 84094
31549 41454...

output:

83824
51294
42396
92956
35315
67672
47179
343
68909
36368
46810
0
33146
25662
20050
23849
0
80208
32083
24689
32840
31079
0
22672
72093
58449
71720
66396
0
71934
20351
91870
93940
41146
24156
68412
68143
0
0
87635
13275
25041
76654
273
81223
0
48926
85929
20349
0
0
3580
2644
0
0
75015
0
0
79336
1681...

result:

ok 18171 numbers

Test #10:

score: 0
Accepted
time: 200ms
memory: 100120kb

input:

100000 100000 6487
93520 95421
30400 62615
1951 83044
41508 90660
1054 38886
4410 70952
23586 96134
83162 99696
26056 47278
17385 61522
13151 87077
9702 90491
55848 82789
15155 33232
45308 89328
54038 61545
9064 26596
20886 86998
19381 65034
54688 79551
11399 77613
17246 82848
44061 65570
9277 73507...

output:

64646
30752
91838
37452
23440
12218
69492
9116
75189
47656
95622
41319
81011
89043
3241
0
1655
33466
81215
85138
78911
92874
89477
73931
26452
21062
65934
36286
59326
28218
29161
25810
66231
39536
6230
33282
20653
39301
8073
25201
56576
27448
73012
58079
66056
20236
2206
87061
47518
67303
47739
3582...

result:

ok 6487 numbers

Test #11:

score: 0
Accepted
time: 195ms
memory: 99932kb

input:

100000 100000 3889
6824 44272
7953 41679
29247 64748
5425 73326
32362 88465
14595 70806
84748 97666
69225 77398
23271 89456
18658 33389
26780 83361
35947 83442
6060 78512
50609 57165
31689 79799
7399 71009
15270 40950
7430 92031
17748 48465
20574 54533
1288 78339
77760 88430
36507 74792
31913 88932
...

output:

65300
75771
19231
34178
40370
72287
90877
42868
21467
31341
51475
21343
52313
91168
33439
89080
72625
15933
51344
40373
34077
9127
29975
13775
69999
33074
66730
98063
8899
73371
32439
31006
17512
57102
75372
19924
20162
21255
69600
60251
63709
48469
13325
55157
90346
14062
10948
88667
36935
10701
77...

result:

ok 3889 numbers

Test #12:

score: 0
Accepted
time: 193ms
memory: 100100kb

input:

100000 100000 400
71199 87490
36484 68533
37117 96109
8848 11256
35636 71230
57301 89083
20202 46774
1507 34537
9117 19504
27635 29289
26556 44606
33824 43277
5345 73653
37056 62505
75807 92210
18624 33223
47357 63627
87341 90506
39869 80288
5008 38702
88801 92572
54411 59816
1793 49615
71877 97192
...

output:

99141
74030
16619
70001
122
35866
70327
37180
99948
44225
33741
14762
20348
17090
88645
89807
16903
50325
54567
54552
94568
61923
90159
26930
87056
97065
74629
38296
19856
29905
46778
81118
81348
10596
75198
70997
17924
26919
66336
53096
1591
22405
2662
60054
48584
61277
18796
5556
53414
81701
10433...

result:

ok 400 numbers

Test #13:

score: 0
Accepted
time: 197ms
memory: 100012kb

input:

100000 100000 40
33812 48349
15097 43656
11978 68493
249 51825
43291 91166
34578 58910
31288 67968
41380 56661
57983 89330
16836 66476
39948 42282
65903 96817
10348 67447
26333 96853
72576 98956
35688 85978
49893 79139
16834 70393
47175 84119
1447 69694
13724 14867
24711 26687
27980 63923
8319 99848...

output:

78906
85062
14765
9789
79202
44840
62646
62651
7566
56152
89337
56379
92388
26469
25562
13601
59429
90892
49043
8594
19156
19762
58826
69226
51258
86571
61661
30687
36329
87695
76536
70333
98284
6598
59312
37819
29386
71881
51876
99729

result:

ok 40 numbers

Test #14:

score: 0
Accepted
time: 187ms
memory: 100808kb

input:

100000 100000 2
28131 28197
25868 68332
78570 86410
77755 90610
12794 89014
46353 51255
30636 64496
68207 88651
17370 20173
22246 32963
23578 51745
11675 93581
49024 95047
1413 72087
9613 93622
40678 89451
34298 87112
8737 53341
25639 41997
17205 75200
67586 74870
453 36247
51730 94593
23501 83101
5...

output:

16948
11551

result:

ok 2 number(s): "16948 11551"

Test #15:

score: -100
Time Limit Exceeded

input:

2 100000 66664
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1 2
1...

output:

0
0
1
0
0
0
0
0
1
0
0
1
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
1
0
0
1
0
0
1
0
1
0
1
0
0
1
1
0
0
1
0
0
1
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
0
0
0
0
0
0
0
1
0
0
0
0
1
1
0
0
0
1
0
0
0
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
1
0
1
0
1
1
0
...

result: