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 ...
随机推荐
- Android 仿百度网页音乐播放器圆形图片转圈播放效果
百度网页音乐播放器的效果 如下 : http://www.baidu.com/baidu?word=%E4%B8%80%E7%9B%B4%E5%BE%88%E5%AE%89%E9%9D%99& ...
- Android自定义的webView——可实现的网页文本的复制
package com.example.customlinearlayout.view; import android.app.ProgressDialog; import android.conte ...
- SwipeRefreshLayout的简要说明及使用demo
在最新的 Android Support Library, revision 19.1.0 (March 2014) 添加了SwipeRefreshLayout控件. 版本发布的说明信息如下: ...
- 【转】《APUE》第三章笔记(4)及习题3-2
原文网址:http://www.cnblogs.com/fusae-blog/p/4256794.html APUE第三章的最后面给出的函数,现在还用不着,所以,先留个名字,待到时候用着了再补上好了. ...
- Oracle数据库表结构导出
1. 在PL/SQL中找到"工具--导出用户对象"菜单.点击运行.
- Jedis的Sharded源代码分析
概述 Jedis是Redis官方推荐的Java客户端,更多Redis的客户端可以参考Redis官网客户端列表.当业务的数据量非常庞大时,需要考虑将数据存储到多个缓存节点上,如何定位数据应该存储的节点, ...
- mvc JavaScriptResult的用法
一.JavaScriptResult在MVC中的定义的代码片段 C# 代码 复制 public class JavaScriptResult : ActionResult { public o ...
- 【和我一起学python吧】Python 启航
话说万张高楼平地起,不会走之前先学会爬吧.尤其对于我等的小菜同学来说更是这样,不管怎么先code first吧,等我等小菜们翅膀硬了才test first吧. 1, 怎么运行python? 先到pyt ...
- Tkinter教程之Toplevel篇
本文转载自:http://blog.csdn.net/jcodeer/article/details/1811341 '''Tkinter教程之Toplevel篇'''#TopLevel与Frame类 ...
- 轻松突击ThreadLocal
本文出自 代码大湿 代码大湿 ThreadLocal是用来保存线程的本地变量,可以保证每个线程都有一个自己的变量(包括static变量). 本文所有代码请点击我 1 看个实际场景. 我们要设计一个序列 ...