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

Source: Internet
Author: User



Greg has a 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 was wondering, what the array a would be was after all the queries was 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 II Integers:xi, Yi, (1?≤?xi?≤?yi?≤?m).



The numbers in the lines is separated by a 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.



%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



With a little trick, linear complexity.


/************************************************* ************************
    > File Name: CF-179-C.cpp
    > Author: ALex
    > Mail: zchao1995@gmail.com
    > Created Time: Sunday, April 26, 2015 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;
} 


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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.