给定一个数列 \(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. 同一个tomcat的项目跳转

  2. kubeSphere v3.3.0+kubernetes v1.22.10 集群部署

    概述 KubeSphere 是 GitHub 上的一个开源项目,是成千上万名社区用户的聚集地.很多用户都在使用 KubeSphere 运行工作负载.对于在 Linux 上的安装,KubeSphere ...

  3. 使用vue3对数据进行分页展示

    要获取用户的滚动位置,可以在末尾添加一列空白节点.每当出现空白时意味着滑倒网页最底部,则进行渲染数据.可以使用getBoundingClientRect来判断是否在页面底部. getBoundingC ...

  4. 在Github上搭建个人主页

    最近试着在github上搭建个人主页,没用github给的模板,用的是自己在网上找到那种类似个人主页的模板,到时候直接上传到仓库里就行了 首先先创建仓库,点击右上角的加号,选择New reposito ...

  5. springboot上传图片

    springboot上传图片 新建一个springboot项目: 在java/main/com/ljx 创建一个controller.fileController类 内容如下: package com ...

  6. 思科数据中心CCIE v3.0考试内容

    考试内容: CCIE DC LAB V3.0 考试内容 1 Design 30 + 选择,拖图及勾选题 2 Deploy&Operate&Optimize 1 套 含3部分 备考安排: ...

  7. mybatisplus根据json字段查询

    参考:https://blog.csdn.net/m0_73311735/article/details/126869623

  8. ts的接口和泛型的基本语法

    一.接口 1.接口定义 接口是一种规范的定义,它定义行为和规范,在程序设计中接口起到限制和规范的作用. 2.接口的声明与使用 //声明对象类型接口 interface Person {   name: ...

  9. Twenty-eight

    组件之间的父子关系 使用组件的三个步骤 步骤1:使用import语法导入需要的组件 步骤2:使用conponents节点注册组件 步骤3:以标签形式使用刚才注册的组件   通过components注册 ...

  10. linux check folder files how many files

    https://linuxhandbook.com/count-number-files/ tree -a