QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#833323#4255. Sone2b6e0100 ✓674ms28304kbC++149.1kb2024-12-26 17:14:222024-12-26 17:14:22

Judging History

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

  • [2024-12-26 17:14:22]
  • 评测
  • 测评结果:100
  • 用时:674ms
  • 内存:28304kb
  • [2024-12-26 17:14:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace fastio
{
	constexpr int S1=1<<20;
	char buf1[S1],*l1,*r1;
	inline char getc()
	{
		return ((l1==r1&&(r1=(l1=buf1)+fread(buf1,1,S1,stdin)),l1!=r1)?*l1++:EOF);
	}
	template<typename T=int>inline T read()
	{
		T x=0,y=1;
		char c=getc();
		while(c<'0'||c>'9')
		{
			if(c=='-')
				y=-1;
			c=getc();
		}
		while(c>='0'&&c<='9')
		{
			x=c-'0'+x*10;
			c=getc();
		}
		return x*y;
	}
	inline double read_db()
	{
		double x=0,y=1;
		char c=getc();
		while(c<'0'||c>'9')
		{
			if(c=='-')
				y=-1;
			c=getc();
		}
		while(c>='0'&&c<='9')
		{
			x=x*10+c-'0';
			c=getc();
		}
		if(c=='.')
		{
			double r=.1;
			for(c=getc();c>='0'&&c<='9';c=getc())
			{
				x+=r*(c-'0');
				r*=.1;
			}
		}
		return x*y;
	}
	constexpr int S2=1<<20;
	char buf2[S2],*l2=buf2;
	inline void putc(char c)
	{
		l2==buf2+S2&&(fwrite(buf2,1,S2,stdout),l2=buf2),*l2++=c;
	}
	int _st[22];
	template<typename T>inline void write(T x,char end='\n')
	{
		if(x<0)
			putc('-'),x=-x;
		int tp=0;
		do
			_st[++tp]=x%10;
		while(x/=10);
		while(tp)
			putc(_st[tp--]+'0');
		if(end)
			putc(end);
	}
	constexpr int DIGIT=3;
	constexpr long long _p=pow(10,DIGIT);
	inline void write_db(double y,char end='\n')
	{
		if(y<0)
			putc('-'),y=-y;
		long long x=round(y*_p);
		write(x/_p),putc('.');
		x%=_p;
		for(int i=1;i<=DIGIT;i++)
			_st[i]=x%10,x/=10;
		for(int i=DIGIT;i;i--)
			putc(_st[i]+'0');
		if(end)
			putc(end);
	}
	inline void ps(const char*s,char end='\n')
	{
		for(auto p=s;*p;p++)
			putc(*p);
		if(end)
			putc(end);
	}
	struct end
	{
		~end()
		{
			fwrite(buf2,1,l2-buf2,stdout);
		}
	}ender;
}
using fastio::getc;
using fastio::read;
using fastio::read_db;
using fastio::putc;
using fastio::write;
using fastio::write_db;
using fastio::ps;
constexpr int MN=100005,SIG=100001;
int n,m,q,a[MN],b[MN],p[MN],nxt[MN],sa[MN],rk[MN],tmpp[MN],buc[MN],st[18][MN];
map<int,int>mp;
struct info
{
	int mx,sum;
	info(int _a=-1,int _b=0)
	{
		mx=_a,sum=_b;
	}
	friend info operator*(info x,info y)
	{
		if(x.mx>y.mx)
			return x;
		if(y.mx>x.mx)
			return y;
		return {x.mx,x.sum+y.sum};
	}
	friend info&operator*=(info&x,info y)
	{
		x=x*y;
		return x;
	}
};
struct segt1
{
	struct node
	{
		int l,r;
		info v,tg;
	}T[MN*4];
	void ch(int i,info x)
	{
		T[i].v=T[i].tg=x;
		T[i].v.sum*=T[i].r-T[i].l+1;
	}
	void up(int i)
	{
		T[i].v=T[i<<1].v*T[i<<1|1].v;
	}
	void down(int i)
	{
		if(T[i].tg.mx==-1)
			return;
		ch(i<<1,T[i].tg);
		ch(i<<1|1,T[i].tg);
		T[i].tg=info();
	}
	void build(int i,int l,int r)
	{
		T[i].l=l,T[i].r=r;
		if(l==r)
			return;
		int mid=(l+r)>>1;
		build(i<<1,l,mid);
		build(i<<1|1,mid+1,r);
	}
	void change(int i,int l,int r,info x)
	{
		if(l<=T[i].l&&T[i].r<=r)
		{
			ch(i,x);
			return;
		}
		down(i);
		if(l<=T[i<<1].r)
			change(i<<1,l,r,x);
		if(r>T[i<<1].r)
			change(i<<1|1,l,r,x);
		up(i);
	}
	info ask(int i,int l,int r)
	{
		if(l<=T[i].l&&T[i].r<=r)
			return T[i].v;
		down(i);
		info res;
		if(l<=T[i<<1].r)
			res=ask(i<<1,l,r);
		if(r>T[i<<1].r)
			res*=ask(i<<1|1,l,r);
		return res;
	}
}T1;
inline int LCP(int x,int y)
{
	if(x>m||y>m)
		return 0;
	if(x==y)
		return m-x+1;
	x=rk[x],y=rk[y];
	if(x>y)
		swap(x,y);
	x++;
	int g=__lg(y-x+1);
	return min(st[g][x],st[g][y-(1<<g)+1]);
}
struct segt2
{
	int lg;
	info T[MN*4];
	void build(int n)
	{
		lg=__lg(n+1)+1;
		for(int i=1;i<=n;i++)
			T[i|(1<<lg)]={LCP(1,i),1};
		for(int i=(1<<lg)-1;i;i--)
			T[i]=T[i<<1]*T[i<<1|1];
	}
	info ask(int l,int r)
	{
		info res;
		for(l=(l-1)|(1<<lg),r=(r+1)|(1<<lg);l^r^1;l>>=1,r>>=1)
		{
			if(~l&1)
				res*=T[l^1];
			if(r&1)
				res*=T[r^1];
		}
		return res;
	}
}T2;
inline void buildsa(int n,int*a)
{
	int l=0;
    for(int i=1;i<=n;i++)
		buc[a[i]]++;
	for(int i=1;i<130;i++)
		buc[i]+=buc[i-1];
	for(int i=1;i<=n;i++)
		sa[buc[a[i]]--]=i;
	memset(buc,0,sizeof buc);
	for(int i=1;i<=n;i++)
		rk[sa[i]]=(l+=(a[sa[i]]!=a[sa[i-1]]));
	for(int w=1;l<n;w<<=1)
	{
		for(int i=0;i<w;i++)
			tmpp[i+1]=n-i;
		int cnt=w;
		for(int i=1;i<=n;i++)
		{
			if(sa[i]>w)
				tmpp[++cnt]=sa[i]-w;
			buc[rk[i]]++;
		}
		for(int i=1;i<=l;i++)
			buc[i]+=buc[i-1];
		for(int i=n;i;i--)
			sa[buc[rk[tmpp[i]]]--]=tmpp[i];
		fill_n(buc+1,l,0),l=0;
		copy_n(rk+1,n,tmpp+1);
		for(int i=1;i<=n;i++)
			rk[sa[i]]=(l+=(tmpp[sa[i]]!=tmpp[sa[i-1]]||tmpp[sa[i]+w]!=tmpp[sa[i-1]+w]));
	}
	for(int i=1,j=0;i<=n;i++)
	{
		for(j=max(0,j-1);a[i+j]==a[sa[rk[i]-1]+j];j++);
		st[0][rk[i]]=j;
	}
	for(int j=1;j<18;j++)
		for(int i=1;i+(1<<j)-1<=n;i++)
			st[j][i]=min(st[j-1][i],st[j-1][i+(1<<(j-1))]);
}
inline int conn(int l1,int r1,int l2,int r2)
{
	if(l1>m||l2>m)
		return 0;
	int L=0,R=m+1,M;
	while(L+1<R)
	{
		M=(L+R)>>1;
		int i=sa[M],t=LCP(i,l1);
		bool res;
		if(t<r1-l1+1)
			res=(b[i+t]<b[l1+t]);
		else
		{
			t=LCP(i+(r1-l1+1),l2);
			if(t>=r2-l2+1)
				return i;
			res=(b[i+(r1-l1+1)+t]<b[l2+t]);
		}
		if(res)
			L=M;
		else
			R=M;
	}
	return 0;
}
inline void check(map<int,int>::iterator it)
{
	if(it==mp.begin())
		return;
	auto pit=it,nit=it;
	pit--,nit++;
	int p=conn(pit->second,pit->second+it->first-pit->first-1,it->second,it->second+nit->first-it->first-1);
	if(p)
	{
		mp.erase(it);
		pit->second=p;
	}
}
inline int LCP2(int l1,int r1,int l2,int r2,int l3,int r3,int l4,int r4)
{
	if(l3>r3)
	{
		l3=l4+l3-r3-1,r3=r4;
		if(l3>r3)
			return 0;
		l4=r4=m+1;
	}
	int t=LCP(l1,l3);
	if(t<r1-l1+1&&t<r3-l3+1)
		return t;
	if(r1-l1<r3-l3)
		return r1-l1+1+LCP2(l2,r2,m+1,m+1,l3+r1-l1+1,r3,l4,r4);
	return r3-l3+1+LCP2(l1+r3-l3+1,r1,l2,r2,l4,r4,m+1,m+1);
}
inline info calcw(int l1,int r1,int l2=m+1,int r2=m+1,int l3=m+1,int r3=m+1)
{
	if(l1>m)
		return {0,1};
	info ans;
	int i=r1;
	while(i>r1-l1+1)
		if(nxt[i]*2>i)
		{
			int d=i-nxt[i],q=i%d;
			if(q+d>r1-l1+1)
				i=q+d;
			else
				i=q+(r1-l1+1-q)/d*d;
		}
		else
			i=nxt[i];
	if(i<r1-l1+1)
		ans=T2.ask(l1,r1-i);
	while(i)
		if(nxt[i]*2>i)
		{
			int d=i-nxt[i],l,r,b1,a1,k,b2,t=LCP(i-d+1,i+1);
			l=t/d,r=i/d-2+t/d,b1=t%d,a1=i+t+1;
			t=LCP2(i-d+1,i,m+1,m+1,l2,r2,l3,r3);
			if(t<d)
				k=0,b2=t;
			else
			{
				t=LCP2(l2,r2,l3,r3,l2+d,r2,l3,r3);
				k=t/d+1,b2=t%d;
			}
			if(b1>b2)
				if(l<k)
					ans*={i+l*d+b1,min(k,r+1)-l};
				else
					ans*={i+k*d+b2,1};
			else if(b1<b2)
				if(l<=k)
					ans*={i+l*d+b1,min(k,r)-l+1};
				else
					ans*={i+k*d+b2,1};
			else if(r<k)
				ans*={i+l*d+b1,r-l+1};
			else if(l>k)
				ans*={i+k*d+b2,1};
			else
			{
				t=LCP2(a1,m,m+1,m+1,l2+k*d+b2,r2,l3,r3);
				if(t)
					ans*={i-(k-l)*d+k*d+b2+t,1};
				else
					ans*={i+l*d+b2,k-l+1};
			}
			i=i%d+d;
		}
		else
		{
			ans*={i+LCP2(i+1,m,m+1,m+1,l2,r2,l3,r3),1};
			i=nxt[i];
		}
	return ans;
}
inline void updw(map<int,int>::iterator it1)
{
	info res;
	auto it2=it1;
	it2++;
	int l1=it1->second,r1=l1+it2->first-it1->first-1;
	auto it3=it2;
	it3++;
	if(it3==mp.end())
		res=calcw(l1,r1);
	else
	{
		int l2=it2->second,r2=l2+it3->first-it2->first-1;
		auto it4=it3;
		it4++;
		if(it4==mp.end())
			res=calcw(l1,r1,l2,r2);
		else
			res=calcw(l1,r1,l2,r2,it3->second,it3->second+it4->first-it3->first-1);
	}
	T1.change(1,it1->first,it2->first-1,{0,0});
	T1.change(1,it1->first,it1->first,res);
}
inline void opch(int x,int y)
{
	a[x]=y;
	auto it=mp.upper_bound(x),pit=it;
	pit--;
	int l=pit->first,r=it->first-1,i=pit->second;
	mp.erase(pit);
	if(l<x)
		mp[l]=i;
	mp[x]=p[y];
	if(x<r)
		mp[x+1]=i+x-l+1;
	if(l<x)
		check(mp.find(l));
	check(mp.find(x));
	if(x<r)
		check(mp.find(x+1));
	if(r<n)
		check(mp.find(r+1));
	updw(--mp.upper_bound(x));
	updw(--mp.upper_bound(r));
	it=--mp.upper_bound(l);
	updw(it);
	if(it!=mp.begin())
	{
		it--;
		updw(it);
		if(it!=mp.begin())
			updw(--it);
	}
}
int main()
{
	read(),n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	m=read();
	for(int i=1;i<=SIG;i++)
		p[i]=m+1;
	for(int i=1;i<=m;i++)
		p[b[i]=read()]=i;
	for(int i=2,j=0;i<=m;i++)
	{
		while(j&&b[i]!=b[j+1])
			j=nxt[j];
		j+=(b[i]==b[j+1]);
		nxt[i]=j;
	}
	buildsa(m,b);
	T2.build(m);
	T1.build(1,1,n);
	mp[1]=p[a[1]];
	for(int i=2;i<=n;i++)
	{
		auto it=--mp.end();
		int x=p[a[i]],t=conn(it->second,it->second+i-it->first-1,x,x);
		if(t)
			it->second=t;
		else
			mp[i]=x;
	}
	mp[n+1]=m+1;
	for(auto it=mp.begin();it->first<=n;it++)
		updw(it);
	q=read();
	while(q--)
	{
		int o=read();
		if(o==1)
		{
			int x=read(),y=read();
			opch(x,y);
			info ans=T1.ask(1,1,n);
			write(ans.mx,' '),write(ans.sum);
		}
		else if(o==2)
		{
			int l=read(),r=read(),tl=a[l-1],tr=a[r+1];
			if(l>1)
				opch(l-1,SIG);
			if(r<n)
				opch(r+1,SIG);
			info ans=T1.ask(1,l,r);
			write(ans.mx,' '),write(ans.sum);
			if(l>1)
				opch(l-1,tl);
			if(r<n)
				opch(r+1,tr);
		}
		else if(o==3)
		{
			int x=read(),y=read();
			write(LCP(x,y));
		}
		else
		{
			int l1=read(),r1=read(),l2=read(),r2=read();
			if(conn(l1,r1,l2,r2))
				ps("yes");
			else
				ps("no");
		}
	}
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 5
Accepted
time: 3ms
memory: 23572kb

input:

1
1000
2 3 1 2 3 2 3 1 2 3 2 3 1 2 3 2 3 1 2 3 2 3 1 2 3 2 3 2 3 1 2 3 2 3 1 2 3 2 3 1 2 3 2 3 1 2 3 2 3 1 2 3 2 3 2 3 1 299 3 2 3 1 2 3 2 3 1 2 3 2 3 1 2 3 2 3 1 2 3 2 3 2 3 1 2 3 2 3 1 2 3 2 3 1 2 3 2 3 1 2 2 3 1 2 3 2 3 1 2 3 2 3 1 2 3 2 3 1 2 3 2 3 1 2 3 2 3 2 3 1 2 3 2 3 1 2 3 2 3 1 2 3 2 824 1...

output:

46 1
12 2
46 1
46 1
73 1
100 1
51 1
100 1
100 1
73 1
0
73 1
73 1
73 1
73 1
73 1
19 1
51 1
73 1
73 1
73 1
44 1
51 1
51 1
73 1
22 2
73 1
46 1
0
73 1
yes
57 1
73 1
73 1
73 1
73 1
73 1
73 1
73 1
73 1
51 1
yes
73 1
51 1
73 1
30 1
73 1
73 1
15 1
73 1
73 1
73 1
73 1
46 1
73 1
65 1
0
73 1
12 1
3 1
73 1
73 1...

result:

ok 1911 tokens

Test #2:

score: 5
Accepted
time: 10ms
memory: 24156kb

input:

2
1000
3 2 4 3 2 4 3 2 4 3 2 3 2 4 3 2 4 3 2 4 3 2 3 2 4 3 2 4 3 2 4 406 2 3 2 4 3 2 4 3 3 2 4 3 2 4 3 2 4 3 2 3 2 4 3 2 4 3 2 4 3 2 3 2 98 3 2 4 3 2 4 3 2 3 2 4 3 2 4 3 3 2 4 3 2 4 3 2 4 3 2 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 4 3 2 3 2 4 3 2 4 3 2 4 3 2 3 2 4 3 2 970 3 2 4 3 2 3 2 4 3 2 4 3 3 2 4 3 ...

output:

62 1
93 1
62 3
93 1
62 2
65 1
93 1
93 1
93 1
93 1
93 1
62 2
1
93 1
93 1
62 2
62 2
62 3
42 1
93 1
93 1
62 2
44 1
93 1
62 2
93 1
62 1
93 1
72 1
72 1
62 1
72 1
23 1
72 1
no
62 2
72 1
72 1
72 1
62 3
72 1
72 1
72 1
no
43 1
72 1
62 2
40 1
62 2
8 1
62 2
62 2
0
62 2
62 1
62 1
62 1
62 2
62 2
62 1
62 2
5
62 1...

result:

ok 1915 tokens

Test #3:

score: 5
Accepted
time: 202ms
memory: 25668kb

input:

3
100000
1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 3 1 1 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 3 1 1 3 1 1 3 1 1 3 1 1 3 1 3 1 1...

output:

100 979
100 978
4
100 978
100 977
100 976
100 975
100 974
100 973
100 972
100 971
100 971
100 970
100 969
100 968
100 967
100 966
100 966
100 965
100 965
9
100 964
no
100 964
100 963
100 962
100 961
100 960
100 959
100 958
100 957
100 956
100 955
yes
100 954
100 954
100 953
100 952
100 951
100 950
1...

result:

ok 191356 tokens

Test #4:

score: 5
Accepted
time: 201ms
memory: 26072kb

input:

4
100000
1 2 3 1 2 3 1 2 3 1 2 3 1 2 1 2 3 1 2 3 1 2 3 1 2 3 1 2 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 1 2 3 1 2 3 1 2 3 1 2 3 1 2 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 1 2 3 1 2 3 1 2 3 1 2 3 1 2 1 2 3 1 2 3 1 2 3 1 1 2 3 1 2 3 1 2 3 1 2 3 1 2 1 2 3 1 2 3 1 2 3 1 2 3 1 2 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 1...

output:

100 979
100 978
100 977
100 976
100 975
100 974
100 974
100 973
no
100 972
100 971
100 970
100 970
100 969
100 968
100 967
100 966
no
100 965
100 964
100 963
100 962
100 961
100 960
100 959
100 959
0
100 958
100 957
100 957
100 957
100 956
100 955
100 954
100 953
0
100 952
2
100 951
100 950
100 950
...

result:

ok 191356 tokens

Test #5:

score: 5
Accepted
time: 633ms
memory: 24160kb

input:

5
100000
5 3 3 5 3 3 5 3 3 5 3 3 5 3 5 3 3 5 3 3 5 3 3 5 3 3 5 3 5 3 5 3 3 5 3 3 5 3 3 5 3 3 5 3 5 3 3 5 3 3 5 3 3 5 3 3 5 3 5 3 5 3 3 5 3 3 5 3 3 5 3 3 5 3 5 3 3 5 3 3 5 3 3 5 3 3 5 3 5 3 5 3 3 5 3 3 5 3 3 5 3 3 5 3 5 3 3 5 3 3 5 3 3 5 3 3 5 3 5 3 5 3 3 5 3 3 5 3 3 5 3 3 5 3 5 3 3 5 3 3 5 3 3 5 3 3...

output:

30 3312
30 1774
30 3311
30 2286
0
30 365
30 3310
30 3309
30 3308
30 3307
30 3306
30 3305
30 1856
30 387
30 1033
30 3304
30 1681
30 3303
30 3302
30 3302
30 3301
30 3300
30 845
30 544
30 2719
30 3299
30 1344
30 3298
30 3298
yes
30 3297
30 3296
30 3295
30 473
30 3294
30 3293
30 3292
yes
30 859
30 3291
...

result:

ok 191359 tokens

Test #6:

score: 5
Accepted
time: 641ms
memory: 25860kb

input:

6
100000
2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2 3 2 2...

output:

30 33114
30 12379
30 33114
30 33104
30 23307
30 33094
30 33084
30 1497
no
30 33074
30 13431
30 33064
30 19
30 33054
30 33044
30 4288
30 10728
30 33034
30 6847
30 33024
30 10621
30 33014
30 10308
1
30 11959
30 3935
30 19153
30 33004
30 32994
30 2789
30 32984
30 32984
0
30 21909
30 32984
30 10889
30 3...

result:

ok 191357 tokens

Test #7:

score: 5
Accepted
time: 24ms
memory: 27540kb

input:

7
100000
1 2 1 1 1 1 1 2 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 2 5 1 1 1 3 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 2 1 1 3 4 2 2 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 4 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

1
0
1
4
1
5
1
12
2
7
3
4
4
0
0
1
0
1
3
2
2
2
1
3
0
3
2
3
2
7
0
2
1
1
3
78193
0
5
2
8
7
10
4
4
2
1
0
0
1
1
9
0
1
2
1
7
10
0
0
0
6
0
0
4
7
4
3
1
2
0
0
1
12
2
0
2
5
3
1
0
3
4
7
1
0
9
4
1
5
2
6
23
0
12
6
6
0
2
8
4
2
5
2
1
0
3
10
8
0
2
5
1
2
6
5
9
1
0
0
9
4
3
0
5
0
0
6
4
4
0
1
3
13
0
2
4
1
5
2
0
5
4
2
1
...

result:

ok 100000 tokens

Test #8:

score: 5
Accepted
time: 16ms
memory: 27544kb

input:

8
100000
1 2 1 1 1 1 1 2 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 2 5 1 1 1 3 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 2 1 1 3 4 2 2 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 4 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

0
8
5
2
0
8
4
8
1
2
0
2
0
1
9
1
0
0
0
2
2
0
0
3
0
4
3
1
5
1
5
2
3
11
8
2
3
3
6
2
0
3
0
1
1
1
3
1
0
16
8
0
0
8
13
4
0
3
0
3
0
0
0
0
0
4
7
2
0
2
8
10
0
0
0
4
0
8
2
0
0
7
1
3
5
9
1
0
2
4
0
8
0
3
2
4
1
3
0
0
1
1
5
8
1
0
0
2
4
2
0
3
0
1
3
0
2
0
1
2
15
0
5
2
13
0
3
0
0
0
1
1
3
4
1
1
2
0
4
2
2
14
1
4
5
9
0...

result:

ok 100000 tokens

Test #9:

score: 5
Accepted
time: 32ms
memory: 27644kb

input:

9
100000
1 1 1 1 1 1 1 3 1 1 1 1 2 3 1 2 1 1 1 1 1 1 1 1 2 1 2 1 1 1 3 1 1 1 1 1 2 2 1 1 1 1 1 1 2 2 1 1 1 3 1 1 1 1 2 1 1 1 3 1 1 1 1 2 1 1 1 2 1 1 3 3 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 3 1 1 2 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 2 1 2 3 2 2 1 3 1 1 1 3 3 1 2 1 1 1 1 1 1 3 1 3 2 1 1 1 1 1 1 1 1 1 2 3 1 1 1...

output:

no
no
no
no
no
no
no
no
no
no
no
yes
no
no
no
no
no
no
no
no
no
no
no
yes
no
no
yes
no
no
no
no
no
no
no
no
no
no
no
no
yes
no
no
yes
yes
no
no
no
no
no
no
no
no
no
no
no
no
no
yes
no
no
no
no
no
no
no
no
no
no
no
yes
no
no
yes
no
no
no
no
no
no
no
no
no
no
no
no
yes
no
no
yes
yes
no
no
no
no
no
no
...

result:

ok 100000 tokens

Test #10:

score: 5
Accepted
time: 23ms
memory: 27568kb

input:

10
100000
1 1 3 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 3 1 1 1 1 2 3 1 2 1 1 1 1 1 1 1 1 2 1 2 1 1 1 3 1 1 1 1 1 2 2 1 1 1 1 1 1 2 2 1 1 1 3 1 1 1 1 2 1 1 1 3 1 1 1 1 2 1 1 1 2 1 1 3 3 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 3 1 1 2 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 2 1 2 3 2 2 1 3 1 1 1 3 3 1 2 1 ...

output:

no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
yes
yes
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
yes
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
yes
yes
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
no
yes
no
no
no
no
no
no
no
no
no
no
no
...

result:

ok 100000 tokens

Test #11:

score: 5
Accepted
time: 674ms
memory: 27996kb

input:

11
100000
1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 2 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 4 2 1 1 2 1 1 1 1 1 2 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 2 5 1 1 1 3 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 2 1 1 3 4 2 2 1 1 1 1 2 2 1 1 1 ...

output:

76221 1
50830 1
72471 1
72471 1
54048 1
54048 1
54048 1
22048 1
16493 1
47298 1
50708 1
26958 1
38307 1
33000 1
no
33000 1
33000 1
33000 1
14143 1
33000 1
23657 1
12221 1
no
12093 1
12221 1
12157 1
12208 1
12221 1
12073 1
12221 1
12221 1
2
12221 1
5907 1
12221 1
11458 1
12221 1
12221 1
11073 1
12208...

result:

ok 191357 tokens

Test #12:

score: 5
Accepted
time: 655ms
memory: 28040kb

input:

12
100000
1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 4 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 3 3 1 1 1 3 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 3 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 2 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 4 ...

output:

64431 1
61681 1
2343 1
3
43431 1
43431 1
43431 1
34516 1
13424 1
43431 1
43431 1
43431 1
21116 1
15931 1
9601 1
43431 1
14281 1
34223 1
34223 1
34223 1
28030 1
28030 1
22280 1
22280 1
18969 1
12780 1
3
15719 1
15719 1
14280 1
9181 1
1767 1
3128 1
14280 1
15719 1
12455 1
14280 1
15719 1
12530 1
15719...

result:

ok 191360 tokens

Test #13:

score: 5
Accepted
time: 625ms
memory: 28080kb

input:

13
100000
1 1 1 1 1 1 4 1 1 1 4 2 1 1 2 1 1 1 1 1 2 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 2 5 1 1 1 3 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 2 1 1 3 4 2 2 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 4 1 1 3 1 1 1 1 ...

output:

46658 1
52000 1
yes
17323 1
47823 1
47823 1
41266 1
14143 1
41266 1
27407 1
27407 1
no
13016 1
27407 1
18907 1
15987 1
19753 1
12073 1
19954 1
19954 1
4
19954 1
5907 1
19611 1
15987 1
19954 1
19954 1
15954 1
19954 1
8
14861 1
13
7407 1
4664 1
5959 1
19954 1
17204 1
2343 1
1
17204 1
14861 1
14477 1
1...

result:

ok 191356 tokens

Test #14:

score: 5
Accepted
time: 633ms
memory: 28304kb

input:

14
100000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 3 3 1 1 1 3 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 3 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 2 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 4 2 1 1 2 1 1 1 1 1 2 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 2 5 1 1 ...

output:

70250 1
28488 1
24024 1
9601 1
40253 1
14281 1
29750 1
25473 1
28738 1
29750 1
29750 1
29750 1
29750 1
29750 1
12780 1
0
29738 1
19344 1
14753 1
12297 1
2253 1
5378 1
14280 1
19344 1
12455 1
14280 1
19344 1
12530 1
19344 1
14753 1
19344 1
19344 1
8738 1
14753 1
19344 1
14753 1
19344 1
no
9323 1
1934...

result:

ok 191360 tokens

Test #15:

score: 5
Accepted
time: 606ms
memory: 28064kb

input:

15
100000
5 1 1 1 3 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 1 2 1 1 3 4 2 2 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 4 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 ...

output:

no
26093 1
71500 1
19840 1
39524 1
41208 1
13823 1
71500 1
55111 1
1
47611 1
6840 1
35861 1
25622 1
47611 1
24860 1
15954 1
24860 1
2
24860 1
0
8340 1
7664 1
5959 1
24860 1
24860 1
2343 1
7
24860 1
24860 1
24860 1
19516 1
9610 1
24860 1
24860 1
24860 1
10204 1
12360 1
9601 1
24860 1
11281 1
24860 1
...

result:

ok 191357 tokens

Test #16:

score: 5
Accepted
time: 633ms
memory: 28020kb

input:

16
100000
1 1 1 1 1 1 1 3 3 1 1 1 3 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 1 3 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 2 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 4 2 1 1 2 1 1 1 1 1 2 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 2 5 1 1 1 3 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 2 1 1 1 1 ...

output:

73250 1
73250 1
65250 1
17300 1
5
46378 1
46378 1
39293 1
15297 1
2253 1
5378 1
22245 1
46378 1
12455 1
32398 1
46378 1
26208 1
37676 1
37676 1
37676 1
37676 1
7675 1
37676 1
33926 1
33926 1
24426 1
no
9323 1
24426 1
19344 1
19344 1
7142 1
19344 1
19344 1
19344 1
no
6343 1
19344 1
10844 1
15987 1
15...

result:

ok 191358 tokens

Test #17:

score: 5
Accepted
time: 628ms
memory: 28256kb

input:

17
100000
5 3 2 5 1 2 1 5 2 1 5 3 2 5 1 2 1 5 2 1 5 3 2 5 1 2 1 5 2 1 5 3 2 5 1 2 1 5 2 1 5 3 2 5 1 2 1 5 2 1 5 3 2 5 1 2 1 5 2 1 5 3 2 5 1 2 1 5 2 1 5 3 2 5 1 2 1 5 2 1 5 3 2 5 1 2 1 5 2 1 5 3 2 5 1 2 1 5 2 1 5 3 2 5 1 2 1 5 2 1 5 3 2 5 1 2 1 5 2 1 5 3 2 5 1 2 1 5 2 1 5 3 2 5 1 2 1 5 2 1 5 3 2 5 1 ...

output:

14991 1
14991 1
0
14991 1
14991 1
14991 1
14991 1
9321 1
14991 1
85 1
14991 1
14991 1
3389 1
14991 1
14991 1
8171 1
14991 1
14991 1
14991 1
7300 1
1
14991 1
3241 1
14991 1
14991 1
14991 1
3078 1
14991 1
14991 1
1
14991 1
14991 1
8171 1
13776 1
2319 1
no
11969 1
11156 1
11969 1
8324 1
8324 1
8324 1
y...

result:

ok 191357 tokens

Test #18:

score: 5
Accepted
time: 622ms
memory: 27916kb

input:

18
100000
4 2 2 1 1 3 2 3 4 5 4 2 2 1 1 3 2 3 4 5 4 2 2 1 1 3 2 3 4 5 4 2 2 1 1 3 2 3 4 5 4 2 2 1 1 3 2 3 4 5 4 2 2 1 1 3 2 3 4 5 4 2 2 1 1 3 2 3 4 5 4 2 2 1 1 3 2 3 4 5 4 2 2 1 1 3 2 3 4 5 4 2 2 1 1 3 2 3 4 5 4 2 2 1 1 3 2 3 4 5 4 2 2 1 1 3 2 3 4 5 4 2 2 1 1 3 2 3 4 5 4 2 2 1 1 3 2 3 4 5 4 2 2 1 1 ...

output:

6664 1
10003 376
10003 376
10003 91
10003 91
1
10003 91
0
10003 91
4612 1
2737 1
10003 91
10003 91
2411 1
0
8229 1
8229 1
8229 1
7466 1
8229 1
7466 1
7466 1
7466 1
7466 1
5884 1
6935 1
7466 1
7125 1
7466 1
7466 1
7466 1
7466 1
7466 1
7125 1
7125 1
7125 1
7125 1
2156
7125 1
7125 1
7125 1
3133 1
1693 ...

result:

ok 191358 tokens

Test #19:

score: 5
Accepted
time: 673ms
memory: 27956kb

input:

19
100000
1 5 2 4 3 5 5 1 4 5 1 5 2 4 3 5 5 1 4 5 1 5 2 4 3 5 5 1 4 5 1 5 2 4 3 5 5 1 4 5 1 5 2 4 3 5 5 1 4 5 1 5 2 4 3 5 5 1 4 5 1 5 2 4 3 5 5 1 4 5 1 5 2 4 3 5 5 1 4 5 1 5 2 4 3 5 5 1 4 5 1 5 2 4 3 5 5 1 4 5 1 5 2 4 3 5 5 1 4 5 1 5 2 4 3 5 5 1 4 5 1 5 2 4 3 5 5 1 4 5 1 5 2 4 3 5 5 1 4 5 1 5 2 4 3 ...

output:

5837 1
7018 1
6352 1
7018 1
6352 1
7018 1
1
7018 1
7018 1
7018 1
7018 1
7018 1
5837 1
5837 1
7018 1
6549 1
5837 1
5565 1
5837 1
4716 1
7018 1
5074 1
7018 1
4979 1
1478
6948 1
no
4716 1
6948 1
6948 1
6726 1
6948 1
5837 1
5837 1
5837 1
5837 1
4076 1
no
5837 1
5837 1
5837 1
85 1
5837 1
5837 1
4288 1
49...

result:

ok 191356 tokens

Test #20:

score: 5
Accepted
time: 605ms
memory: 28116kb

input:

20
100000
2 1 3 1 3 5 5 3 5 2 2 1 3 1 3 5 5 3 5 2 2 1 3 1 3 5 5 3 5 2 2 1 3 1 3 5 5 3 5 2 2 1 3 1 3 5 5 3 5 2 2 1 3 1 3 5 5 3 5 2 2 1 3 1 3 5 5 3 5 2 2 1 3 1 3 5 5 3 5 2 2 1 3 1 3 5 5 3 5 2 2 1 3 1 3 5 5 3 5 2 2 1 3 1 3 5 5 3 5 2 2 1 3 1 3 5 5 3 5 2 2 1 3 1 3 5 5 3 5 2 2 1 3 1 3 5 5 3 5 2 2 1 3 1 3 ...

output:

1608 1
no
10002 1
4364 1
8329 1
10002 1
8329 1
10002 1
no
2957 1
10002 1
10002 1
10002 1
6406 1
10002 1
10002 1
10002 1
no
5719 1
10002 1
6406 1
6406 1
5719 1
3748 1
10002 1
10002 1
0
10002 1
3316 1
5719 1
5719 1
10002 1
10002 1
6162 1
10002 1
0
5719 1
0
4726 1
2804 1
2895 1
10002 1
10002 1
1223 1
1...

result:

ok 191355 tokens

Extra Test:

score: 0
Extra Test Passed