Description
There is a array contain N (1<n<=100000) numbers. Now give you M (1<m<10000) query.
Every query would be:
1 X:ask longest substring which every number no less than X
2 y X:change the a[y] to X. There is at the very change times.
For each ask can you tell me the length of longest substring.
Input
There is multiple tests.
Each test first line contain the integer numbers n m,second line contain n integer numbers.
Next M lines Each line would be:
1 X:ask longest substring which every number no less than X
2 y X:change the a[y] to X. There is at the very change times.
0 < N <= 100000, 0 < M <= 10000, -1000000000 <= a[i] <= 1000000000
Output
Each ask output the length of longest substring.
Sample Input
5 51 2 3 2 11 21 32 3 11 21 3
Sample Output
3110 preprocess The maximum length of the n number of values to reach. Insert by value from large to small. Then record a vis[i], l[i], r[i]. Indicates whether this data is inserted, to the left to reach the farthest, to the right to reach the farthest. Operation 1 is a direct 2-point answer. Operation 2 for a maximum of 10, just one more direct violence.
#include <iostream>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<vector>#include<queue>#include<map>#include<Set>#include<stack>#include<algorithm>using namespaceStd;typedefLong LongLl;typedef pair<int,int>PII;Const intMoD = 1e9+7;Const intN =100005 ;#defineX First#defineY SecondintN, Q, a[n];structOK {intVis[n], l[n], r[n]; voidinit () {memset (Vis,false,sizeofvis); for(inti =1; I <= N; ++i) L[i] = r[i] =i; } intGetlen (inti) {returnR[i]-l[i] +1 ; } voidRelax (inti) {if(vis[i+1]) R[i] = r[i+1]; if(vis[i-1]) L[i] = l[i-1], r[l[i-1]] =R[i]; if(vis[i+1]) l[r[i+1]] =L[i]; }}e;structnode{intx, res, id; BOOL operator< (ConstNode &a)Const { returnX <a.x; }}p[n];voidTest () { for(inti =1; I <= N; ++i) cout << E.l[i] <<' '; cout <<Endl; for(inti =1; I <= N; ++i) cout << E.r[i] <<' '; cout <<Endl; for(inti =1; I <= N; ++i) cout<< p[i].x <<' '<< P[i].res <<Endl;}voidSolve () { for(inti =1; I <= N; ++i) {p[i].x= A[i], p[i].id =i; } sort (P+1, p + n +1 ) ; E.init (); P[n+1].res =0 ; for(inti = n; i >0; --i) {intID =p[i].id; E.vis[id]=true ; E.relax (ID); P[i].res= Max (p[i+1].res, E.getlen (p[i].id)); }}intFind (intnum) { intL =1, R = N, pos =0 ; if(Num > p[n].x)return 0; while(L <=r) {intMid = (l+r) >>1; if(P[mid].x <num) L= Mid +1 ; ElsePOS= Mid, R = mid-1 ; } returnp[pos].res;}voidRun () { for(inti =1; I <= N; ++i) {scanf ("%d",&A[i]); } Solve ();//test (); while(q--){ intop, x, y; scanf ("%d%d",&op,&x); if(OP = =1) {printf ("%d\n", Find (x)); } Else{scanf ("%d",&y); A[X]=y; Solve ();//test (); } }}intMain () {#ifdef LOCAL freopen ("In.txt","R", stdin); #endif //LOCAL while(SCANF ("%d%d", &n,&q)! =EOF) Run ();}View Code
Fzu 2059 MM