ZJOI2007 Report Statistics

Source: Internet
Author: User

Transmission Door

The problem is still quite interesting.

At first I had the idea of a very sand sculpture. Now that he's asking for interpolation in the back of a wish sequence, this excellent operation, of course, is done with vectors! Then every time the interpolation will affect its front and back, directly so update on the finished! The following one with the maintenance of a balance tree to find a successor, update the minimum value of the difference is good!

Then happy to turn up the zero ...

Come back and think ... You do affect the front and back, but it also affects the minimum value ...

Ah! Well, we'll use multi set!.

And then hand it over to T.

The power of the STL Army must be opened O2 to show!

Then he was surprised to find that he had written a program that could only get big data 233333.

Later found ... When you insert a number, it will not affect the previous one and the previous one number ... What do you mean by deleting the difference between them? So he handed in a.

Ovo Well this is not practice splay, it is to see how low IQ.

//Luogu-judger-enable-o2#include <iostream>#include<cstdio>#include<cmath>#include<algorithm>#include<queue>#include<cstring>#include<vector>#include<Set>#defineRep (i,a,n) for (int i = a;i <= n;i++)#definePer (i,n,a) for (int i = n;i >= a;i--)#defineEnter Putchar (' \ n ')#defineDe Putchar (' # ')#definePR pair<int,int>#defineMP Make_pair#defineFi first#defineSC Second#definePB Push_backusing namespaceStd;typedefLong Longll;Const intM =500005;Const intN =10000005;Const intINF =1000000009; intRead () {intAns =0, op =1; CharCH =GetChar ();  while(Ch <'0'|| CH >'9')    {    if(ch = ='-') op =-1; CH=GetChar (); }     while(Ch >='0'&& CH <='9') {ans*=Ten; Ans+ = CH-'0'; CH=GetChar (); }    returnAns *op;}structnode{intfa,ch[2],size,cnt,val;} T[m<<1];vector<int>V[m];multiset<int>Q;multiset<int>:: iterator it;intN,m,x,root,tot,minn = Inf,minx =Inf,idx,a;Chars[ the];BOOL Get(intx) {    returnt[t[x].fa].ch[1] ==x;}voidPushup (intx) {T[x].size= t[t[x].ch[0]].size + t[t[x].ch[1]].size +t[x].cnt;}voidRotateintx) {    inty = t[x].fa,z = T[y].fa,k =Get(x); t[z].ch[t[z].ch[1] = = Y] = X,T[X].FA =Z; T[Y].CH[K]= t[x].ch[k^1],T[T[Y].CH[K]].FA =y; T[x].ch[k^1] = Y,T[Y].FA =x; Pushup (x), pushup (y);}voidSplay (intXintgoal) {     while(T[x].fa! =goal) {    inty = T[x].fa,z =T[y].fa; if(Z! = goal) (t[y].ch[1] = = x) ^ (t[z].ch[1] = = y)?Rotate (x): Rotate (y);    Rotate (x); }    if(!goal) root =x;}BOOLInsertintx) {    intU = root,f =0; BOOLFlag =0;  while(U && x! = t[u].val) F = u,u = t[u].ch[x >T[u].val]; if(u) T[u].cnt++,flag =1; Else{u= ++idx; if(f) t[f].ch[x > T[f].val] =u; t[u].ch[0] = t[u].ch[1] =0; T[U].FA= F,t[u].val = X,t[u].size = t[u].cnt =1; } splay (U,0); returnFlag;}intPre () {intU = t[root].ch[0]; if(!u)returnINF;  while(t[u].ch[1]) U = t[u].ch[1]; returnT[u].val;}intNext () {intU = t[root].ch[1]; if(!u)returnINF;  while(t[u].ch[0]) U = t[u].ch[0]; returnT[u].val;}voidModiintXinta) {    intL = (int) (V[x].size ()-1); if(X! =N) {It= Q.find (ABS (v[x][l]-v[x+1][0])); if(It! =q.end ()) q.erase (it);    } V[X].PB (a); Q.insert (ABS (V[x][l+1]-v[x][l])); if(x! = N) Q.insert (ABS (v[x][l+1]-v[x+1][0]));}intMain () {n= Read (), M = Read (), insert (INF), insert (-INF); X= Read (), v[1].PB (x), insert (x); Rep (I,2, N) {x= Read (), V[I].PB (x), Q.insert (ABS (v[i][0]-v[i-1][0])); if(insert (x)) Minx =0; if(Minx = =0)Continue; intA1 = Pre (), a2 =next (); Minx= Min (Minx,min (ABS (A1-X), ABS (a2-x)); }    //printf ("%d\n", * (Q.begin ()));Rep (I,1, M) {scanf ("%s", s); if(s[0] =='I') {x= Read (), a =read ();        Modi (x,a); if(Insert (a)) Minx =0; if(Minx = =0)Continue; intA1 = Pre (), a2 =next (); //printf ("#%d%d\n", a1,a2);Minx = min (minx,min (ABS (A1-A), ABS (a2-a)); }    Else if(s[4] =='G') printf ("%d\n",*(Q.begin ())); Else if(s[4] =='S') printf ("%d\n", Minx); }    return 0;}

ZJOI2007 Report Statistics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.