程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> CF 315B(Sereja and Array-峰頂距離統計)

CF 315B(Sereja and Array-峰頂距離統計)

編輯:C++入門知識

B. Sereja and Array
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Sereja has got an array, consisting of n integers, a1, a2, ..., an. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms:


Make vi-th array element equal to xi. In other words, perform the assignment avi = xi.
Increase each array element by yi. In other words, perform n assignments ai = ai + yi (1 ≤ i ≤ n).
Take a piece of paper and write out the qi-th array element. That is, the element aqi.

Help Sereja, complete all his operations.

Input
The first line contains integers n, m (1 ≤ n, m ≤ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the original array.

Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1 ≤ ti ≤ 3) that represents the operation type. If ti = 1, then it is followed by two integers vi and xi, (1 ≤ vi ≤ n, 1 ≤ xi ≤ 109). If ti = 2, then it is followed by integer yi (1 ≤ yi ≤ 104). And if ti = 3, then it is followed by integer qi (1 ≤ qi ≤ n).

Output
For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input.

Sample test(s)
input
10 11
1 2 3 4 5 6 7 8 9 10
3 2
3 9
2 10
3 1
3 10
1 1 10
2 10
2 10
3 1
3 10
3 9
output
2
9
11
20
30
40
39


水題,統計與峰頂的距離,模擬


[cpp]
#include<cstdio>  
#include<cstring>  
#include<cstdlib>  
#include<algorithm>  
#include<functional>  
#include<iostream>  
#include<cmath>  
#include<cctype>  
#include<ctime>  
using namespace std; 
#define For(i,n) for(int i=1;i<=n;i++)  
#define Fork(i,k,n) for(int i=k;i<=n;i++)  
#define Rep(i,n) for(int i=0;i<n;i++)  
#define ForD(i,n) for(int i=n;i;i--)  
#define RepD(i,n) for(int i=n;i>=0;i--)  
#define Forp(x) for(int p=pre[x];p;p=next[p])  
#define MAXM (1000000+10)  
int n,m; 
/*
struct tree_arr
{
    int a[MAXM*4];
    tree_arr(){memset(a,0,sizeof(a));}
    void inc(int x,int c)
    {
        for(int i=x;i<=n;i+=i&(-i)) a[x]+=c;
    }
    int qur(int x)
    {
        int ans=0;
        for(int i=x;i;i-=i&(-i)) ans+=a[x];
        return ans;
    }
}T1,T2;
void Ins()
{
 
}*/ 
int a[MAXM],tmp=0; 
 
int main() 

//  freopen(".in","r",stdin);  
//  freopen(".out","w",stdout);  
    cin>>n>>m; 
    For(i,n) {scanf("%d",&a[i]);} 
    For(i,m) 
    { 
        int type; 
        scanf("%d",&type); 
        if (type==1) 
        { 
            int v,x; 
            scanf("%d%d",&v,&x); 
            a[v]+=x-(a[v]+tmp); 
        } 
        else if (type==2) 
        { 
            int w; 
            cin>>w; 
            tmp+=w; 
        } 
        else 
        { 
            int v; 
            scanf("%d",&v); 
            cout<<a[v]+tmp<<endl; 
        } 
 
    } 
 
    return 0; 

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define MAXM (1000000+10)
int n,m;
/*
struct tree_arr
{
    int a[MAXM*4];
    tree_arr(){memset(a,0,sizeof(a));}
    void inc(int x,int c)
    {
        for(int i=x;i<=n;i+=i&(-i)) a[x]+=c;
    }
    int qur(int x)
    {
        int ans=0;
        for(int i=x;i;i-=i&(-i)) ans+=a[x];
        return ans;
    }
}T1,T2;
void Ins()
{

}*/
int a[MAXM],tmp=0;

int main()
{
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
    cin>>n>>m;
    For(i,n) {scanf("%d",&a[i]);}
    For(i,m)
    {
        int type;
        scanf("%d",&type);
        if (type==1)
        {
            int v,x;
            scanf("%d%d",&v,&x);
            a[v]+=x-(a[v]+tmp);
        }
        else if (type==2)
        {
            int w;
            cin>>w;
            tmp+=w;
        }
        else
        {
            int v;
            scanf("%d",&v);
            cout<<a[v]+tmp<<endl;
        }

    }

 return 0;
}


 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved