Newcoder 111 F.托米搭積木(水~)
阿新 • • 發佈:2018-11-09
Description
這天,可愛的小托米得到了n堆積木,且第i堆積木初始時有ai塊積木.
小托米很快就喜歡上了玩積木.
他會作出三種操作:
1.把第 堆的積木數量更改為 .
2.在每堆積木的上面都加上 個積木.
3.數第 堆積木的積木個數.
由於這天可愛的小托米實在是太困了,所以他請你幫他完成這些操作.
Input
第一行兩個整數
.
第二行
個整數,第
個整數代表
的值.
接下來
行,每行代表一個操作:
第一個整數
代表操作的型別
若
,則接下來兩個整數
,代表操作
.
若
,則接下來一個整數
,代表操作
.
若
,則接下來一個整數
,代表操作
.
Output
對於每個操作 ,輸出其對應的答案.
Sample 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
Sample Output
2
9
11
20
30
40
39
Solution
維護每堆加的值 ,假設當前要把第 堆從 變成 ,相當於把 變成 ,查詢 的答案即為
Code
#include<cstdio>
using namespace std;
typedef long long ll;
const int maxn=100005;
int n,m;
ll a[maxn];
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
ll res=0;
while(m--)
{
int op,x,y;
scanf("%d%d",&op,&x);
if(op==1)
{
scanf("%d",&y);
a[x]=y-res;
}
else if(op==2)res+=x;
else printf("%lld\n",a[x]+res);
}
return 0;
}