Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //{ ************[ Template ]************
- using namespace std;
- //{ ************[ C headers ]************
- #include <cstdio>
- #include <cstdlib>
- #include <cmath>
- #include <cstring>
- #include <climits>
- #include <cfloat>
- #include <cctype>
- #include <cassert>
- #include <ctime>
- //}
- //{ ************[ C++ headers ]************
- #include <iostream>
- #include <iomanip>
- #include <sstream>
- #include <algorithm>
- #include <numeric>
- #include <utility>
- #include <string>
- #include <stack>
- #include <queue>
- #include <deque>
- #include <vector>
- #include <set>
- #include <map>
- #include <list>
- #include <complex>
- //{ ************[ Test Report 1 ]************
- // #include <tr1/regex>
- // #include <tr1/unordered_set>
- // #include <tr1/unordered_map>
- //}
- //}
- //{ ************[ Loops ]************
- #define forab(i, a, b) for (__typeof(b) i = (a); i <= (b); ++i)
- #define rep(i, n) forab (i, 0, (n) - 1)
- #define For(i, n) forab (i, 1, n)
- #define rofba(i, a, b) for (__typeof(b) i = (b); i >= (a); --i)
- #define per(i, n) rofba (i, 0, (n) - 1)
- #define rof(i, n) rofba (i, 1, n)
- #define forstl(i, s) for (__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
- //}
- //{ ************[ Floating points ]************
- #define EPS DBL_EPSILON
- #define abs(x) (((x) < 0) ? - (x) : (x))
- #define zero(x) (abs (x) < EPS)
- #define equal(a,b) (zero ((a) - (b)))
- #define PI 2 * acos (0.0)
- //}
- //{ ************[ Macros ]************
- #define mem(a, i) memset ((a), i, sizeof ((a)))
- #define clr(a) mem ((a), 0)
- #define all(a) (a).begin (), (a).end ()
- #define pb push_back
- template <class T, class U> inline T max (T &a, U &b) { return a > b ? a : b; }
- template <class T, class U> inline T min (T &a, U &b) { return a < b ? a : b; }
- static struct _ { ios_base :: Init Init; _ () { cin.sync_with_stdio (false); cin.tie (false); } } _;
- //}
- //{ ************[ Typedefs && Consts ]************
- typedef long long int64;
- typedef unsigned long long int64u;
- const int MAX_N = int (4e5) + 7;
- const int MOD = int (1e9) + 7;
- //}
- //}
- struct node {
- int key, rnk, cnt;
- node *le, *ri;
- node (int key = 0, int rnk = rand ()) : key (key), rnk (rnk), cnt (1), le (0), ri (0) {}
- };
- class treap {
- typedef node* pNode;
- pNode root;
- int count (pNode temp) { return temp ? temp -> cnt : 0; }
- void updateCnt (pNode temp) { if (temp) temp -> cnt = 1 + count (temp -> le) + count (temp -> ri); }
- void split (pNode temp, pNode &le, pNode &ri, int key) {
- if (!temp) { le = ri = 0; return; }
- if (key < temp -> key ) split (temp -> le, le, temp -> le, key), ri = temp;
- else split (temp -> ri, temp -> ri, ri, key), le = temp;
- updateCnt (temp);
- }
- void merge (pNode &temp, pNode le, pNode ri) {
- if (!le || !ri) temp = le ? le : ri;
- else if (le -> rnk > ri -> rnk) merge (le -> ri, le -> ri, ri), temp = le;
- else merge (ri -> le, le, ri -> le), temp = ri;
- updateCnt (temp);
- }
- void insert (pNode &temp, pNode it) {
- if (!temp) temp = it;
- else if (it -> rnk > temp -> rnk) split (temp, it -> le, it -> ri, it -> key), temp = it;
- else insert ((it -> key < temp -> key) ? temp -> le : temp -> ri, it);
- updateCnt (temp);
- }
- void erase (pNode &temp, int key, int rnk) {
- if (!temp) return;
- if (temp -> key == key) {
- if (rnk == -1) rnk = temp -> rnk;
- if (rnk == temp -> rnk) merge (temp, temp -> le, temp -> ri);
- else erase (temp -> ri, key, rnk);
- } else erase ((key < temp -> key) ? temp -> le : temp -> ri, key, rnk);
- updateCnt (temp);
- }
- int countLess (pNode temp, int key) {
- if (!temp) return 0;
- if (key <= temp -> key) return countLess (temp -> le, key);
- return 1 + count (temp -> le) + countLess (temp -> ri, key);
- }
- void clear (pNode cur) {
- if (cur -> le) free (cur -> le);
- if (cur -> ri) free (cur -> ri);
- free (cur);
- }
- public:
- treap () { root = 0; }
- void insert (int key, int rnk = rand ()) { insert (root, new node (key, rnk)); }
- void erase (int key, int rnk = -1) { erase (root, key, rnk); }
- void clear () { clear (root); root = 0; }
- int countLess (int key) { return countLess (root, key); }
- } treap [MAX_N];
- int n, m, u, a[MAX_N];
- void add (int x, int c) { for (int i = x; i <= n; i += i & (-i)) treap [i].insert (c); }
- void del (int x, int c) { for (int i = x; i <= n; i += i & (-i)) treap [i].erase (c); }
- int sum (int x, int v) { int y = 0; for (int i = x; i; i -= i & (-i)) y += treap [i].countLess (v); return y; }
- inline int nextInt (){
- int x = 0;
- register int c = getc (stdin);
- int sign = 0;
- for (; ((c < 48 || c > 57) && c != '-'); c = getc (stdin));
- if (c == '-') {
- sign = 1;
- c = getc (stdin);
- }
- for (; c > 47 && c < 58; c = getc (stdin)) x = (x << 1) + (x << 3) + c - 48;
- if (sign) x = -x;
- return x;
- }
- int main() {
- #ifdef Local
- freopen ("input.txt", "r", stdin);
- // freopen ("output.txt", "w", stdout);
- #endif
- while (scanf("%d %d %d",&n, &m, &u) != EOF) {
- srand (time (0));
- For (i, n) { scanf ("%d", a + i); add (i, a [i]); }
- rep (i, m) {
- int l = nextInt ();
- int r = nextInt ();
- int v = nextInt ();
- int p = nextInt ();
- int ans = sum (r, v) - sum (l - 1, v);
- del (p, a [p]);
- int64 x = u;
- x *= (int64) ans;
- x /= (r - l + 1);
- a [p] = (int) x;
- add (p, a [p]);
- }
- For (i, n) printf ("%d\n", a [i]);
- For (i, n) treap [i].clear ();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment