1901:zju2112 Dynamic Rankings

Source: Internet
Author: User

1901:zju2112 Dynamic Rankings time limit:10 Sec Memory limit:128 MB
submit:7339 solved:3055
[Submit] [Status] [Discuss] Description

Given a sequence of n A[1],a[2],a[3]......a[n], the program must answer this question: For a given i,j,k, the small number of K in A[i],a[i+1],a[i+2]......a[j] is (1≤k≤j-i+1), and, You can change the value of some a[i], and after the change, the program can continue to answer the above question for the changed a. You need to make a program that reads the sequence a from the input file and then reads in a series of instructions, including the Ask and modify instructions. For each inquiry instruction, you must output the correct answer. The first line has two positive integers n (1≤n≤10000), M (1≤m≤10000). Indicates the length of the sequence and the number of instructions, respectively. The second line has n number, which means a[1],a[2]......a[n], these numbers are smaller than 10^9. The next M-line describes each instruction, and the format of each line is one of the following two formats. Q I j K or C i t Q i j K (I,j,k is a number, 1≤i≤j≤n, 1≤k≤j-i+1) indicates an inquiry instruction asking for a small number of k in the A[i],a[i+1]......a[j]. C i T (1≤i≤n,0≤t≤10^9) means to change a[i] into T.

Input

For each query, you need to output his answer, with each output occupying a separate line.

Output Sample Input5 3
3 2 1) 4 7
Q 1 4 3
C 2 6
Q 2 5 3
Sample Output3
6
HINT

20% of the data, m,n≤100; 40% of the data, m,n≤1000; 100% of the data, m,n≤10000.

Source

#include <cstdio>#include<algorithm>using namespacestd;Const intn=1e5+5;Const intm=2200001;intn,m,cnt,top,a,b,x[n],a[n],b[n],v[n],num[n<<1],k[n],l[ -],r[ -];intRoot[n],ls[m],rs[m],sum[m];intLowbit (intx) {    returnx&-x;}voidInsertint&k,intLastintLintRintXintadd) {k=++CNT; intMid=l+r>>1; LS[K]=Ls[last]; RS[K]=Rs[last]; SUM[K]=sum[last]+add; if(L==R)return; if(x<=mid) Insert (LS[K],LS[LAST],L,MID,X,ADD); ElseInsert (rs[k],rs[last],mid+1, R,x,add);} intQueryintLintRintk) {    if(L==R)returnl; intMid=l+r>>1; intSuml=0, sumr=0;  for(intI=1; i<=a;i++) suml+=Sum[ls[l[i]];  for(intI=1; i<=b;i++) sumr+=Sum[ls[r[i]]; if(sumr-suml>=k) {         for(intI=1; i<=a;i++) l[i]=Ls[l[i]];  for(intI=1; i<=b;i++) r[i]=Ls[r[i]]; returnquery (L,MID,K); }    Else{         for(intI=1; i<=a;i++) l[i]=Rs[l[i]];  for(intI=1; i<=b;i++) r[i]=Rs[r[i]]; returnQuery (mid+1, r,k-(sumr-suml)); }}     intMain () {scanf ("%d%d", &n,&m); top=N;  for(intI=1; i<=n;i++) scanf ("%d", &v[i]), num[i]=V[i]; Charopt[6];  for(intI=1; i<=m;i++) {scanf ("%s%d%d",opt,&a[i],&B[i]); if(opt[0]=='Q') scanf ("%d", &x[i]), k[i]=1; Elsenum[++top]=B[i]; } sort (num+1, num+top+1); intTot=unique (num+1, num+top+1)-num-1;  for(intI=1; i<=n;i++){        intT=lower_bound (num+1, num+tot+1, V[i])-num;  for(intj=i;j<=n;j+=Lowbit (j)) Insert (Root[j],root[j],1, Tot,t,1); }     for(intI=1; i<=m;i++){        if(K[i]) {a=0, b=0; a[i]--;  for(intj=a[i];j>=1; J-=lowbit (j)) l[++a]=Root[j];  for(intj=b[i];j>=1; J-=lowbit (j)) r[++b]=Root[j]; printf ("%d\n", Num[query (1, Tot,x[i])); }        Else{            intT=lower_bound (num+1, num+tot+1, V[a[i]])-num;  for(intj=a[i];j<=n;j+=Lowbit (j)) Insert (Root[j],root[j],1, tot,t,-1); V[a[i]]=B[i]; T=lower_bound (num+1, num+tot+1, V[a[i]])-num;  for(intj=a[i];j<=n;j+=Lowbit (j)) Insert (Root[j],root[j],1, Tot,t,1); }    }}

1901:zju2112 Dynamic Rankings

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.