华东交通大学2015年ACM“双基”程序设计竞赛1005
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
同时给定m个操作,每个操作有三个整形数据 x,y,z。
每个操作的意义就是给数组中下标为x与下标为y之间(包括x,y)的元素的值加上z。
Input
每一组数据第一行有两个整数 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
#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的更多相关文章
- 华东交通大学2015年ACM“双基”程序设计竞赛1002
Problem B Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other) Total Sub ...
- 华东交通大学2015年ACM“双基”程序设计竞赛1007
Problem G Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other) Total Sub ...
- 华东交通大学2015年ACM“双基”程序设计竞赛1003
Problem C Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other) Total Sub ...
- 华东交通大学2015年ACM“双基”程序设计竞赛1001
Problem A Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other) Total Sub ...
- 华东交通大学2015年ACM“双基”程序设计竞赛1004
Problem D Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other) Total Sub ...
- 华东交通大学2016年ACM“双基”程序设计竞赛 1005
Problem Description 最近侯ry感觉自己在数学方面的造诣不忍直视:他发现他的学习速率呈一个指数函数递增,疯狂的陷入学习的泥潭,无法自拔:他的队友发现了他的学习速率y=e^(b*lna ...
- 华东交通大学2017年ACM“双基”程序设计竞赛 1005
Problem Description 假设你有一个矩阵,有这样的运算A^(n+1) = A^(n)*A (*代表矩阵乘法)现在已知一个n*n矩阵A,S = A+A^2+A^3+...+A^k,输出S ...
- 华东交通大学2018年ACM“双基”程序设计竞赛 C. 公式题 (2) (矩阵快速幂)
题目链接:公式题 (2) 比赛链接:华东交通大学2018年ACM"双基"程序设计竞赛 题目描述 令f(n)=2f(n-1)+3f(n-2)+n,f(1)=1,f(2)=2 令g(n ...
- 华东交通大学2018年ACM“双基”程序设计竞赛部分题解
链接:https://ac.nowcoder.com/acm/contest/221/C来源:牛客网 C-公式题(2) 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其 ...
随机推荐
- c++primer-p101.ex3.24
要求使用迭代器 读入一组整数并把它们存入一个vector对象 1. 将相邻每对整数和输出 2. 先输出第一个和最后一个数的和,然后是第二个和倒数第二个...等等 自己写的: #include<i ...
- hibernate的子查询
hibernate原话 HQL supports subqueries in the where clause. We can't think of many good uses for subque ...
- Bind和Eval的不同用法 (转)
今天在用DataList的模板列的时候习惯性地像在03中那样去给模板列的绑定字段加个处理函数: < asp:Label ID = " Label1 " runat = &qu ...
- Oracle merge into 语句进行insert或者update操作,如果存在就update,如果不存在就insert
merge into的形式: MERGE INTO [target-table] A USING [source-table sql] B ON([conditional expression] ...
- cd命令无效
原因是没有切换盘符步骤一:C:\Documents and Settings\Administrator>d:步骤二:cd D:\Program Files\Python35-32\Script ...
- 在Ubuntu里启用root账号
我的系统环境, 操作系统:Win7 虚拟机软件:VMware workstation 12 在虚拟机里安装了Ubuntu 18,安装时的账号frank,在安装其它软件的时候,报权限不足,因此,准备启用 ...
- noi.ac day6t1 queen
传送门 分析 我就是个BT...... 直接排序后开数组记录每条线上的信息,注意由于每个点只会影响前面第一个点和后面第一个点,所以记录每条线的前一个点就行了. 代码 #include<iostr ...
- 利用HTML5 与CSS3 做的放大镜
利用HTML5 与CSS3 做的放大镜 html结构 <div class="wrap"> <div class="move"> < ...
- Python程序设计3——字典
1 字典 字典是Python唯一内建的映射类型.字典是键值对的集合. 1.1 字典的使用 某些情况下字典更加好用,比如一个电话列表.注意:电话号码只能用字符串数字表示,否则会出问题.因为电话号码一旦以 ...
- 带有通配符的字符串匹配算法-C/C++
日前某君给我出了这样一道题目:两个字符串,一个是普通字符串,另一个含有*和?通配符,*代表零个到多个任意字符,?代表一个任意字符,通配符可能多次出现.写一个算法,比较两个字符串是否相等. 我花了四个小 ...