Fzu 2059 MM (and check set + sort insert)

Source: Internet
Author: User
Tags integer numbers

problem 2059 MMaccept:109 submit:484
Time limit:1000 mSec Memory limit:32768 KB problem 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

Outputeach ask output the length of longest substring. Sample INPUT5 2 3 2 3 3 sample Output3110 test instructions: Give a sequence, two operations, the first operation is to enter an X, find a substring satisfies each element's value is not less than X and the maximum length, output this maximum value, the first Two operations are input x and Y, modify a[y]=x, the second operation up to only 10 times thought: O (nlogn) preprocessing, O (logn) query. Because the modification operation only 10 times, so each modification is directly violent pre-treatment, and then consider the situation without modifying the operation. Preprocessing methods: Sorting the sequence values, and then from large to small insert, with and check the set to maintain the maximum length of the inserted point can be connected, in this process to maintain a max, the maximum value is the answer.
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespaceStd;typedefLong LongLl;typedef pair<int,int>PII;Const intINF =1e9;Const DoubleEPS = 1e-6;Const intN =100010;intCAS =1;struct_node{intPos,val,ans; FriendBOOL operator< (Const_node &a,Const_node &b) {returnA.val <B.val; }};intn,m;intFa[n],sum[n],b[n],mxval;_node A[n];intFindintx) {    returnfa[x]==x?x:fa[x]=find (Fa[x]);}voidUnintUintv) {u=find (u), v=Find (v); Fa[u]=v; SUM[V]+=sum[u];}voidPre () {memset (sum,0,sizeof(sum)); Mxval=-inf-Ten;  for(intI=0; i<n;i++) fa[i]=i;  for(intI=0; i<n;i++) {A[i].val=b[i],a[i].pos=i; if(A[i].val > Mxval) mxval =A[i].val; } sort (A,a+N); intMX =0;  for(inti=n-1; i>=0; i--) {Sum[a[i].pos]=1; if(sum[a[i].pos-1]) un (a[i].pos-1, A[i].pos); if(sum[a[i].pos+1]) un (a[i].pos+1, A[i].pos); if(MX < Sum[find (a[i].pos)]) MX =Sum[fa[a[i].pos]]; A[i].ans=MX; }}intSolveintx)    {_node T; T.val=x; intid = lower_bound (a,a+n,t)-A; returnA[id].ans;}voidrun () { for(intI=0; i<n;i++) scanf ("%d", B +i);    Pre (); intX,y,op;  while(m--) {scanf ("%d",&op); if(op==1) {scanf ("%d",&x); if(X>mxval) puts ("0"); Elseprintf"%d\n", Solve (x)); }        Else{scanf ("%d%d",&y,&x); B[y-1]=x;        Pre (); }    }}intMain () {#ifdef LOCAL freopen ("Case.txt","R", stdin); #endif     while(SCANF ("%d%d", &n,&m)! =EOF) run (); return 0;}

Fzu 2059 MM (and check set + sort insert)

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.