给定一个数列 \(a= { a_1,a_2,...,a_n }\) 以及 \(m\) 次操作,\(q\) 次查询。

其中第 \(i\) 次操作如同:\(l_i, r_i, d_i\),意指区间 \([ l_i, r_i]\) 中每个元素加上 \(d_i\)。

其中第 \(i\) 次查询如同:\(x_i, y_i\),意指需要执行第 \(x_i,x_i+1,...y_i\) 次操作。

现在问你,执行完所有查询后的序列 \(a\) 是怎么样的。

Input

第 \(1\) 行 \(n,m,k\);

第 \(2\) 行 \(a_1,a_2,...,a_n\);

接下来 \(m\) 行,每行三个整数 \(l_i,r_i,d_i\);

接下来 \(k\) 行,每行三个整数 \(x_i,y_i\);

数据范围:\(1≤n,m,k≤10^5, 1≤l_i≤r_i≤n, 0≤a_i,d_i≤10^5, 1≤x_i≤y_i≤m\)。

Output

单行打印 \(a_1, a_2, ..., a_n\)。用空格分隔打印的数字。

Sample Input 1

3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3

Sample Output 1

9 18 17

分析

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e6+10,INF=0x3f3f3f3f;
LL n,m,k,a[N],l[N],r[N],d[N],res=0;
LL b[N],c[N]; //#define local
int main(){
#ifdef local
freopen("data.in", "r", stdin);
// freopen("data.out", "w", stdout);
#endif cin>>n>>m>>k;
for(int i=1; i<=n; i++) cin>>a[i];
for(int i=1; i<=m; i++) cin>>l[i]>>r[i]>>d[i];
int x,y;
while(k--){
cin>>x>>y; b[x]++, b[y+1]--;
}
for(int i=1; i<=m; i++) b[i]+=b[i-1];
for(int i=1; i<=m; i++){
c[l[i]] += d[i]*b[i];
c[r[i]+1] -= d[i]*b[i];
}
for(int i=1; i<=n; i++) c[i]+=c[i-1], a[i]+=c[i];
for(int i=1; i<=n; i++) cout<<a[i]<<" \n"[i==n];
return 0;
}

Greg and Array CodeForces - 296C - 差分的更多相关文章

  1. Greg and Array CodeForces 296C 差分数组

    Greg and Array CodeForces 296C 差分数组 题意 是说有n个数,m种操作,这m种操作就是让一段区间内的数增加或则减少,然后有k种控制,这k种控制是说让m种操作中的一段区域内 ...

  2. G - Greg and Array CodeForces - 296C 差分+线段树

    题目大意:输入n,m,k.n个数,m个区间更新标记为1~m.n次操作,每次操作有两个数x,y表示执行第x~y个区间更新. 题解:通过差分来表示某个区间更新操作执行的次数.然后用线段树来更新区间. #i ...

  3. Codeforces Round #179 (Div. 1) A. Greg and Array 离线区间修改

    A. Greg and Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/295/pro ...

  4. Codeforces 295A Greg and Array

    传送门 A. Greg and Array time limit per test 1.5 seconds memory limit per test 256 megabytes input stan ...

  5. Codeforces 296C Greg and Array

    数据结构题.个人认为是比较好的数据结构题.题意:给定一个长度为n的数组a,然后给定m个操作序列,每个操作:l, r, x将区间[l, r]内的元素都增加a,然后有k个查询,查询形式是对于操作序列x,y ...

  6. CodeForces Round #179 (295A) - Greg and Array

    题目链接:http://codeforces.com/problemset/problem/295/A 我的做法,两次线段树 #include <cstdio> #include < ...

  7. CodeForces Round #179 (295A) - Greg and Array 一个线段树做两次用

    线段树的区间更新与区间求和...一颗这样的线段树用两次... 先扫描1~k...用线段树统计出每个操作执行的次数... 那么每个操作就变成了 op. l  , op.r , op.c= times* ...

  8. Curious Array Codeforces - 407C(高阶差分(?)) || sequence

    https://codeforces.com/problemset/problem/407/C (自用,勿看) 手模一下找一找规律,可以发现,对于一个修改(l,r,k),相当于在[l,r]内各位分别加 ...

  9. CF296C Greg and Array 查分数组

    题目链接:http://codeforces.com/problemset/problem/296/C 题意:给你n.m.k,表示n个数a[i],m个对数的操作,k个对操作的操作.m个操作:数a[l] ...

  10. Greg and Array

    Codeforces Round #179 (Div. 2) C:http://codeforces.com/problemset/problem/296/C 题意:给你一个序列,然后有两种操作,第一 ...

随机推荐

  1. [jQuery]判断页面是否滚动到底部

    方法1:判断可见高度+滚动高度是否等于内容高度 但经过测试UC.QQ.华为浏览器,这个方法不生效.(打印查因:可能由于屏幕缩放,可见高度和滚动高度会偏小. $(this).scroll(functio ...

  2. java原生生成验证码

    @WebServlet("/code") public class VerifyCodeUtils extends HttpServlet { @Override protecte ...

  3. vue项目使用vue-amap调用高德地图api详细步骤

    想要的效果如下 : 高德地图 && 信息窗体 步骤一: 申请高德key 高德开放平台 | 高德地图API (amap.com) (可参考博客:   [996]如何申请高德地图用户Key ...

  4. span&不同字体

    <html> <style> .p1{ color:red; font-size:28px; } .p2{ font-weight:bold; } .p3{ font-styl ...

  5. 性能测试工具locust压测介绍

    官方文档:https://docs.locust.io/en/stable/index.html 1.初识locust Locust 完全基本 Python 编程语言,采用python 编写压测脚本, ...

  6. linux忘记密码-进入单用户模式修改密码

    1.重启系统 重启可以使用命令 reboot.init 6.shutdown -r now 或点击VMware-虚拟机-电源-重新启动客户机 2.进入GRUB界面 重启后,在启动界面按上下方向键选择第 ...

  7. nacos服务端和客户端版本不一致的时候,客户端无限刷日志

    解决方法: logging: level: com: alibaba: nacos: client: error

  8. js动态删除添加一行

    <div class="input-dyna-add"> <form class="form-inline form-group" role= ...

  9. [Swift] 在 OC 工程中,创建和使用 Swift

    1.我们创建了一个 Objective-C 的工程,叫做 playGround. 2.首先,我们需要在 工程的 Build Settings,找到 如中所示的项目,并将 Defines Module ...

  10. 用windows 定时任务执行kettle的ktr文件,以及问题处理

    新建.bat文件,输入下面的批处理语句 d: cd D:\kettle\data-integration\ pan /file D:\etltest\EtltestTrans.ktr 第一行:进入你的 ...