QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#153692#6352. SPPPSPSS.PhantomThreshold#TL 127ms40592kbC++204.8kb2023-08-30 19:01:352023-08-30 19:01:36

Judging History

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

  • [2023-08-30 19:01:36]
  • 评测
  • 测评结果:TL
  • 用时:127ms
  • 内存:40592kb
  • [2023-08-30 19:01:35]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MOD=993244853;
int S=100,pw[1111111];
struct node
{
	int siz;
	int h;
	int lson,rson;
}pool[21000050];
void upd(int cur)
{
	pool[cur].siz=0;
	pool[cur].h=0;
	if(pool[cur].lson)
	{
		pool[cur].h=(pool[cur].h+1ll*pool[pool[cur].lson].h*pw[pool[cur].siz])%MOD;
		pool[cur].siz+=pool[pool[cur].lson].siz;
	}
	if(pool[cur].rson)
	{
		pool[cur].h=(pool[cur].h+1ll*pool[pool[cur].rson].h*pw[pool[cur].siz])%MOD;
		pool[cur].siz+=pool[pool[cur].rson].siz;
	}
}
int top;
queue<int> recycle;
int nn(int l,int r)
{
	int tmp;
	if(recycle.empty())
	{
		tmp=++top;
//		if(top%100000==0)cerr<<"mem "<<top<<endl;
	}
	else tmp=recycle.front(),recycle.pop();
	pool[tmp].lson=pool[tmp].rson=0;
	pool[tmp].siz=1;pool[tmp].h=l;
	return tmp;
}
int build(int l,int r,int pos)
{
	int tmp=nn(l,r);
//	cerr<<"build "<<tmp<<' '<<l<<' '<<r<<endl;
	if(l==r)return tmp;
	int mid=(l+r)/2;
	if(pos<=mid)pool[tmp].lson=build(l,mid,pos);
	else pool[tmp].rson=build(mid+1,r,pos);
	upd(tmp);
	return tmp;
}
int merge(int u,int v,int l,int r)
{
	if(not u or not v)return u|v;
//	cerr<<"merge "<<u<<' '<<v<<' '<<l<<' '<<r<<endl;
	int mid=(l+r)/2;
	pool[u].lson=merge(pool[u].lson,pool[v].lson,l,mid);
	pool[u].rson=merge(pool[u].rson,pool[v].rson,mid+1,r);
	recycle.push(v);
	upd(u);
	return u;
}
pair<int,int> split(int cur,int lsiz,int l,int r)
{
//	cerr<<"split "<<cur<<' '<<lsiz<<' '<<l<<' '<<r<<endl;
	if(lsiz==0)return {0,cur};
	if(lsiz==pool[cur].siz)return {cur,0};
	int ex=nn(l,r);
	int mid=(l+r)/2;
	int ls=pool[cur].lson,rs=pool[cur].rson;
	if(pool[ls].siz<=lsiz)
	{
		auto [curr,exr]=split(rs,lsiz-pool[ls].siz,mid+1,r);
		pool[cur].rson=curr;
		pool[ex].rson=exr;
	}
	else
	{
		swap(pool[cur].rson,pool[ex].rson);
		auto [curl,exl]=split(ls,lsiz,l,mid);
		pool[cur].lson=curl;
		pool[ex].lson=exl;
	}
	upd(cur);
	upd(ex);
	return make_pair(cur,ex);
}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	int n;
	cin>>n;
	pw[0]={1};
	vector<int> a(n+5);
	for(int i=1;i<=n;i++)
	{
		a[i]=n-i+1;
		cin>>a[i];
		pw[i]=1ll*pw[i-1]*S%MOD;
	}
	auto solve=[&](int ty)
	{
//		cerr<<"solve "<<ty<<endl;
		top=0;while(not recycle.empty())recycle.pop();
		deque<int> dq;
		int now=0,target=0;
		for(int i=1;i<=n;i++)
		{
			target=(target+1ll*pw[i-1]*i)%MOD;
		}
		for(int i=1;i<=n;i++)
		{
			int nd=build(1,n,a[i]);
			dq.push_back(nd);
			now=(now+1ll*pw[i-1]*pool[nd].h)%MOD;
		}
		if(now==target)return 0;
		for(int i=1;i<=n;i++,ty^=1)
		{
//			cerr<<"round "<<i<<" type "<<ty<<endl;
//			for(auto idx:dq){cerr<<idx<<' '<<pool[idx].h<<endl;}//cerr<<endl;
			if(i==1)continue;
			if(ty==0)
			{
				int lsiz=0;
				int tmp=dq.front();dq.pop_front();
//				cerr<<"pop0 "<<tmp<<' '<<pool[tmp].siz<<endl;
				now=(now-1ll*pw[lsiz]*pool[tmp].h%MOD+MOD)%MOD;
//				cerr<<"now "<<now<<endl;
				lsiz+=pool[tmp].siz;
				while(lsiz<i)
				{
					int tmp2=dq.front();dq.pop_front();
//					cerr<<"pop "<<tmp2<<' '<<pool[tmp2].siz<<endl;
					now=(now-1ll*pw[lsiz]*pool[tmp2].h%MOD+MOD)%MOD;
//					cerr<<"now "<<now<<endl;
					if(lsiz+pool[tmp2].siz>=i)
					{
//						cerr<<"lsiz "<<i-lsiz<<endl;
						auto [L,R]=split(tmp2,i-lsiz,1,n);
						if(R)
						{
//							cerr<<"splitted "<<R<<' '<<pool[R].h<<endl;
							dq.push_front(R);
							now=(now+1ll*pw[i]*pool[R].h)%MOD;
						}
						int m=merge(tmp,L,1,n);
//						cerr<<"merged "<<m<<' '<<pool[m].siz<<' '<<pool[m].h<<endl;
						dq.push_front(m);
						now=(now+1ll*pw[0]*pool[m].h)%MOD;
					}
					else
					{
						tmp=merge(tmp,tmp2,1,n);
					}
					lsiz+=pool[tmp2].siz;
				}
			}
			else
			{
				int lsiz=n;
				int tmp=dq.back();dq.pop_back();
//				cerr<<"pop0 "<<tmp<<' '<<pool[tmp].siz<<endl;
				lsiz-=pool[tmp].siz;
				now=(now-1ll*pw[lsiz]*pool[tmp].h%MOD+MOD)%MOD;
				while(n-lsiz<i)
				{
					int tmp2=dq.back();dq.pop_back();
//					cerr<<"pop "<<tmp2<<' '<<pool[tmp2].siz<<endl;
					lsiz-=pool[tmp2].siz;
					now=(now-1ll*pw[lsiz]*pool[tmp2].h%MOD+MOD)%MOD;
					if(n-lsiz>=i)
					{
//						cerr<<"lsiz "<<n-i-lsiz<<endl;
						auto [L,R]=split(tmp2,n-i-lsiz,1,n);
						if(L)
						{
//							cerr<<"splitted "<<L<<endl;
							dq.push_back(L);
							now=(now+1ll*pw[lsiz]*pool[L].h)%MOD;
						}
						int m=merge(R,tmp,1,n);
//						cerr<<"merged "<<m<<endl;
						dq.push_back(m);
						now=(now+1ll*pw[n-i]*pool[m].h)%MOD;
					}
					else
					{
						tmp=merge(tmp2,tmp,1,n);
					}
				}
			}
//			cerr<<now<<','<<target<<endl;
			if(now==target)return i;
		}
		return n;
	};
	int l0=solve(0);
	int l1=solve(1);
