给定一个数列 \(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. vue中的Swiper使用slideTo提示no function

    参考官网资料解决:

  2. Nginx 虚拟主机中配置 server_name ⼀个server块中配置多个站点 ⼀个站点配置多个⼆级域名

    ⼀个server块中配置多个站点 server { listen 80; server_name ~^(www.)?(.+)$; index index.php index.html; root /h ...

  3. xxl-job调度任务简单使用

    简介 XXL-JOB是一个分布式任务调度平台,其核心设计目标是开发迅速.学习简单.轻量级.易扩展.现已开放源代码并接入多家公司线上产品线,开箱即用. https://www.cnblogs.com/x ...

  4. js 防抖

    // 防抖 作用:防止重复触发事件 var count = 1; var container = document.getElementById('container'); function getU ...

  5. ubuntu测网速speedometer

    下载安装speedometer sudo apt-get install speedometer 查询需要测速的网卡 ifconfig 测速 speedometer -rx enp2s0 执行效果图如 ...

  6. 7.26-javascript

    折半查找:数据必须有序 //数组定义 let arr1 = [1,2,3,4,5]; //用字面量定义数组 let arr2 = new Array(1,2,3,4,5); //用字面量定义数组 le ...

  7. 基于Vue项目+django写一个登录的页面

    基于Vue项目+django写一个登录的页面 前端 借用了一下vue项目模板的AboutView.vue 页面组件 <template> <div class="about ...

  8. REST开发(1)

    REST风格 REST简介 Rest(Representational State Transfer),表现形式状态转换(访问网络资源的形式) 传统风格资源描述形式 http://localhost/ ...

  9. npm i error:0909006C:PEM routines:get_name:no start line 遇到问题解决

    找了大半天的问题,结果是有个httpd的线程开机自动启动,把端口占用了

  10. IaaS--云虚拟机(二)(何恺铎《深入浅出云计算》笔记整理)

    [如何挑选合适的虚拟机型号] 1.根据类型.云厂商会提供均衡型.计算密集型.内存优化型.图形计算型等常见的虚拟机类型.这些类型对应着硬件资源的某种合理配比或针对性强化,方便你在面向不同场景时,选择最合 ...