Problem E

Time Limit : 3000/2000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other)
Total Submission(s) : 357   Accepted Submission(s) : 16

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

给定一个长度为n的数组 a[1],a[2],a[3],a[4].....a[n]。
同时给定m个操作,每个操作有三个整形数据 x,y,z。
每个操作的意义就是给数组中下标为x与下标为y之间(包括x,y)的元素的值加上z。

Input

输入有多组数据(3组左右)
每一组数据第一行有两个整数 n,m 。(0<m<100000,0<n<1000000);
第二行有n个整数,分别代表 a[1],a[2],a[3],a[4]......a[n]的初始值.(0<=a[i]<10)
接下来就m行,每一行有3个整数,x,y,z。 (0<=x,y<=n, 0<z<10)
(请大家特别注意本题的数据范围)

Output

在一行内输出这个序列的所有元素的值,并且每个值之间应该以空格隔开。
(题目保证所有的输出数据都在int32范围内)

Sample Input

10 5
0 0 0 0 0 0 0 0 0 0
1 5 1
2 6 1
3 7 1
4 9 1
5 10 1
1 1
1
1 1 2

Sample Output

1 2 3 4 5 4 3 2 2 1
3

Author

moonlike
 
没错!!!看似简单其实很坑,坑在a和b不一定是a<b的关系。知道这个,用线段树就好
#include<stdio.h>
//#include<bits/stdc++.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<sstream>
#include<set>
#include<queue>
#include<map>
#include<vector>
#include<algorithm>
#include<limits.h>
#define inf 0x3fffffff
#define INF 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define ULL unsigned long long
using namespace std;
const int maxn = 1000000;
int add[maxn<<2];
int sum[maxn<<2];
int aa[1000000];
void PushUp(int rt){
sum[rt] = sum[rt<<1] + sum[rt<<1|1];
}
void PushDown(int rt,int m){
if (add[rt]){
add[rt<<1] += add[rt];
add[rt<<1|1] += add[rt];
sum[rt<<1] += add[rt] * (m - (m >> 1));
sum[rt<<1|1] += add[rt] * (m >> 1);
add[rt] = 0;
}
}
void build(int l,int r,int rt){
add[rt] = 0;
if (l == r){
sum[rt]=0;
// scanf("%lld",&sum[rt]);
return ;
}
int m = (l + r) >> 1;
build(lson);
build(rson);
PushUp(rt);
}
void update(int L,int R,int c,int l,int r,int rt){
if (L <= l && r <= R){
add[rt] += c;
sum[rt] += (LL)c * (r - l + 1);
return ;
}
PushDown(rt , r - l + 1);
int m = (l + r) >> 1;
if (L <= m) update(L , R , c , lson);
if (m < R) update(L , R , c , rson);
PushUp(rt);
}
int query(int L,int R,int l,int r,int rt){
if (L <= l && r <= R){
return sum[rt];
}
PushDown(rt , r - l + 1);
int m = (l + r) >> 1;
int ret = 0;
if (L <= m) ret += query(L , R , lson);
if (m < R) ret += query(L , R , rson);
return ret;
}
int main(){
int N , M;
int i,j;
int a,b,c;
while(~scanf("%d%d",&N,&M)){
build(1 , N , 1);
for(i=1; i<=N; i++){
scanf("%d",&aa[i]);
}
for(i=1; i<=M; i++){
scanf("%d%d%d",&a,&b,&c);
if(a==0){
a+=1;
}
if(b==0){
b+=1;
}
update(min(a,b),max(b,a),c,1,N,1);
}
if(N==1){
printf("%d\n",aa[1]+query(1,1,1,N,1));
}
else{
for(i=1; i<=N; i++){
if(i!=N){
printf("%d ",aa[i]+query(i,i,1,N,1));
}
else{
printf("%d\n",aa[i]+query(i,i,1,N,1));
}
}
}
}
return 0;
}

  

