Greg has an array a = a1, a2, …, an and m operations. Each operation looks as: li, ri, di, (1 ≤ li ≤ ri ≤ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, …, ri by value di.

Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, (1 ≤ xi ≤ yi ≤ m). That means that one should apply operations with numbers xi, xi + 1, …, yi to the array.

Now Greg is wondering, what the array a will be after all the queries are executed. Help Greg.

Input
The first line contains integers n, m, k (1 ≤ n, m, k ≤ 105). The second line contains n integers: a1, a2, …, an (0 ≤ ai ≤ 105) — the initial array.

Next m lines contain operations, the operation number i is written as three integers: li, ri, di, (1 ≤ li ≤ ri ≤ n), (0 ≤ di ≤ 105).

Next k lines contain the queries, the query number i is written as two integers: xi, yi, (1 ≤ xi ≤ yi ≤ m).

The numbers in the lines are separated by single spaces.

Output
On a single line print n integers a1, a2, …, an — the array after executing all the queries. Separate the printed numbers by spaces.

Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier.

Examples
Input
3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3
Output
9 18 17
Input
1 1 1
1
1 1 1
1 1
Output
2
Input
4 3 6
1 2 3 4
1 2 1
2 3 2
3 4 4
1 2
1 3
2 3
1 2
1 3
2 3
Output
5 18 31 20
题意:给定一组序列。总共有m个操作,每个操作就是一次区间更新。后面有k次读入,每次读入l~r,代表着l ~r中的操作都执行一次,输出最后的序列是什么。
肯定不能直接暴力,每次都更新。我们可以离线一下,把所有操作会执行几次给计算出来(利用差分数组),然后再更新的时候就直接把最后一次的给求出来,这样就省时间了。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;const int maxx=1e5+100;
struct node{int l;int r;ll sum;ll lazy;
}p[maxx<<2];
struct Node{int l;int r;ll v;
}t[maxx];
int a[maxx];
ll b[maxx];
int n,m,k;inline void pushdown(int cur)
{if(p[cur].lazy){p[cur<<1].lazy+=p[cur].lazy;p[cur<<1|1].lazy+=p[cur].lazy;p[cur<<1].sum+=p[cur].lazy;p[cur<<1|1].sum+=p[cur].lazy;p[cur].lazy=0;}
}
inline void build(int l,int r,int cur)
{p[cur].l=l;p[cur].r=r;p[cur].sum=0;p[cur].lazy=0;if(l==r){p[cur].sum=b[l];return ;}int mid=l+r>>1;build(l,mid,cur<<1);build(mid+1,r,cur<<1|1);
}
inline void update(int l,int r,int cur,ll v)
{int L=p[cur].l;int R=p[cur].r;if(l<=L&&R<=r){p[cur].sum+=v;p[cur].lazy+=v;return ;}pushdown(cur);int mid=L+R>>1;if(r<=mid) update(l,r,cur<<1,v);else if(l>mid) update(l,r,cur<<1|1,v);else{update(l,mid,cur<<1,v);update(mid+1,r,cur<<1|1,v);}
}
inline void solve(int cur)
{int L=p[cur].l;int R=p[cur].r;if(L==R) {cout<<p[cur].sum<<" ";return ;}pushdown(cur);solve(cur<<1);solve(cur<<1|1);
}
int main()
{int x,y;while(~scanf("%d%d%d",&n,&m,&k)){memset(a,0,sizeof(a));for(int i=1;i<=n;i++) cin>>b[i];build(1,n,1);for(int i=1;i<=m;i++) cin>>t[i].l>>t[i].r>>t[i].v;for(int i=1;i<=k;i++){cin>>x>>y;a[x]++;a[y+1]--;}//差分数组的常规操作for(int i=1;i<=m;i++) a[i]+=a[i-1];//还原之前的数组for(int i=1;i<=m;i++) update(t[i].l,t[i].r,1,(ll)a[i]*t[i].v);solve(1);puts("");}
}

努力加油a啊,(o)/~

Greg and Array CodeForces - 296C(差分数组+线段树)相关推荐

  1. Master of GCD(差分数组||线段树)

    题意:长度为n的数组,一开始都是1.对于区间操作l,r,x,在l~r上乘以x.x2||x3.问操作完毕之后,n个数的最大公因子是多少. 对于每个x,都等于2或者是3.那么看最大的公因子,就看各个位置上 ...

  2. D-query SPOJ - DQUERY(求区间不同数的个数)(树状数组||线段树+离散)(主席树+在线)

    English Vietnamese Given a sequence of n numbers a1, a2, -, an and a number of d-queries. A d-query ...

  3. HDU 6194 String String String (后缀数组+线段树, 2017 ACM/ICPC Asia Regional Shenyang Online)

    Problem 求字符串 S 中严格出现 k 次的子串个数 k≥1k\ge 1 |S|≤105|S|\le 10^5 ∑|S|≤2×106\sum |S| \le 2\times 10^6 Idea ...

  4. 差分+树状数组 线段树【P2357】 守墓人

    题目描述-->p2357 守墓人 敲了一遍线段树,水过. 树状数组分析 主要思路: 差分 简单介绍一下差分(详细概念太麻烦,看下面. 给定一个数组 7 8 6 5 1 8 18 20 35 // ...

  5. Codeforces 833B 题解(DP+线段树)

    题面 传送门:http://codeforces.com/problemset/problem/833/B B. The Bakery time limit per test2.5 seconds m ...

  6. Codeforces 997E Good Subsegments (线段树)

    题目链接 https://codeforces.com/contest/997/problem/E 题解 经典题,鸽了 159 天终于看明白题解了.. 考虑一个区间是连续的等价于这个区间内的 \((\ ...

  7. HDU 1556 前缀和 树状数组 线段树

    解法一: a[i]表示以 i作为起点,对 i-n的气球全部上色的次数  对(start,end)区间上色 ++a[start] --a[end+1]抵消掉 end+1-n的部分 问题转换为求 a的前缀 ...

  8. CF-547E(Mike and Friends)后缀数组+线段树 AC自动机+DFS序+树状数组

    题目链接 题意 NNN个串,每次询问区间[L,R][L,R][L,R]中有多少子串SiS_iSi​ 思路 把NNN个串合成一个长字符串,对这个长字符串求后缀数组,包含SiS_iSi​的子串的heigh ...

  9. AcWing - 246. 区间最大公约数(树状数组+线段树)

    题目链接:点击查看 题目大意:给出一个长度为 nnn 的序列,需要执行 mmm 次操作,每次操作分为下列两种类型: C l r d:将区间 [l,r][l,r][l,r] 位置的数字都加上 ddd Q ...

最新文章

  1. Windows上IDEA搭建最新Spark2.4.3源码阅读及调试的开发环境
  2. 鲲鹏入晋 万里腾飞,鲲鹏应用创新大赛2021山西赛区邀你来战!
  3. html页面缓存meta,html中怎么用meta语句禁用页面缓存?
  4. Ubuntu如何启动Pycharm
  5. PHP中4个包含文件方法的差异
  6. 《深入理解计算机系统》CSAPP
  7. python模块-paramiko
  8. 何时创建MVC应用程序
  9. [转载] 【python系列】numpy中的tile函数
  10. redis在windows上的安装
  11. 破旧手机改造系列:最牛逼的行车记录仪
  12. Telos 首份年报(中译版-下)
  13. Shape—自定义图片(详细讲解)
  14. python学习一点 快乐一点(2)乱序整数序列两数之和绝对值最小
  15. 用相关函数法计算信号的延迟量
  16. 【Java学习】JUC并发编程
  17. 2020全国计算机考试ps版本,2020年3月计算机等级Photoshop练习题及参考答案
  18. Element UI table 修改定位
  19. 分布式协调系统ZooKeeper的安装
  20. 7.28 结构体 Day18

热门文章

  1. uni-app 用户地理位置授权
  2. php远程连接403,php中出现“ HTTP 异常 403 - 禁止访问”解决方法 总结
  3. python selenium_Python+selenium自动化测试
  4. php curl发送post请求失败,php 利用curl发送post请求
  5. 春运12306的bug
  6. java常用类总结_java——常用类的总结
  7. asp.net 4.0 新特性(翻译)
  8. ASP.NET 例程完全代码版(5)——通过web.config配置数据库连接池
  9. Linux自学笔记——Centos系统安装
  10. 动动嘴皮子就解决身份安全验证问题,这很NICE