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/problem/A
Description
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 %I64dspecifier.
Sample Input
3 3 3
1 2 3
1 2 1
1 3 2
2 3 4
1 2
1 3
2 3
Sample Output
9 18 17
HINT
题意
给你n个数,然后有m个命令,每个命令是将[l,r]中的数都增加d,有k次真正要执行的操作(。。),是将第[l,r]的命令执行一遍
然后问你,这个n个数,最后悔变成什么模样。
题解:
这道题扫一遍就好了,由于只有最后一次询问,那么我们可以离线去做,而不用去写什么线段树
首先我们离线处理操作,然后得到每一个命令都会执行多少次,然后我们再离线去处理命令就好了
离线处理,就是在起始端和结束段打上标记,然后扫一遍就好了
代码:
#include<iostream>
#include<stdio.h>
using namespace std;
#define maxn 100005
long long a[maxn];
long long flag[maxn];
long long t[maxn];
struct OP
{
int x,y;
long long val;
};
OP op[maxn];
int main()
{
int n,m,k;scanf("%d%d%d",&n,&m,&k);
for(int i=;i<=n;i++)
scanf("%lld",&a[i]);
for(int i=;i<=m;i++)
{
int x,y;long long z;
scanf("%d%d%lld",&op[i].x,&op[i].y,&op[i].val);
}
for(int i=;i<=k;i++)
{
int x,y;scanf("%d%d",&x,&y);
t[x]++;
t[y+]--;
}
long long sum = ;
for(int i=;i<=m;i++)
{
sum+=t[i];
op[i].val*=sum;
}
for(int i=;i<=m;i++)
{
flag[op[i].x]+=op[i].val;
flag[op[i].y+]-=op[i].val;
}
sum = ;
for(int i=;i<=n;i++)
{
sum+=flag[i];
printf("%lld ",a[i]+sum);
}
printf("\n");
}
Codeforces Round #179 (Div. 1) A. Greg and Array 离线区间修改的更多相关文章
- Codeforces Round #179 (Div. 1 + Div. 2)
A. Yaroslav and Permutations 值相同的个数不能超过\(\lfloor \frac{n + 1}{2} \rfloor\). B. Yaroslav and Two Stri ...
- Codeforces Round #390 (Div. 2) D. Fedor and coupons(区间最大交集+优先队列)
http://codeforces.com/contest/754/problem/D 题意: 给定几组区间,找k组区间,使得它们的公共交集最大. 思路: 在k组区间中,它们的公共交集=k组区间中右端 ...
- Codeforces Round #156 (Div. 2)---A. Greg's Workout
Greg's Workout time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces Round #179 (Div. 2) B. Yaroslav and Two Strings (容斥原理)
题目链接 Description Yaroslav thinks that two strings s and w, consisting of digits and having length n ...
- Codeforces Round #179 (Div. 1)
A 直接线段树过的 两遍 貌似大多是标记过的..注意long long #include <iostream> #include <cstdio> #include <c ...
- Codeforces Round #331 (Div. 2) B. Wilbur and Array 水题
B. Wilbur and Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/p ...
- Codeforces Round #Pi (Div. 2) D. One-Dimensional Battle Ships set区间分解
D. One-Dimensional Battle ShipsTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/co ...
- Codeforces Round #258 (Div. 2) B. Sort the Array
题目链接:http://codeforces.com/contest/451/problem/B 思路:首先找下降段的个数,假设下降段是大于等于2的,那么就直接输出no,假设下降段的个数为1,那么就把 ...
- Codeforces Round #510 (Div. 2) D. Petya and Array(离散化+反向树状数组)
http://codeforces.com/contest/1042/problem/D 题意 给一个数组n个元素,求有多少个连续的子序列的和<t (1<=n<=200000,abs ...
随机推荐
- Squid 反向代理加速网站
本实例的域名是 wenjin.cache.ibm.com.cn,通过DNS的轮询 技术,将客户端的请求分发给其中一台 Squid 反向代理服务器处理,如果这台 Squid 缓存了用户的请求资源,则将请 ...
- equals方法
一.equals方法介绍 1.1.通过下面的例子掌握equals的用法 package cn.galc.test; public class TestEquals { public static vo ...
- 典型的 SQL 注入过程(转)
无意间发现某站点存在 SQL 注入漏洞,于是利用这个漏洞提权并获取服务器控制权.这个案例很典型,像是教科书式的典型入侵步骤,下面就以这个案例展示从 SQL 注入到获取目标服务器控制权限的全过程. 发现 ...
- codeforces 691F Couple Cover 暴力
分析:开一个300w的数组,统计,然后nlogn统计每个值在在序对第一个出现有多少种情况 时间复杂度:O(nlogn) n在3e6数量级 #include<cstdio> #include ...
- 关于DISPLAY变量显示问题
DISPLAY用来设置将图形显示到何处 在本机上直接登录之后,startx,可以发现display变量自动设置为 [oracle@kel ~]$ echo $DISPLAY :0.0 不论使用何种用户 ...
- 基于Python的Grib数据可视化
http://www.cnblogs.com/kallan/p/5160017.html
- 杂谈:HTML 5页面可视性API
译文来源:http://www.ido321.com/1126.html 原文:HTML5 Page Visibility API 译文:HTML 5的页面可视性API 译者:dwqs 在早期,浏览器 ...
- Google Maps API显示地图的小示例
来源:http://www.ido321.com/1089.html 效果(新版Firefox中测试): 代码: <!DOCTYPE> <html> <head> ...
- C#选择排序详解
选择排序图解 选择排序(Selection sort)是一种简单直观的排序算法.它的工作原理如下.首先在未排序序列中找到最小(大)元素,存放到排序序列的 ...
- 线性模型(1):Perceptron Learning Algorithm (PLA)
此笔记源于台湾大学林轩田老师<机器学习基石><机器学习技法> (一) PLA算法是基本的binary Classification算法. 一个基本的问题是,对于银行,假设我知道 ...