华东交通大学2015年ACM“双基”程序设计竞赛1005的更多相关文章

  1. 华东交通大学2015年ACM“双基”程序设计竞赛1002

    Problem B Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Sub ...

  2. 华东交通大学2015年ACM“双基”程序设计竞赛1007

    Problem G Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Sub ...

  3. 华东交通大学2015年ACM“双基”程序设计竞赛1003

    Problem C Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Sub ...

  4. 华东交通大学2015年ACM“双基”程序设计竞赛1001

    Problem A Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Sub ...

  5. 华东交通大学2015年ACM“双基”程序设计竞赛1004

    Problem D Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Sub ...

  6. 华东交通大学2016年ACM“双基”程序设计竞赛 1005

    Problem Description 最近侯ry感觉自己在数学方面的造诣不忍直视:他发现他的学习速率呈一个指数函数递增,疯狂的陷入学习的泥潭,无法自拔:他的队友发现了他的学习速率y=e^(b*lna ...

  7. 华东交通大学2017年ACM“双基”程序设计竞赛 1005

    Problem Description 假设你有一个矩阵,有这样的运算A^(n+1) = A^(n)*A (*代表矩阵乘法)现在已知一个n*n矩阵A,S = A+A^2+A^3+...+A^k,输出S ...

  8. 华东交通大学2018年ACM“双基”程序设计竞赛 C. 公式题 (2) (矩阵快速幂)

    题目链接:公式题 (2) 比赛链接:华东交通大学2018年ACM"双基"程序设计竞赛 题目描述 令f(n)=2f(n-1)+3f(n-2)+n,f(1)=1,f(2)=2 令g(n ...

  9. 华东交通大学2018年ACM“双基”程序设计竞赛部分题解

    链接:https://ac.nowcoder.com/acm/contest/221/C来源:牛客网 C-公式题(2) 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其 ...

随机推荐

  1. 第一天:tomcat相关知识和浏览器的访问机制

    1.tomcat的目录结构 1)bin目录:启动和关闭tomcat以及其他的脚本命令  2)conf目录:存放各种配置文件 a.server.xml配置文件的配置: *<host/>标签: ...

  2. spring整合web项目演示

  3. Redis Cluster 伪集群的搭建

    简介 为何要搭建Redis集群?Redis是在内存中保存数据的,而我们的电脑一般内存都不大,这也就意味着Redis不适合存储大数据,适合存储大数据的是Hadoop生态系统的Hbase或者是MogoDB ...

  4. C语言基础问题总结

    Double 类型用 %f 接受会产生错误,应该用%lf C语言中SIN,COS的参数为弧度,角度应先转换为弧度才能计算,否则出错 三角形的判断条件,任意两边长度和大于第三边 闰年判断条件整百年为40 ...

  5. 报错:空指针java.lang.NullPointerException 原因 Action层 private UserService userservice 上未加@Autowire注解

    java.lang.NullPointerException at com.itheima.test.Test2.fun1(Test2.java:18) at sun.reflect.NativeMe ...

  6. Data Mining: SSE,MSE,RMSE,R-square指标讲解

    转载自:http://blog.csdn.net/l18930738887/article/details/50629409 SSE(和方差.误差平方和):The sum of squares due ...

  7. Apache Thrift with Java Quickstart(thrift入门及Java实例)

    thrift是一个软件框架,用来进行可扩展且跨语言的服务的开发.它结合了功能强大的软件堆栈和代码生成引擎,以构建在 C++, Java, Python, PHP, Ruby, Erlang, Perl ...

  8. Entity Framework Tutorial Basics(27):Update Entity Graph

    Update Entity Graph using DbContext: Updating an entity graph in disconnected scenario is a complex ...

  9. CodeForces 478D Red-Green Towers (DP)

    题意:给定 n 块红砖,m 块绿砖,问有多少种方式可以建造成最高的塔,每一层颜色必须一样. 析:首先要确定最高是多少层h,大约应该是用 h * (h+1) <= (m+n) * 2,然后dp[i ...

  10. 【Arcgis for android】程序运行出错原因分析及解决(超详细)

    查看项目下是否有libs文件夹,正常情况下其中应该有 如果没有,在项目上右键 ->arcgis tools->convert to arcgis android project 排除了上述 ...