Greg and Array CodeForces - 296C - 差分
给定一个数列 \(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 - 差分的更多相关文章
- Greg and Array CodeForces 296C 差分数组
Greg and Array CodeForces 296C 差分数组 题意 是说有n个数,m种操作,这m种操作就是让一段区间内的数增加或则减少,然后有k种控制,这k种控制是说让m种操作中的一段区域内 ...
- G - Greg and Array CodeForces - 296C 差分+线段树
题目大意:输入n,m,k.n个数,m个区间更新标记为1~m.n次操作,每次操作有两个数x,y表示执行第x~y个区间更新. 题解:通过差分来表示某个区间更新操作执行的次数.然后用线段树来更新区间. #i ...
- 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 ...
- Codeforces 295A Greg and Array
传送门 A. Greg and Array time limit per test 1.5 seconds memory limit per test 256 megabytes input stan ...
- Codeforces 296C Greg and Array
数据结构题.个人认为是比较好的数据结构题.题意:给定一个长度为n的数组a,然后给定m个操作序列,每个操作:l, r, x将区间[l, r]内的元素都增加a,然后有k个查询,查询形式是对于操作序列x,y ...
- CodeForces Round #179 (295A) - Greg and Array
题目链接:http://codeforces.com/problemset/problem/295/A 我的做法,两次线段树 #include <cstdio> #include < ...
- CodeForces Round #179 (295A) - Greg and Array 一个线段树做两次用
线段树的区间更新与区间求和...一颗这样的线段树用两次... 先扫描1~k...用线段树统计出每个操作执行的次数... 那么每个操作就变成了 op. l , op.r , op.c= times* ...
- Curious Array Codeforces - 407C(高阶差分(?)) || sequence
https://codeforces.com/problemset/problem/407/C (自用,勿看) 手模一下找一找规律,可以发现,对于一个修改(l,r,k),相当于在[l,r]内各位分别加 ...
- CF296C Greg and Array 查分数组
题目链接:http://codeforces.com/problemset/problem/296/C 题意:给你n.m.k,表示n个数a[i],m个对数的操作,k个对操作的操作.m个操作:数a[l] ...
- Greg and Array
Codeforces Round #179 (Div. 2) C:http://codeforces.com/problemset/problem/296/C 题意:给你一个序列,然后有两种操作,第一 ...
随机推荐
- kolla
kolla项目是为了容器化openstack,目标是做到100个节点的开箱即用,所有的组件的HA都具备.kolla是一个革命性的项目,我们以前积累的安装部署经验,全部都报废.使用kolla可以快速部署 ...
- 在centos环境下利用docker安装kail
配置好国内阿里云镜像 vim /etc/docker/daemon.json {"registry-mirrors":["https://cq20bk8v.mirror ...
- layui富文本编辑器提交时无法获取到值
使用layui的富文本提交时一直获取不到值,仔细检查代码之后发现是没有绑定textarea,要将编辑器中的内容同步到textarea中. 先在lay-verify="名字"中输入一 ...
- 使用NibiruSDK 坑
最近有项目要接NibiruSDK ,在使用时需要用他们提供的软件,进行项目签名,在这里包名前必须是 com.dream.*** ,否则会导致签名失败而且没有任何提示.用DreamClass打开apk, ...
- 【Frida】调试js代码
方法一attach启动 js代码动态注入app,app需要保持运行状态 # coding: utf-8 import sys import frida app_name = "猿人学APP& ...
- pycharm安装appium,通过国内的镜像源安装python包,注意每次都要添加信任选项 --trusted-host mirrors.aliyun.com
1.更改阿里源 或者清华源 1.file - - settings - - project - - project interpreter - - 右侧+ - - manage rep ...
- 靶场练习1:Medium_Socialnetwork
靶机链接 https://www.vulnhub.com/entry/boredhackerblog-social-network,454/ 信息收集阶段 进行主机的发现,由于已知主机跟Kali在同一 ...
- linux run/media/wang/centos_磁盘爆满
在使用iso安装了linux系统后,会有个 /run/media/wang/CentOS 7 x86_64 无法删除,这个是我们安装程序时的安装驱动, 登陆用户后将他卸载就可
- reduce对数组及数组对象的常见操作
语法: array.reduce(function(prev, currentValue, currentIndex, arr), initialValue)prev: 初始值,或者是计算结束后的返回 ...
- 如何下载zoom上别人录制的视频?
参考知乎作者"Oops chocoholic"的方法 https://www.zhihu.com/question/432030457/answer/1681898684 临时关闭 ...