QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#347158 | #6352. SPPPSPSS. | chenxinyang2006 | WA | 0ms | 3772kb | C++14 | 4.2kb | 2024-03-09 11:43:13 | 2024-03-09 11:43:13 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define db double
#define ldb long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define eb emplace_back
#define SZ(S) (int)S.size()
//#define mod 998244353
//#define mod 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
using namespace std;
template <class T>
void chkmax(T &x,T y){
if(x < y) x = y;
}
template <class T>
void chkmin(T &x,T y){
if(x > y) x = y;
}
inline int popcnt(int x){
return __builtin_popcount(x);
}
inline int ctz(int x){
return __builtin_ctz(x);
}
/*ll power(ll p,int k = mod - 2){
ll ans = 1;
while(k){
if(k % 2 == 1) ans = ans * p % mod;
p = p * p % mod;
k /= 2;
}
return ans;
}*/
int n;
int a[1000005],b[1000005],Mx[1000005],Mn[1000005],sum[1000005];
int c[1000005];
struct node{
int sum,tag,len;
}tree[4000005];
#define ls (rt * 2)
#define rs (rt * 2 + 1)
void upd(int rt,int C){
tree[rt].sum = C * tree[rt].len;
tree[rt].tag = C;
}
void pushdown(int rt){
if(tree[rt].tag == -1) return;
upd(ls,tree[rt].tag);
upd(rs,tree[rt].tag);
tree[rt].tag = -1;
}
void pushup(int rt){
tree[rt].sum = tree[ls].sum + tree[rs].sum;
}
void build(int rt,int l,int r){
tree[rt].len = r - l + 1;
tree[rt].tag = -1;
if(l == r){
tree[rt].sum = c[l];
return;
}
int mid = (l + r) >> 1;
build(ls,l,mid);build(rs,mid+1,r);
pushup(rt);
}
void upload(int rt,int l,int r,int L,int R,int C){
if(l == L && r == R){
upd(rt,C);
return;
}
int mid = (l + r) >> 1;
pushdown(rt);
if(R <= mid){
upload(ls,l,mid,L,R,C);
}else if(L > mid){
upload(rs,mid+1,r,L,R,C);
}else{
upload(ls,l,mid,L,mid,C);
upload(rs,mid+1,r,mid+1,R,C);
}
pushup(rt);
}
int kth(int rt,int l,int r,int k){//kth 1
if(l == r) return l;
int mid = (l + r) >> 1;
pushdown(rt);
if(k > tree[ls].sum) return kth(rs,mid+1,r,k - tree[ls].sum);
return kth(ls,l,mid,k);
}
int _kth(int rt,int l,int r,int k){//kth 0
if(l == r) return l;
int mid = (l + r) >> 1;
pushdown(rt);
if(k > tree[ls].len - tree[ls].sum) return _kth(rs,mid+1,r,k - tree[ls].len + tree[ls].sum);
return _kth(ls,l,mid,k);
}
int query(int rt,int l,int r,int L,int R){
if(L > R) return 0;
// if(l == 1 && r == n) printf("query [%d,%d]\n",L,R);
if(l == L && r == R) return tree[rt].sum;
int mid = (l + r) >> 1;
pushdown(rt);
if(R <= mid) return query(ls,l,mid,L,R);
else if(L > mid) return query(rs,mid+1,r,L,R);
else return query(ls,l,mid,L,mid) + query(rs,mid+1,r,mid+1,R);
}
int slv(){
rep(i,1,n){
sum[i] = sum[i - 1] + (a[i] != i);
Mx[i] = max(Mx[i - 1],a[i]);
b[i] = a[i];
}
if(sum[n] == n) return 0;
Mn[n + 1] = n + 1;
per(i,n,1) Mn[i] = min(Mn[i + 1],a[i]);
int p = 1,q = n + 1,ret = 1;
while(1){
if(Mx[p] == p && Mn[q] == q && sum[q - 1] == sum[p]) return ret;
if(ret & 1){
q -= 2;
ret++;
if(p >= q){
sort(b + 1,b + p + 1);
sort(b + q,b + n + 1);
break;
}
}else{
p += 2;
ret++;
if(p >= q){
sort(b + q,b + n + 1);
sort(b + 1,b + p + 1);
break;
}
}
}
fill(c,c + n + 1,0);
if(ret & 1) rep(i,1,p) c[b[i]] = 1;
else rep(i,1,q - 1) c[b[i]] = 1;
build(1,1,n);
// printf("p=%d q=%d ret=%d\n",p,q,ret);
// rep(i,1,n) printf("%d ",b[i]);
// printf("\n");
int pos;
while(1){
if(ret & 1){
if(query(1,1,n,1,p) == p) break;
q -= 2;
pos = kth(1,1,n,q);
upload(1,1,n,pos,n,0);
}else{
if(query(1,1,n,1,q - 1) == q - 1) break;
p += 2;
pos = _kth(1,1,n,p - q + 1);
upload(1,1,n,1,pos,1);
}
ret++;
}
return ret;
}
int main(){
// freopen("test.in","r",stdin);
scanf("%d",&n);
rep(i,1,n) scanf("%d",&a[i]);
int ans1 = slv();
reverse(a + 1,a + n + 1);
rep(i,1,n) a[i] = n + 1 - a[i];
int ans2 = slv();
if(ans1 <= ans2){
rep(i,1,ans1){
if(i & 1) printf("P");
else printf("S");
}
printf(".\n");
return 0;
}else{
rep(i,1,ans2){
if(i & 1) printf("S");
else printf("P");
}
printf(".\n");
return 0;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3772kb
input:
3 1 2 3
output:
P.
result:
wrong answer Jury (0) found answer better than participant (1)