08: Challenge 1,08 challenge

Source: Internet
Author: User

08: Challenge 1,08 challenge

Total time limit:
10000 ms
 
Time limit for a single test point:
1000 ms
 
Memory limit:
262144kB
Description

For an N-length series with M operations, each operation is one of the following two types:

(1) modify a number in a series

(2) evaluate the value of a position in a sequence after an operation

Input
The first line has two integers, N and M.
The N integers in the second row represent the series.
Next, the M line starts with one character. If the character is 'M', it indicates a modification operation. The next two integers x and y, it indicates that the value at the position x is changed to y. If the character is 'Q', it indicates a query operation. The next two integers x and y are involved, returns the value of x after the y operation.
Output
Output a single line for each query operation, indicating the answer.
Sample Input
5 31 2 3 4 5Q 1 0M 1 3Q 1 2
Sample output
13
Prompt
1 <= N <= 10 ^ 5, 1 <= M <= 10 ^ 5, the input is valid, and All integers can be stored with 32-bit integers.
  • View
  •  
  • Submit
  •  
  • Statistics
  •  
  • Question

At first glance, many people thought it was necessary to use the Chairman tree or something.

However.

Rope !!.

There is nothing to explain, that is, the template question cannot be left empty ,,,

 

#include<iostream>#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<ext/rope>using namespace std;using namespace __gnu_cxx;const int MAXN=2000050;const int maxn=0x7fffffff;void read(int &n){    char c='+';int x=0;bool flag=0;    while(c<'0'||c>'9'){c=getchar();if(c=='-')flag=1;}    while(c>='0'&&c<='9'){x=x*10+(c-48);c=getchar();}    flag==1?n=-x:n=x;}rope<int> *rp[MAXN];int a[MAXN];int tot=0;int main(){ios::sync_with_stdio(0);    int n,m;    read(n);read(m);    for(int i=1;i<=n;i++)    read(a[i]);    rp[0]=new rope<int>(a+1,a+n+1);    for(int i=1;i<=m;i++)    {    rp[i]=new rope<int>(*rp[i-1]);    char c=getchar();int x,y;    if(c=='Q')    {    int l,r;    int ans=0;    read(l);read(r);read(x);    for(int i=l;i<=r;i++)    ans+=(rp[x]->at(i-1));    printf("%d\n",ans);}else{read(x);read(y);rp[i]->replace(x-1,y);}}    return 0;}

 

  

 

Related Article

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.