Report
Test instructions: Gives a sequence of length n, the number of operations is m;n and m (1≤ n, m ≤200 000), the operation is divided into T R, when T = 1 means that the [1,r] sequence is sorted by non-descending order, T = 2 means that the sequence [1,r] by non-ascending order; output m-operation sequence?
Idea: Because the sort is the prefix sort, then the preceding Operation Ti,ri; if Ri <= RJ, then the I operation is directly overwritten. In this way we can know that the useful sort operation Ri is strictly decremented, and at this point the number between RI and R (i + 1) is irrelevant to the subsequent operation ~ ~ (linear processing), which directly illustrates the need to sort only once, that is, for [1,max (RI)] sort, Then directly using the double pointer in the sorted array to find the corresponding value to fill in the result array;
#include <bits/stdc++.h>using namespacestd;typedef __int64 ll;template<typename t>voidRead1 (T &m) {T x=0, f=1;CharCh=GetChar (); while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} M= x*F;} Template<typename t>voidRead2 (T &a,t &b) {Read1 (a); Read1 (b);} Template<typename t>voidRead3 (T &a,t &b,t &B) {Read1 (a); Read1 (b); Read1 (c);}Const intN =200200;intA[n],b[n],t[n],r[n],p[n],q[n];intMain () {intn,m; Read2 (N,M); for(inti =1; I <= n;i++) read1 (A[i]), b[i] =A[i]; for(inti =1; I <= m;i++) read2 (T[i],r[i]); intMX =0, cnt =0; for(inti = M;i >=1; i--) {//Add MX in reverse order, compress useful sort; if(R[i] >mx) MX= r[i],p[++cnt] = r[i],q[cnt] =T[i]; } p[0] =0;//complete processing;Sort (b +1, B + mx +1);//a The final ordered elements can be found in B; intLa =1, RA = mx, lb =1, RB =MX; for(inti = cnt;i >0; i--){ if(Q[i] = =1) for(Ra > P[i-1];ra--, rb--) A[ra] =B[RB]; Else for(Ra > P[i-1];ra--, lb++) A[ra] =B[LB]; } for(inti =1; I <= n;i++) printf ("%d", A[i]); return 0;}
Codeforces Round #344 (Div. 2) C. Report