CodeForces - 315B

Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

Submit Status

Description

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:

  1. Make vi-th array element equal to xi. In other words,
    perform the assignment avi = xi.
  2. Increase each array element by yi. In other words, perform n assignments ai = ai + yi(1 ≤ i ≤ n).
  3. 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 nm(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 Input

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

这道题目大家须要思考,不要一看到题目就用线段树,要想想有没有更好的方法,这里的题目给出的三种操作
能够知道没有一个是对区间进行操作的,唯一一个都是对整个数组操作。对全部的数的影响一样。
所以代码便能够变为例如以下:
/*
Author: 2486
Memory: 204 KB Time: 93 MS
Language: GNU G++11 4.9.2 Result: Accepted
VJ RunId: 4206974 Real RunId: 12270208
Public: No Yes
*/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1e5+5;
int n,m,p,c,v,a[maxn];
int main() {
scanf("%d%d",&n,&m);
for(int i=1; i<=n; i++) {
scanf("%d",&a[i]);
}
int cnt=0;
while(m--) {
scanf("%d%d",&p,&c);
if(p==1) {
scanf("%d",&v);
a[c]=v-cnt;
} else if(p==2) {
cnt+=c;
} else {
printf("%d\n",a[c]+cnt);
}
}
return 0;
}

Sereja and Array-数组操作或者线段树或树状数组的更多相关文章

  1. HDU 1394 线段树or 树状数组~

    Minimum Inversion Number Description The inversion number of a given number sequence a1, a2, ..., an ...

  2. 2019牛客暑期多校训练营(第七场)F-Energy stones(思维+树状数组)

    >传送门< 题意:有n块能量石,每秒钟会增加Li的能量,但是一旦增长到了Ci它就不会增长了,它初始的能量为Ei. 现在有若干个时刻ti,会选择下标在[Si,Ti]的能量石吸取它们的能量,这 ...

  3. 【BZOJ-3790】神奇项链 Manacher + 树状数组(奇葩) + DP

    3790: 神奇项链 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 304  Solved: 150[Submit][Status][Discuss] ...

  4. php 数组操作类(整合 给意见)

    数组操作函数整理: /* 将一个二维数组按照指定字段的值分组 * * @param array $arr * @param string $keyField * * @return array */ ...

  5. js之数组操作

    js之数组操作 前言 本文主要从应用来讲数组api的一些操作,如一行代码扁平化n维数组.数组去重.求数组最大值.数组求和.排序.对象和数组的转化等.(文章摘自:https://segmentfault ...

  6. 牛客小白月赛12 F 华华开始学信息学 (分块+树状数组)

    链接:https://ac.nowcoder.com/acm/contest/392/F来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 32768K,其他语言65536K ...

  7. BZOJ2120:数颜色(数状数组套主席树)(带修改的莫对)

    墨墨购买了一套N支彩色画笔(其中有些颜色可能相同),摆成一排,你需要回答墨墨的提问.墨墨会像你发布如下指令: 1. Q L R代表询问你从第L支画笔到第R支画笔中共有几种不同颜色的画笔. 2. R P ...

  8. HDU3333 Turing Tree 树状数组+离线处理

    Turing Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  9. PHP数组操作汇总

    php 操作数组 (合并,拆分,追加,查找,删除等) - Just Code - ITeye技术网站 PHP操作数组的一些函数介绍 -- 简明现代魔法 PHP数组元素操作实例 -- 简明现代魔法 儿童 ...

随机推荐

  1. git版本控制的常用指令

    使用git版本控制之前,首先安装好git,安装方式比如可以通过下载客户等方式来安装:这里提供网址:http://windows.github.com/ 1.登入远程仓库,创建仓库2.复制仓库地址3.在 ...

  2. linux下编译libmysqlclient, 安装mysql-server mysql-client

    cmake . -DCMAKE_INSTALL_PREFIX=/home/zhangyawei/server/depends make make install 安装 mysql-server mys ...

  3. 如何在Ionic2项目中使用第三方JavaScript库

    onic的官网放出一记大招Ionic and Typings,来介绍如何在Ionic2项目中使用第三方JavaScript库. 因为在前阵子正好想用一个非常有名的第三方JS库ChartJs来实现一些东 ...

  4. 事务的四大属性ACID即事务的原子性(Atomicity)、一致性(Consistency)、隔离性(Isolation)、持久性(Durability.。

    事务的四大属性ACID即事务的原子性(Atomicity).一致性(Consistency).隔离性(Isolation).持久性(Durability.. 原子性(Atomicity) 原子性是指事 ...

  5. bzoj 4310 跳蚤 二分答案+后缀数组/后缀树

    题目大意 给定\(k\)和长度\(\le10^5\)的串S 把串分成不超过\(k\)个子串,然后对于每个子串\(s\),他会从\(s\)的所有子串中选择字典序最大的那一个,并在选出来的\(k\)个子串 ...

  6. Cookies设置,获取,删除

    之前的博客,整理了下Session的存储方式和原理http://www.cnblogs.com/chinaagan/p/3200456.html. 本篇再次整理下Cookies的使用和原理. 参考博客 ...

  7. [NOIP2013] 提高组 洛谷P1967 货车运输

    题目描述 A 国有 n 座城市,编号从 1 到 n,城市之间有 m 条双向道路.每一条道路对车辆都有重量限制,简称限重.现在有 q 辆货车在运输货物, 司机们想知道每辆车在不超过车辆限重的情况下,最多 ...

  8. 当文字过长时裁剪(显示省略号或只裁剪 用CSS方法,不用程序)

    原文发布时间为:2009-09-16 -- 来源于本人的百度文章 [由搬家工具导入] CSS中ellipsis()应用【转】 CSS手册中text-overflow属性的定义:   语法: text- ...

  9. 《Linux命令行与shell脚本编程大全 第3版》Linux命令行---22

    以下为阅读<Linux命令行与shell脚本编程大全 第3版>的读书笔记,为了方便记录,特地与书的内容保持同步,特意做成一节一次随笔,特记录如下:

  10. msm8917 GPIO Voh(min)

    有些 pin 可以當成多種 function, 此例以 GPIO function P3 voltage 為例 Voh(min) = 1.67 - 0.45 = 1.22 V