Codeforces Round #179 (Div. 2)---C. Greg and Array

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 %I64d specifier.

Sample test(s)

Input

3 3 3

1 2 3

1 2 1

1 3 2

2 3 4

1 2

1 3

2 3

Output

9 18 17

Input

1 1 1

1

1 1 1

1 1

Output

2

Input

4 3 6

1 2 3 4

1 2 1

2 3 2

3 4 4

1 2

1 3

2 3

1 2

1 3

2 3

Output

5 18 31 20

用一个小技巧就行了,线性复杂度

/*************************************************************************
    > File Name: CF-179-C.cpp
    > Author: ALex
    > Mail: [email protected]
    > Created Time: 2015年04月26日 星期日 21时52分26秒
 ************************************************************************/

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <bitset>
#include <set>
#include <vector>

using namespace std;

const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
typedef long long LL;
typedef pair <int, int> PLL;

static const int N = 100100;
LL arr[N];
LL cnt[N];
LL cnt2[N];

struct node {
    int l, r;
    LL d;
}ope[N];

int main() {
    int n, m, k, l, r;
    LL d;
    while (~scanf("%d%d%d", &n, &m, &k)) {
        memset(cnt, 0, sizeof(cnt));
        memset(cnt2, 0, sizeof(cnt2));
        for (int i = 1; i <= n; ++i) {
            scanf("%I64d", &arr[i]);
        }
        for (int i = 1; i <= m; ++i) {
            scanf("%d%d%I64d", &ope[i].l, &ope[i].r, &ope[i].d);
        }
        while (k--) {
            scanf("%d%d", &l, &r);
            ++cnt[l];
            --cnt[r + 1];
        }
        for (int i = 1; i <= m; ++i) {
            cnt[i] += cnt[i - 1];
        }
        for (int i = 1; i <= m; ++i) {
            l = ope[i].l;
            r = ope[i].r;
            d = ope[i].d;
            cnt2[l] += d * cnt[i];
            cnt2[r + 1] -= d * cnt[i];
        }
        for (int i = 1; i <= n; ++i) {
            cnt2[i] += cnt2[i - 1];
        }
        printf("%I64d", cnt2[1] + arr[1]);
        for (int i = 2; i <= n; ++i) {
            printf(" %I64d", cnt2[i] + arr[i]);
        }
        printf("\n");
    }
    return 0;
}
时间: 2024-11-10 18:48:44

Codeforces Round #179 (Div. 2)---C. Greg and Array的相关文章

Codeforces Round #179 (Div. 2)---D. Greg and Graph(离线+floyd)

Greg has a weighed directed graph, consisting of n vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game: The game consists of n steps.

Codeforces Round #258 (Div. 2) B. Sort the Array(简单题)

题目链接:http://codeforces.com/contest/451/problem/B ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943/ma

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 are non-comparable if there are two numbers, i andj(1 ≤ i, j ≤ n), such that si > wi and sj < wj. Here sign si represents the i-th digit of string s,

Codeforces Round #179 (Div. 2) B (codeforces 296b) Yaroslav and Two Strings

题目链接:点这里!!!! 题意: 给定两个长度为n(n<=1e5)的串s,w,串中能包含'0'~'9','?','?'可以代替'0'~'9'中任何一个数字. 问你能组成多少对特殊的串('?'代替为数字后的s,w),使得存在(1<=i,j<=n)si<wi,sj>wj. 题解: 1.我们假设'?'的总个数为num,则能够成的总情况为10^num. 2.我们可以通过求相反的情况来求出答案. 3.可以分为4种情况. (1)已知存在(1<=i,j<=n)si<wi,

Codeforces Round #510 (Div. 2) D. Petya and Array (权值线段树)

题目地址:http://codeforces.com/contest/1042/problem/D 题意:给你n个数,问有多少个区间的和的值小于t 分析:区间和问题,常常用到前缀和来进行预处理,所以先预处理出前缀和数组sum sum[i]代表前i个数的和,那么sum[i]的贡献就是,  当i<k<=n时,存在多少个k,使sum[k]<t+sum[i] 也就是求在[i+1,n]中,小于t+sum[i]的数有多少. 所以我们可以类比于询问一个数是区间第几大的方法,使用权值线段树来解决,这里因

Codeforces Round #569 (Div. 2) B. Nick and Array

原文链接:https://codeforces.com/contest/1180/problem/B 题意:给你n个数,你要进行一次或者多次操作(操作的方式a[i]=-a[i]-1),让它们的乘积最大,当然也可以不进行操作,答案有多组.思路:根据(操作的方式a[i]=-a[i]-1),我们发现,正数进行操作后,绝对值变大了,那么想让全部数乘积最大,就让这组数全变成负数(是不是好奇,如果存在0的问题,0进行操作可以变为(-1)),然后判断个数n的奇偶,偶数就直接输出,奇数的话把最小(除去-1)的变

Codeforces Round #258 (Div. 2/B)/Codeforces451B_Sort the Array

解题报告 http://blog.csdn.net/juncoder/article/details/38102391 对于给定的数组,取对数组中的一段进行翻转,问翻转后是否是递增有序的. 思路: 仅仅要找到最初递减的区域,记录区域内最大和最小的值,和区间位置. 然后把最大值与区间的下一个元素对照,最小值与区间上一个元素对照. 这样还不够,可能会出现两个或两个以上的递减区间,这样的情况直接pass,由于仅仅能翻转一次. #include <iostream> #include <cstd

Codeforces Round #374 (Div. 2) D. Maxim and Array

题解: 模拟题 虽然是个大模拟题,但是很考验思维的活跃度. 刚开始做的时候知道怎么做.但是自己的想法情况很多.分类枚举总是把自己混淆 这题教会我的是,要仔细思考分类的方式 这个题.根据枚举负数的个数奇偶来判断 为奇数:那么绝对值最小的数,如果是正,+x,是负,-x; 为偶数:那么使得绝对值最小的数.改变符号,如果正-x,负+x. 代码: #include<bits/stdc++.h> #define maxn 200010 #define mod 1000000007 #define ll l

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

Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers. Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array,