bzoj3212 pku3468 A Simple Problem with Integers
一个有初值的数列、区间加、区间查
用线段树直接水过
然而并没有1A,主要是做题太快没看规模结果没注意线段树要用longlong建
卧槽怎么可以这么坑爹,害得我看见wa心慌了,还以为连线段树都要跪
一开始在写下传(MDZZ)然后发现没什么操作就删了
#include <cstdio>
#include <iostream>
#define mid (l+r)/2
long long t[],tr[];
int n,m;
void add(int now,int l,int r,int x,int y)
{
t[now]+=y;
if(l==r)
return;
if(x<=mid)
add(now*,l,mid,x,y);
else
add(now*+,mid+,r,x,y);
}
void plus(int now,int l,int r,int x,int y,int z)
{
if(l==x && r==y)
{
tr[now]+=z;
return;
}
if(x<=mid)
plus(now*,l,mid,x,std::min(y,mid),z);
if(y>mid)
plus(now*+,mid+,r,std::max(x,mid+),y,z);
t[now]=t[now*]+tr[now*]*(mid-l+)+t[now*+]+tr[now*+]*(r-mid);
}
long long que(int now,int l,int r,int x,int y)
{
if(l==x && r==y)
return t[now]+tr[now]*(r-l+);
long long sum=(y-x+)*tr[now];
if(x<=mid)
sum+=que(now*,l,mid,x,std::min(y,mid));
if(y>mid)
sum+=que(now*+,mid+,r,std::max(x,mid+),y);
return sum;
}
int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
int x;
scanf("%d",&x);
add(,,n,i,x);
}
for(int i=;i<=m;i++)
{
char ch=getchar();
for(;ch!='C' && ch!='Q';ch=getchar());
if(ch=='C')
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
plus(,,n,x,y,z);
}
else
{
int x,y;
scanf("%d%d",&x,&y);
printf("%lld\n",que(,,n,x,y));
}
}
return ;
}
bzoj3212 pku3468 A Simple Problem with Integers的更多相关文章
- BZOJ-3212 Pku3468 A Simple Problem with Integers 裸线段树区间维护查询
3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 128 MB Submit: 1278 Sol ...
- bzoj3212 Pku3468 A Simple Problem with Integers 线段树
3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2046 So ...
- BZOJ3212: Pku3468 A Simple Problem with Integers(线段树)
3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2530 So ...
- BZOJ3212 Pku3468 A Simple Problem with Integers 题解
题目大意: 一个数列,有两个操作:1.修改操作,将一段区间内的数加上c:2.查询操作,查询一段区间内的数的和. 思路: 线段树裸题,区间修改.区间查询,维护和以及加上的数,由于无序,不需要向下推标记, ...
- 【分块】【线段树】bzoj3212 Pku3468 A Simple Problem with Integers
线段树入门题…… 因为poj原来的代码莫名RE,所以丧病地写了区间修改的分块…… 其实就是块上打标记,没有上传下传之类. #include<cstdio> #include<cmat ...
- 3212: Pku3468 A Simple Problem with Integers
3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1053 So ...
- bzoj 3212 Pku3468 A Simple Problem with Integers
3212: Pku3468 A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 128 MB Description You ...
- bzoj 3212 Pku3468 A Simple Problem with Integers 线段树基本操作
Pku3468 A Simple Problem with Integers Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 2173 Solved: ...
- [BZOJ3212][POJ3468]A Simple Problem with Integers
题目大意: 维护一个长度为$n(n\leq100000)$的数列,支持区间加.区间求和两种操作,操作共$m(m\leq100000)$次. 思路: Splay区间操作. #include<cst ...
随机推荐
- zabbix注入过程分析
Zabbix jsrpc.php sql 注入过程分析 漏洞公开详情(https://support.zabbix.com/browse/ZBX-11023)中提示在insertDB() 中的inse ...
- [Maven] 变态问题收集
1.新换的系统,eclipse运行起来之后,一直报错Missing artifact 折腾了好久,没法了,把服务器上的仓库直接压缩,传到本地计算机上,覆盖本地仓库,完美解决这个问题! 2.tomcat ...
- Filter体现职责链模式
1. 前言 Filter—Filter 技术是servlet2.3 新增加的功能.完成的流程:对用户请求进行预处理,接着将请求交给Servlet进行处理并生成响应,最后Filter再对服务器响应进行后 ...
- [译]Testing Node.js With Mocha and Chai
原文: http://mherman.org/blog/2015/09/10/testing-node-js-with-mocha-and-chai/#.ViO8oBArIlJ 为什么要测试? 在此之 ...
- R语言学习笔记-机器学习1-3章
在折腾完爬虫还有一些感兴趣的内容后,我最近在看用R语言进行简单机器学习的知识,主要参考了<机器学习-实用案例解析>这本书. 这本书是目前市面少有的,纯粹以R语言为基础讲解的机器学习知识,书 ...
- thinkphp3.2.3之自动完成的实现
有时候,我们希望系统能够帮我们自动完成一些功能,比如自动为密码加密,忽略空等,这个时候我们就需要利用到自动完成(填写)的功能. ThinkPHP 模型层提供的数据处理方法,主要用于数据的自动处理和过滤 ...
- vue 列表渲染
在Vue官网中写道,vue无法直接用索引设置元素, 如 vm.items[0] = {}: 提出的解决方法是用 : example1.items.$set(0, { childMsg: 'Change ...
- ICMP的应用--Traceroute
Traceroute是用来侦测主机到目的主机之间所经路由情况的重要工具,也是最便利的工具.前面说到,尽管ping工具也可以进行侦测,但是,因为ip头的限制,ping不能完全的记录下所经过的路由器.所以 ...
- mysql 最大连接数 & 连接池
MySQL最大连接数 关于最大连接数:http://mg123.lofter.com/post/1a5f3e_996f838 可以通过修改配置文件(默认/etc/my.cnf)中的"mysq ...
- [转]spring beans.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...