AOJ DSL_2_E Range Add Query (RAQ)
Range Add Query
数列 A = {a1,a2,...,an} に対し、次の2つの操作を行うプログラムを作成せよ。
- add(s,t,x): as,as+1,...,at にxを加算する。
- get(i): aiの値を出力する。
ただし、ai (i=1,2,...,n)は、0 で初期化されているものとする。
入力
n q
query1
query2
:
queryq
1行目にAの要素数n, クエリの数qが与えられる。続くq行に i 番目のクエリ queryi が与えられる。queryi は以下のいずれかの形式で与えられる。
0 s t x
または
1 i
各クエリの最初の数字は、クエリの種類を示し、'0'がadd(s,t,x)、'1'がget(i)を表す。
出力
各getクエリについて、値を1行に出力せよ。
制約
- 1≤n≤100000
- 1≤q≤100000
- 1≤s≤t≤n
- 1≤i≤n
- 0≤x≤1000
入力例 1
3 5
0 1 2 1
0 2 3 2
0 3 3 3
1 2
1 3
出力例 1
3
5
入力例 2
4 3
1 2
0 1 4 1
1 2
出力例 2
0
1
区间加 单点查
树状数组+差分 或 线段树
缩常数,继续打榜
#include <cstdio>
#include <cstdlib> #define siz 10000000 char buf[siz], *bit = buf; inline int nextInt(void) {
register int ret = ;
register int neg = false; for (; *bit < ''; ++bit)
if (*bit == '-')neg ^= true; for (; *bit >= ''; ++bit)
ret = ret * + *bit - ''; return neg ? -ret : ret;
} int n, m; int pre[]; inline int ask(int p) {
int ret = ;
for (; p; p -= p&-p)
ret += pre[p];
return ret;
} inline void add(int p, int k) {
for (; p <= n; p += p&-p)
pre[p] += k;
} signed main(void) {
fread(buf, , siz, stdin); n = nextInt();
m = nextInt(); for (int i = ; i <= m; ++i) {
int c = nextInt();
if (c) // get(i)
printf("%d\n", ask(nextInt()));
else // add(s, t, x)
{
int x = nextInt();
int y = nextInt();
int k = nextInt();
add(x, k); add(y + , -k);
}
} //system("pause");
}
@Author: YouSiki
AOJ DSL_2_E Range Add Query (RAQ)的更多相关文章
- AOJ DSL_2_D Range Update Query (RUQ)
Range Update Query 数列 A = {a0,a1 ,...,an−1} に対し.次の2つの操作を行うプログラムを作成せよ. update(s,t,x): as,as+1,...,at ...
- AOJ DSL_2_A Range Minimum Query (RMQ)
Range Minimum Query (RMQ) Write a program which manipulates a sequence A = {a0,a1,...,an−1} with the ...
- Leetcode: Range Sum Query 2D - Mutable && Summary: Binary Indexed Tree
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...
- leetcode笔记:Range Sum Query - Mutable
一. 题目描写叙述 Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), ...
- [LeetCode] Range Sum Query 2D - Mutable 二维区域和检索 - 可变
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...
- [LeetCode] Range Sum Query - Mutable 区域和检索 - 可变
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...
- [LeetCode] Range Sum Query 2D - Immutable 二维区域和检索 - 不可变
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper lef ...
- [LeetCode] Range Sum Query - Immutable 区域和检索 - 不可变
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...
- range for query
static void range_test(Args _args) { Query Query; QueryRun QueryRun ...
随机推荐
- IOS基础之UILineBreakModeWordWrap
UILineBreakModeWordWrap详细解释如下: typedef enum { UILineBreakModeWordWrap = 0, UILineBreakModeC ...
- 报文格式:xml 、定长报文、变长报文
目前接触到的报文格式有三种:xml .定长报文.变长报文 . 此处只做简单介绍,日后应该会深入学习到三者之间如何解析,再继续更新.——2016.9.23 XML XML 被设计用来传输和存储数据. H ...
- 将ASP.NET Core应用程序部署至生产环境中(CentOS7)
这段时间在使用Rabbit RPC重构公司的一套系统(微信相关),而最近相关检验(逻辑测试.压力测试)已经完成,接近部署至线上生产环境从而捣鼓了ASP.NET Core应用程序在CentOS上的部署方 ...
- ORACLE VARCHAR2最大长度问题
VARCHAR2数据类型的最大长度问题,是一个让人迷惑的问题,因为VARCHAR2既分PL/SQL Data Types中的变量类型,也分Oracle Database中的字段类型.简单的说,要看你在 ...
- Java借助axis2发布WebService
Webservice: 1.Xml: 2.WSDL: Web service描述语言(WSDL)就是这样一个基于XML(标准通用标记语言下的一个子集)的语言,用于描述Web service及其函数.参 ...
- linux中offsetof与container_of宏定义
linux内核中offsetof与container_of的宏定义 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->M ...
- 今天主要推荐一下django学习的网址!
前言:每个月忙碌的头20天后,在上班时间投入到django理论学习的过程中,花了差不多3天时间简单的研究了一下django,着实废了我不少脑细胞. 采用虫师前辈的一张图和话: 如果你把这过程梳理清晰了 ...
- 《InsideUE4》UObject(一)开篇
UE生UObject,UObject生万物 引言 在上个GamePlay专题,谈到UE创建游戏世界的时候(GamePlay架构(一)Actor和Component),简单的介绍了一下UObject的功 ...
- 第2章 Linux系统安装(3)_SSH连接Linux工具:SecureCRT和WinSCP
4. SSH连接Linux工具 4.1 Linux网卡配置 (1)临时配置: ifconfig eth0 192.168.32.100 //给eth0网卡指定IP,写在ROM里的,关机会丢失. (2) ...
- SQL/LINQ/Lamda 写法[转发]
SQL LINQ Lambda SELECT * FROM HumanResources.Employee from e in Employees select e Employees .Sele ...