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: liridi, (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: xiyi, (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 nmk (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: liridi, (1 ≤ li ≤ ri ≤ n), (0 ≤ di ≤ 105).

Next k lines contain the queries, the query number i is written as two integers: xiyi, (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 离线区间修改的更多相关文章

  1. Codeforces Round #179 (Div. 1 + Div. 2)

    A. Yaroslav and Permutations 值相同的个数不能超过\(\lfloor \frac{n + 1}{2} \rfloor\). B. Yaroslav and Two Stri ...

  2. Codeforces Round #390 (Div. 2) D. Fedor and coupons(区间最大交集+优先队列)

    http://codeforces.com/contest/754/problem/D 题意: 给定几组区间,找k组区间,使得它们的公共交集最大. 思路: 在k组区间中,它们的公共交集=k组区间中右端 ...

  3. Codeforces Round #156 (Div. 2)---A. Greg&#39;s Workout

    Greg's Workout time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  4. 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  ...

  5. Codeforces Round #179 (Div. 1)

    A 直接线段树过的 两遍 貌似大多是标记过的..注意long long #include <iostream> #include <cstdio> #include <c ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #258 (Div. 2) B. Sort the Array

    题目链接:http://codeforces.com/contest/451/problem/B 思路:首先找下降段的个数,假设下降段是大于等于2的,那么就直接输出no,假设下降段的个数为1,那么就把 ...

  9. Codeforces Round #510 (Div. 2) D. Petya and Array(离散化+反向树状数组)

    http://codeforces.com/contest/1042/problem/D 题意 给一个数组n个元素,求有多少个连续的子序列的和<t (1<=n<=200000,abs ...

随机推荐

  1. Ruby窗口程序

    require 'tk' tkroot=TkRoot.new { title 'hellw word' geometry '300x200' } lb = TkLabel.new(tkroot) do ...

  2. LwIP源代码文件目录解析

    1 -- LwIP源代码文件目录 root@motadou:/home/motadou/lwip/lwip-1.4.1# tree . ├── CHANGELOG ├── COPYING ├── do ...

  3. iOS - NSLog、UncaughtException日志保存到文件

    转:http://blog.csdn.net/marujunyy/article/details/12005767 对于真机,日志没法保存,不好分析问题.所以有必要将日志保存到应用的Docunment ...

  4. 开启Ubuntu Linux下VirtualBox访问USB功能

    解决方法如下: 1.增加用户组usbfs sudo groupadd usbfs 2.查看usbfs用户组的gid cat /etc/group | grep usbfs usbfs:x:1002: ...

  5. Listview异步加载之优化篇

    异步加载图片基本思想: 1.      先从内存缓存中获取图片显示(内存缓冲) 2.      获取不到的话从SD卡里获取(SD卡缓冲) 3.      都获取不到的话从网络下载图片并保存到SD卡同时 ...

  6. java 中常见异常

    1. Java.lang.NullPointerException  这个异常大家肯定都经常遇到,异常的解释是"程序遇上了空指针",简单地说就是调用了未经初始化的对象或者是不存在的 ...

  7. ORACLE临时表总结[转]

    临时表概念 临时表就是用来暂时保存临时数据(亦或叫中间数据)的一个数据库对象,它和普通表有些类似,然而又有很大区别.它只能存储在临时表空间,而非用户的表空间.ORACLE临时表是会话或事务级别的,只对 ...

  8. [BILL WEI] A potentially dangerous Request.Path value was detected from the client 异常处理办法

    我们在ASP.net中使用URL导向后, 我们在访问某个地址,或者打开某个系统页面的时候,就会报错误: A potentially dangerous Request.Path value was d ...

  9. Android引用百度定位API第三方组件后导致其它.so文件无法正常加载的问题

    查看当前调试设备CPU架构的方法: adb.exe shell getprop ro.product.cpu.abi  (一般返回值为:armeabi-v7a) adb.exe shell getpr ...

  10. 将数据库从普通文件系统迁移到ASM中

    数据库存储的是普通的文件系统,现在将数据库迁移到ASM存储中. 准备ASM环境: [oracle@kel ~]$ asmcmd ASMCMD> ls ASM/ KEL/ ASMCMD> 在 ...