//	cerr<<"ans "<<l0<<' '<<l1<<endl;
	if(l0<l1)
	{
		for(int i=1;i<=l0;i++)cout<<"SP"[i%2];
		cout<<".";
	}
	else
	{
		for(int i=1;i<=l1;i++)cout<<"PS"[i%2];
		cout<<".";
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 5524kb

input:

3
1 2 3

output:

.

result:

ok OK 0 operations

Test #2:

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

input:

2
2 1

output:

SP.

result:

ok OK 2 operations

Test #3:

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

input:

9
3 2 4 1 5 6 7 9 8

output:

SPSP.

result:

ok OK 4 operations

Test #4:

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

input:

10
2 9 5 7 10 6 3 1 8 4

output:

SPSPSPSP.

result:

ok OK 8 operations

Test #5:

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

input:

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

output:

PSPSPSPS.

result:

ok OK 8 operations

Test #6:

score: 0
Accepted
time: 2ms
memory: 5636kb

input:

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

output:

SPSPSPSPSPSPSP.

result:

ok OK 14 operations

Test #7:

score: 0
Accepted
time: 2ms
memory: 5864kb

input:

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

output:

SPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPS.

result:

ok OK 57 operations

Test #8:

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

input:

1000
668 554 210 852 617 846 561 95 341 893 276 224 287 1000 356 362 897 205 369 654 181 590 339 377 346 557 382 593 55 62 126 899 49 509 977 585 614 232 865 800 790 292 219 957 379 914 946 246 294 403 940 517 768 623 376 624 331 353 887 626 424 449 115 628 569 809 956 942 300 894 61 936 678 779 549...

output:

SPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSP...

result:

ok OK 523 operations

Test #9:

score: 0
Accepted
time: 127ms
memory: 40592kb

input:

100000
30619 15529 4854 9258 46894 29948 59533 56945 19473 7608 42291 95532 80537 83105 70434 68130 89221 96367 26768 43837 54765 52814 88446 14950 63224 63479 11957 41446 38702 8466 85556 57724 50097 29014 17961 65178 88627 96815 80115 79096 19625 2979 51033 68224 48649 96250 3406 96433 22584 79610...

output:

SPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSPSP...

result:

ok OK 50224 operations

Test #10:

score: -100
Time Limit Exceeded

input:

999999
1578 253230 300479 227250 673195 324827 649281 5836 935739 543519 370574 305888 969960 550993 463132 799873 408104 207874 140152 331798 698935 749195 181667 828624 142806 789266 207545 870039 88700 189925 952818 455047 184020 276480 107352 733977 864792 660399 680663 667372 602838 139419 6373...

output:


result: