QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#108348#6511. Balancing SequencesCrysflyAC ✓256ms3696kbC++173.8kb2023-05-24 19:02:402023-05-24 19:02:44

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-24 19:02:44]
  • 评测
  • 测评结果:AC
  • 用时:256ms
  • 内存:3696kb
  • [2023-05-24 19:02:40]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
inline int read()
{
	char c=getchar();int x=0;bool f=0;
	for(;!isdigit(c);c=getchar())f^=!(c^45);
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
	if(f)x=-x;return x;
}

#define mod 998244353
struct modint{
	int x;
	modint(int o=0){x=o;}
	modint &operator = (int o){return x=o,*this;}
	modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
	modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
	modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
	modint &operator ^=(int b){
		modint a=*this,c=1;
		for(;b;b>>=1,a*=a)if(b&1)c*=a;
		return x=c.x,*this;
	}
	modint &operator /=(modint o){return *this *=o^=mod-2;}
	friend modint operator +(modint a,modint b){return a+=b;}
	friend modint operator -(modint a,modint b){return a-=b;}
	friend modint operator *(modint a,modint b){return a*=b;}
	friend modint operator /(modint a,modint b){return a/=b;}
	friend modint operator ^(modint a,int b){return a^=b;}
	friend bool operator ==(modint a,int b){return a.x==b;}
	friend bool operator !=(modint a,int b){return a.x!=b;}
	bool operator ! () {return !x;}
	modint operator - () {return x?mod-x:0;}
	bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define maxn 400005
#define inf 0x3f3f3f3f

int n;
int a[2][maxn];
pii pa[maxn],pb[maxn];
int b[2][maxn];
int ma[maxn],mb[maxn],ta[maxn],tb[maxn];

bool no;
vector<vi>res; 

bool chk(){
	For(i,1,n) ma[i]=min(a[0][i],a[1][i]),ta[i]=(a[1][i]<a[0][i]);
	For(i,1,n) if(ma[i]!=mb[i] || ta[i]!=tb[i]) return 0;
	return 1;
}

void wk(int x,int y,int xx,int yy){
	assert(ta[y]!=x);
	assert(ta[yy]!=xx);
	res.pb({x+1,y,xx+1,yy});
	swap(a[x][y],a[xx][yy]);
	pa[a[x][y]]=mkp(x,y);
	pa[a[xx][yy]]=mkp(xx,yy);
	ta[y]=(a[1][y]<a[0][y]);
	ta[yy]=(a[1][yy]<a[0][yy]);
}
void wk(int x,int y){
//	cout<<"wk "<<x<<" "<<y<<"\n";
	wk(pa[x].fi,pa[x].se,pa[y].fi,pa[y].se);
}
bool isbig(int x){
	int p=pa[x].fi,pp=pa[x].se;
	assert(a[p][pp]==x);
//	cout<<"Big "<<x<<" "<<pp<<" "<<p<<" "<<a[!p][pp]<<endl;
	return x>a[!p][pp];
}

void work()
{
	n=read(); res.clear();
	For(j,0,1)For(i,1,n)a[j][i]=read(),pa[a[j][i]]=mkp(j,i);
	For(j,0,1)For(i,1,n)b[j][i]=read(),pb[b[j][i]]=mkp(j,i);
	
	For(i,1,n) mb[i]=min(b[0][i],b[1][i]),tb[i]=(b[1][i]<b[0][i]);
	For(i,1,n) ma[i]=min(a[0][i],a[1][i]),ta[i]=(a[1][i]<a[0][i]);
	
	For(i,1,n){
		if(mb[i]>ma[i])return puts("-1"),void();
		if(mb[i]==ma[i] && ta[i]!=tb[i])return puts("-1"),void();
	}
	
	while(!chk()){
		int u=-1,qwq=inf;
		For(i,1,n)
			if(ma[i]!=mb[i] && mb[i]<qwq) qwq=mb[i],u=i;
	//	For(i,1,n) cout<<ma[i]<<" ";puts("");
	//	For(i,1,n) cout<<mb[i]<<" ";puts("");
	//	cout<<"U: "<<u<<endl;
		assert(u!=-1);
	//	cout<<"u: "<<u<<" "<<ta[u]<<" "<<tb[u]<<endl;
		if(ta[u]!=tb[u]){
			wk(a[!ta[u]][u],qwq);
		}else{
			int v=-1;
			For(i,mb[u]+1,ma[u]-1)
				if(isbig(i)){
					v=i;
					break;
				}
		//	cout<<"isbig3 "<<isbig(3)<<endl; 
			if(v==-1){
				puts("-1");
				return;
			}
			int typ=ta[u];
			wk(a[!typ][u],v);
			wk(a[typ][u],qwq);
		}
	}
	
	while(1){
		int u=inf,ui,uj;
		For(i,0,1){
			For(j,1,n){
				if(a[i][j]!=b[i][j] && b[i][j]<u)
					u=b[i][j],ui=i,uj=j;
			}
		}
		if(u==inf)break;
		wk(u,a[ui][uj]);
	}
	
	cout<<res.size()<<"\n";
	for(auto t:res){
		for(int x:t)cout<<x<<" ";
		cout<<"\n";
	}
}

signed main()
{
	int T=read();
	while(T--)work();
	return 0;
}
/*
5
4
1 4 5 7
2 3 6 8
1 4 5 2
7 3 6 8

1 4 5 7
2 3 6 8

1 4 5 7


*/

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

詳細信息

Test #1:

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

input:

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

output:

-1
1
2 1 2 2 

result:

ok correct plan (nYES = 1, nNO = 1) (2 test cases)

Test #2:

score: 0
Accepted
time: 14ms
memory: 3480kb

input:

100000
3
1 6 4
2 3 5
5 6 1
3 4 2
3
3 5 2
6 1 4
4 3 5
6 2 1
3
6 4 3
2 5 1
1 4 5
2 3 6
3
4 2 3
6 1 5
3 1 4
5 2 6
3
4 3 1
5 2 6
4 3 6
5 1 2
3
1 5 6
3 2 4
2 3 5
6 1 4
3
2 5 4
6 1 3
6 3 2
5 4 1
3
3 6 5
2 1 4
3 5 4
2 6 1
3
5 6 3
2 4 1
3 4 6
2 5 1
3
4 5 6
2 3 1
1 2 3
4 6 5
3
3 2 1
6 4 5
3 1 5
2 4 6
3
5 2 3...

output:

-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
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
4
1 3 1 1 
2 3 1 2 
1 3 1 1 
1 2 1 3 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
2 3 1 1 
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
2 2 1 1 
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok correct plan (nYES = 1646, nNO = 98354) (100000 test cases)

Test #3:

score: 0
Accepted
time: 25ms
memory: 3412kb

input:

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

output:

-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
-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
-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
...

result:

ok correct plan (nYES = 292, nNO = 99708) (100000 test cases)

Test #4:

score: 0
Accepted
time: 28ms
memory: 3500kb

input:

100000
5
4 5 10 1 2
6 9 7 3 8
4 8 5 3 6
2 10 7 1 9
5
6 10 4 8 3
7 9 1 5 2
1 6 8 2 10
3 5 4 7 9
5
3 6 2 8 9
10 7 4 5 1
8 10 3 6 2
5 1 4 7 9
5
6 1 9 4 2
3 10 7 5 8
3 6 8 1 9
4 5 7 10 2
5
8 6 1 2 4
7 10 5 9 3
7 10 9 1 3
6 8 5 4 2
5
1 5 3 9 7
4 2 8 10 6
6 2 1 9 7
8 5 4 10 3
5
9 4 10 8 3
1 6 7 5 2
7 10 2...

output:

-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
-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
-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
...

result:

ok correct plan (nYES = 51, nNO = 99949) (100000 test cases)

Test #5:

score: 0
Accepted
time: 39ms
memory: 3396kb

input:

100000
6
12 11 10 7 8 1
3 4 2 6 9 5
2 4 12 10 8 9
6 3 7 11 1 5
6
4 10 1 3 7 6
9 5 2 8 11 12
2 3 5 8 12 10
6 9 11 4 7 1
6
4 1 11 3 8 6
5 12 10 2 7 9
8 1 10 12 3 2
4 5 11 7 9 6
6
10 3 1 5 8 11
9 6 12 7 2 4
4 8 5 2 6 3
1 12 7 10 11 9
6
11 6 8 2 12 1
4 10 7 5 3 9
8 10 2 1 12 7
9 5 3 4 6 11
6
7 1 5 6 9 3...

output:

-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
-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
-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
...

result:

ok correct plan (nYES = 13, nNO = 99987) (100000 test cases)

Test #6:

score: 0
Accepted
time: 11ms
memory: 3448kb

input:

10000
20
15 26 22 6 17 32 24 29 16 8 9 27 25 28 7 11 2 40 3 14
38 13 20 31 30 33 35 10 39 4 23 1 36 21 18 19 12 34 37 5
22 34 6 30 25 31 20 28 14 37 13 2 32 1 35 27 10 11 38 8
26 39 4 19 33 29 17 40 5 21 15 7 23 16 3 24 18 9 12 36
20
16 21 19 3 36 25 2 22 23 26 12 34 9 33 14 24 40 28 35 1
13 32 4 10...

output:

-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
-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
-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
...

result:

ok correct plan (nYES = 0, nNO = 10000) (10000 test cases)

Test #7:

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

input:

1
2000
3210 3824 856 2261 3740 2833 1675 1387 380 689 1915 1152 1129 1416 145 3845 1211 1450 1328 2069 2649 347 1193 2904 2517 1373 2346 2610 1094 2736 3821 953 3997 3776 1041 539 1516 2739 129 995 1886 2201 1563 1039 173 1566 1286 2336 3283 3473 1550 2664 2854 1778 3419 2394 921 58 1500 1980 1771 5...

output:

-1

result:

ok correct plan (nYES = 0, nNO = 1) (1 test case)

Test #8:

score: 0
Accepted
time: 71ms
memory: 3400kb

input:

100000
3
1 6 4
2 3 5
1 2 4
6 5 3
3
5 3 6
1 4 2
4 3 6
1 5 2
3
3 2 4
1 5 6
3 2 4
1 6 5
3
4 5 6
2 3 1
4 5 6
2 3 1
3
3 5 4
6 2 1
3 6 5
4 2 1
3
4 3 5
2 1 6
3 5 6
2 1 4
3
2 1 3
5 6 4
2 1 3
4 6 5
3
5 4 2
6 1 3
5 4 2
6 1 3
3
1 3 5
2 4 6
1 3 6
4 5 2
3
1 4 5
2 3 6
1 4 5
6 3 2
3
6 2 1
5 4 3
4 2 1
3 5 6
3
1 3 2...

output:

2
1 2 2 1 
2 3 2 2 
1
2 2 1 1 
1
2 2 2 3 
0
2
1 3 2 1 
1 2 1 3 
3
2 3 1 1 
1 2 1 1 
1 3 1 2 
1
2 3 2 1 
0
3
2 3 2 1 
2 2 2 1 
1 3 2 2 
1
2 3 2 1 
3
1 1 2 2 
2 1 2 3 
2 3 2 2 
1
2 1 2 3 
1
1 3 2 1 
2
2 3 1 1 
2 2 2 3 
0
0
1
1 2 2 3 
2
2 2 1 1 
1 1 2 3 
2
1 1 1 3 
1 2 1 3 
2
1 1 1 2 
1 1 2 3 
0
1
1 3 ...

result:

ok correct plan (nYES = 100000, nNO = 0) (100000 test cases)

Test #9:

score: 0
Accepted
time: 107ms
memory: 3468kb

input:

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

output:

3
2 3 1 2 
1 1 1 2 
2 1 1 2 
1
1 2 2 4 
2
1 2 2 3 
2 1 1 4 
2
1 3 2 2 
1 4 2 3 
2
1 3 2 2 
1 3 1 4 
0
3
1 2 1 3 
2 4 1 3 
2 2 2 4 
1
2 2 2 1 
1
1 2 2 1 
1
1 3 2 4 
4
1 1 2 4 
2 3 2 4 
2 1 2 4 
1 3 2 1 
2
2 1 2 2 
2 4 2 1 
3
2 3 1 4 
1 2 1 3 
1 1 1 2 
2
2 3 1 1 
2 3 2 2 
3
2 3 1 4 
2 1 1 4 
2 2 2 1 
...

result:

ok correct plan (nYES = 100000, nNO = 0) (100000 test cases)

Test #10:

score: 0
Accepted
time: 163ms
memory: 3452kb

input:

100000
5
4 5 10 1 2
6 9 7 3 8
9 5 6 1 2
3 4 7 10 8
5
4 10 5 6 1
3 7 8 9 2
2 4 5 6 1
3 8 9 10 7
5
4 8 3 1 9
7 6 2 10 5
4 9 5 1 3
10 6 2 8 7
5
1 8 9 6 7
2 5 10 4 3
1 7 4 2 10
9 5 8 6 3
5
7 5 2 8 3
4 1 9 10 6
10 8 2 6 3
4 1 7 9 5
5
7 9 2 8 5
3 1 4 10 6
9 10 2 8 5
3 1 7 6 4
5
5 10 8 2 1
6 9 3 4 7
5 6 9 ...

output:

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

result:

ok correct plan (nYES = 100000, nNO = 0) (100000 test cases)

Test #11:

score: 0
Accepted
time: 256ms
memory: 3408kb

input:

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

output:

7
2 2 1 3 
1 8 1 1 
1 7 1 1 
1 4 1 6 
1 3 1 4 
2 7 1 3 
1 1 2 7 
12
2 8 1 4 
1 1 1 5 
1 3 1 8 
1 6 2 1 
2 6 2 3 
1 2 1 4 
2 3 1 5 
1 8 1 4 
1 7 2 1 
2 3 2 2 
2 3 1 7 
2 3 1 8 
6
1 1 2 6 
1 4 1 2 
2 7 1 3 
1 4 2 7 
2 1 1 4 
2 8 1 5 
7
2 7 1 3 
1 7 2 4 
1 7 2 6 
2 8 2 2 
1 3 2 1 
2 8 2 5 
2 8 1 7 
7
2...

result:

ok correct plan (nYES = 62500, nNO = 0) (62500 test cases)

Test #12:

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

input:

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

output:

11
1 9 1 10 
2 1 2 7 
1 1 1 2 
2 1 2 7 
2 5 1 10 
2 9 2 1 
2 4 1 3 
1 2 1 8 
2 9 2 5 
1 6 2 4 
2 9 1 6 
14
1 7 2 4 
1 5 2 1 
2 5 2 7 
2 2 2 8 
1 2 1 5 
1 3 1 10 
1 9 2 1 
1 5 2 3 
1 6 1 9 
2 7 1 5 
2 7 1 6 
1 10 2 8 
2 4 1 10 
2 4 2 7 
12
1 5 2 6 
2 5 1 4 
1 3 1 5 
2 1 2 2 
2 1 2 9 
2 1 1 4 
2 1 2 3...

result:

ok correct plan (nYES = 40000, nNO = 0) (40000 test cases)

Test #13:

score: 0
Accepted
time: 128ms
memory: 3400kb

input:

10000
20
15 26 22 6 17 32 24 29 16 8 9 27 25 28 7 11 2 40 3 14
38 13 20 31 30 33 35 10 39 4 23 1 36 21 18 19 12 34 37 5
15 12 18 6 17 32 30 13 16 28 40 27 14 20 7 11 2 9 3 33
25 24 37 36 26 21 23 10 31 4 8 1 29 39 19 22 38 35 34 5
20
17 1 39 27 13 25 12 3 35 21 28 33 16 29 22 40 20 19 8 6
32 37 10 9...

output:

24
2 11 1 10 
1 18 1 11 
1 2 2 17 
2 13 2 15 
1 13 1 20 
1 3 2 13 
1 14 2 3 
2 6 2 14 
2 7 1 10 
2 2 1 8 
2 16 2 15 
2 13 2 16 
1 7 2 2 
1 20 2 1 
2 17 2 5 
2 3 1 10 
1 7 2 13 
2 17 1 7 
2 4 2 9 
2 14 1 20 
2 18 2 19 
2 3 2 18 
2 17 2 4 
2 14 2 17 
22
2 13 1 8 
1 16 1 13 
2 16 1 7 
2 17 1 16 
2 6 1 ...

result:

ok correct plan (nYES = 10000, nNO = 0) (10000 test cases)

Test #14:

score: 0
Accepted
time: 71ms
memory: 3484kb

input:

2500
40
20 66 71 79 65 73 42 2 27 63 16 35 45 56 49 52 1 24 78 5 21 15 47 80 68 64 54 11 13 26 39 50 77 29 72 75 62 53 23 30
14 8 51 6 28 67 12 18 70 61 17 34 41 10 59 36 43 9 46 33 74 37 25 40 19 57 31 48 22 55 76 7 4 60 69 58 38 44 32 3
44 53 45 57 17 35 59 2 27 24 16 38 28 69 48 33 1 67 22 5 21 1...

output:

54
1 5 2 11 
1 35 1 1 
2 35 2 8 
1 36 1 35 
1 19 2 29 
1 10 1 18 
1 13 2 5 
2 15 1 40 
1 37 2 20 
2 37 2 39 
1 16 1 37 
1 6 1 12 
1 26 2 16 
1 38 2 39 
2 38 2 22 
1 3 2 5 
1 38 1 12 
2 13 1 27 
1 7 1 35 
2 17 1 23 
2 22 1 1 
2 19 2 9 
2 17 1 37 
2 28 1 15 
2 28 2 30 
1 32 2 29 
2 3 2 6 
2 17 1 38 
2...

result:

ok correct plan (nYES = 2500, nNO = 0) (2500 test cases)

Test #15:

score: 0
Accepted
time: 59ms
memory: 3512kb

input:

1600
50
19 11 69 62 13 54 23 56 65 83 21 17 95 91 9 100 48 18 22 53 74 3 59 5 27 36 16 58 50 80 68 78 42 88 73 6 10 15 35 67 28 81 38 43 72 76 29 84 1 45
44 99 32 79 4 71 8 47 87 52 89 93 96 77 86 37 57 30 55 64 46 25 7 92 90 33 70 97 66 31 40 85 12 94 24 20 39 82 51 41 2 26 61 75 49 98 63 60 14 34
...

output:

63
1 50 1 5 
2 46 2 49 
1 14 2 36 
2 28 1 7 
2 29 1 41 
1 29 2 22 
2 44 2 29 
2 43 2 18 
2 9 2 50 
1 48 1 26 
1 10 1 43 
2 6 2 37 
1 45 1 33 
2 4 2 1 
1 4 1 44 
1 21 2 4 
2 17 1 5 
2 20 2 21 
2 32 2 22 
2 34 2 39 
2 13 2 10 
1 17 2 38 
2 45 2 37 
1 20 1 8 
1 6 2 4 
2 19 1 42 
1 20 1 13 
1 5 1 32 
1 ...

result:

ok correct plan (nYES = 1600, nNO = 0) (1600 test cases)

Test #16:

score: 0
Accepted
time: 36ms
memory: 3484kb

input:

400
100
180 101 194 36 166 121 61 174 94 153 40 140 102 96 93 68 145 24 16 85 183 55 172 176 181 198 45 81 158 165 99 132 12 29 182 125 190 52 129 141 113 46 189 120 138 199 130 167 106 196 136 78 76 127 13 43 123 144 30 108 82 114 60 35 1 142 8 32 200 86 70 112 155 192 31 119 73 20 90 14 39 168 69 ...

output:

141
1 51 2 84 
2 47 2 81 
1 47 1 85 
1 49 2 47 
2 40 2 42 
1 40 2 49 
2 71 2 40 
1 24 2 18 
2 66 2 67 
1 66 2 4 
1 50 2 7 
2 50 2 66 
1 93 1 50 
2 17 1 71 
2 28 2 59 
1 82 2 75 
1 26 1 53 
2 26 2 93 
1 44 1 26 
1 43 2 51 
2 43 2 63 
1 48 1 43 
2 95 2 80 
1 95 1 28 
2 57 2 95 
1 74 1 20 
2 14 1 70 
2...

result:

ok correct plan (nYES = 400, nNO = 0) (400 test cases)

Test #17:

score: 0
Accepted
time: 25ms
memory: 3496kb

input:

100
200
276 115 118 75 252 391 300 241 341 172 95 30 134 371 53 261 218 328 70 169 312 189 379 381 107 262 273 398 187 329 123 212 207 364 184 269 229 277 331 347 197 225 320 236 230 351 296 213 182 268 32 186 37 29 369 34 168 202 346 46 198 265 377 10 290 193 148 224 180 393 233 65 114 167 50 397 2...

output:

274
2 172 1 146 
1 6 2 143 
1 24 1 172 
2 24 2 54 
1 94 1 24 
2 42 2 117 
1 63 2 106 
2 104 2 72 
1 104 2 15 
2 137 2 104 
2 67 2 6 
1 9 2 75 
1 165 2 158 
2 120 2 4 
2 87 1 99 
2 130 1 198 
1 130 1 73 
2 66 2 130 
1 18 2 60 
1 183 1 13 
2 183 2 92 
1 101 1 183 
2 57 1 188 
2 141 2 131 
2 68 2 101 
...

result:

ok correct plan (nYES = 100, nNO = 0) (100 test cases)

Test #18:

score: 0
Accepted
time: 16ms
memory: 3472kb

input:

16
500
937 228 200 167 830 159 627 860 548 749 95 747 312 999 138 101 541 896 699 647 646 279 360 707 890 822 425 441 852 96 526 899 585 701 223 321 264 934 595 267 259 772 81 178 339 557 163 677 359 343 779 738 838 106 516 121 338 191 345 579 295 650 663 470 485 388 293 500 135 364 532 949 496 263 ...

output:

758
1 229 1 80 
2 4 1 340 
1 131 2 209 
2 309 2 236 
2 285 1 427 
1 486 1 81 
1 495 2 470 
1 329 1 309 
2 203 1 43 
1 317 2 413 
2 71 1 264 
1 92 2 152 
2 157 1 285 
2 415 1 56 
2 345 2 459 
2 212 1 69 
1 337 1 415 
2 64 2 131 
1 105 2 317 
1 360 1 47 
2 360 2 398 
2 241 2 92 
1 241 1 360 
1 116 2 2...

result:

ok correct plan (nYES = 16, nNO = 0) (16 test cases)

Test #19:

score: 0
Accepted
time: 13ms
memory: 3668kb

input:

4
1000
1506 1787 219 1614 1499 427 1175 1054 871 492 1115 1522 1028 1761 997 177 1086 1942 1821 1351 100 20 1128 1222 1606 1291 952 1495 816 888 841 462 113 1871 652 1519 764 208 1009 849 1061 1660 655 1133 114 1899 838 982 1038 1742 1011 1692 542 636 119 647 530 194 1215 1471 1224 506 1107 1642 171...

output:

1512
2 374 2 980 
2 905 2 449 
1 669 2 210 
2 589 2 221 
1 445 1 262 
1 144 1 501 
2 937 1 809 
2 354 1 212 
1 354 1 111 
1 387 2 354 
1 32 2 144 
2 949 2 32 
1 1000 2 261 
1 673 1 38 
2 911 2 613 
2 101 2 76 
2 203 2 321 
1 663 2 630 
2 663 1 757 
1 624 1 663 
1 384 2 705 
2 855 1 779 
2 318 2 445 ...

result:

ok correct plan (nYES = 4, nNO = 0) (4 test cases)

Test #20:

score: 0
Accepted
time: 19ms
memory: 3696kb

input:

1
2000
3210 3824 856 2261 3740 2833 1675 1387 380 689 1915 1152 1129 1416 145 3845 1211 1450 1328 2069 2649 347 1193 2904 2517 1373 2346 2610 1094 2736 3821 953 3997 3776 1041 539 1516 2739 129 995 1886 2201 1563 1039 173 1566 1286 2336 3283 3473 1550 2664 2854 1778 3419 2394 921 58 1500 1980 1771 5...

output:

2979
2 622 1 1574 
2 1497 1 1307 
2 123 2 687 
1 141 1 987 
1 1009 1 455 
2 280 1 1256 
2 1813 2 596 
2 17 2 1408 
1 98 1 1419 
1 685 1 1633 
2 685 1 1720 
2 295 1 685 
1 641 1 102 
2 1010 2 121 
1 398 1 1438 
2 319 1 829 
1 802 2 1245 
2 207 1 280 
2 63 1 1644 
1 1003 1 614 
2 1821 2 1016 
2 453 2 ...

result:

ok correct plan (nYES = 1, nNO = 0) (1 test case)