#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a); i < (b); i++) #define all(x) begin(x), end(x) #define sz(x) int((x).size()) using ll = long long; using pii = pair<int, int>; using vi = vector<int>; #ifdef LOCAL auto operator<<(auto& o, auto x) -> decltype(x.first, o); auto operator<<(auto& o, auto x) -> decltype(x.end(), o) { o << "{"; for (int i = 0; auto y : x) o << ", " + !i++ * 2 << y; return o << "}"; } auto operator<<(auto& o, auto x) -> decltype(x.first, o) { return o << "(" << x.first << ", " << x.second << ")"; } void __print(auto... x) { ((cerr << x << " "), ...) << endl; } #define debug(x...) __print("[" #x "]:", x) #else #define debug(...) 2137 #endif const int nax = 1e6 + 10; int a[nax]; ll val[nax]; pair<int, ll> upd[nax]; pair<int, int> qr[nax]; array<int, 3> op[2 * nax]; struct node { int val, tl, tr; node *l = 0, *r = 0; node(int tl, int tr, int val = 0) : val(val), tl(tl), tr(tr) {} void extend() { int tm = (tl + tr) >> 1; if(!l) l = new node(tl, tm); if(!r) r = new node(tm, tr); } node* upd(int i, int x) { if(tl + 1 == tr) { return new node(tl, tr, val + x); } extend(); int tm = (tl + tr) >> 1; node* v = new node(tl, tr); if(i < tm) { v->l = l->upd(i, x); v->r = r; } else { v->l = l; v->r = r->upd(i, x); } v->val = v->l->val + v->r->val; return v; } int get(int a, int b) { if(a <= tl && tr <= b) return val; if(b <= tl || a >= tr) return 0; extend(); int tm = (tl + tr) >> 1; return l->get(a, b) + r->get(a, b); } }; int main() { cin.tie(0)->sync_with_stdio(0); ll n, m, z; cin >> n >> m >> z; for(int i = 0; i < n; i++) cin >> a[i]; int cur_m = -1, cur_z = -1; for(int i = 0; i < m + z; i++) { int t, p, d; cin >> t >> p >> d; if(t == 1) { upd[++cur_m] = {p, d}; } else { qr[++cur_z] = {p, d}; } op[i] = {t, cur_m, cur_z}; } const int bnd1 = 1e7 + 10; if((m + z) * n <= bnd1) { for(int i = 0; i < m + z; i++) { if(op[i][0] == 1) { auto [p, w] = upd[op[i][1]]; for(int j = 0; j < p; j++) val[j] += w; } else { auto [p, d] = qr[op[i][2]]; ll res = 0; for(int j = 0; j < p; j++) { if(a[j] >= d) res += val[j]; } cout << res << '\n'; } } } else if(1 || z * m <= bnd1) { vector<node*> t(n + 1); t[0] = new node(0, nax); for(int i = 0; i < n; i++) { t[i + 1] = t[i]->upd(a[i], 1); } for(int i = 0; i < m + z; i++) { if(op[i][0] == 2) { auto [p, d] = qr[op[i][2]]; int id = op[i][1]; ll res = 0; for(int j = 0; j <= id; j++) { auto [q, w] = upd[j]; int cnt = t[min(p, q)]->get(d, nax); res += cnt * w; } cout << res << '\n'; } } } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a); i < (b); i++) #define all(x) begin(x), end(x) #define sz(x) int((x).size()) using ll = long long; using pii = pair<int, int>; using vi = vector<int>; #ifdef LOCAL auto operator<<(auto& o, auto x) -> decltype(x.first, o); auto operator<<(auto& o, auto x) -> decltype(x.end(), o) { o << "{"; for (int i = 0; auto y : x) o << ", " + !i++ * 2 << y; return o << "}"; } auto operator<<(auto& o, auto x) -> decltype(x.first, o) { return o << "(" << x.first << ", " << x.second << ")"; } void __print(auto... x) { ((cerr << x << " "), ...) << endl; } #define debug(x...) __print("[" #x "]:", x) #else #define debug(...) 2137 #endif const int nax = 1e6 + 10; int a[nax]; ll val[nax]; pair<int, ll> upd[nax]; pair<int, int> qr[nax]; array<int, 3> op[2 * nax]; struct node { int val, tl, tr; node *l = 0, *r = 0; node(int tl, int tr, int val = 0) : val(val), tl(tl), tr(tr) {} void extend() { int tm = (tl + tr) >> 1; if(!l) l = new node(tl, tm); if(!r) r = new node(tm, tr); } node* upd(int i, int x) { if(tl + 1 == tr) { return new node(tl, tr, val + x); } extend(); int tm = (tl + tr) >> 1; node* v = new node(tl, tr); if(i < tm) { v->l = l->upd(i, x); v->r = r; } else { v->l = l; v->r = r->upd(i, x); } v->val = v->l->val + v->r->val; return v; } int get(int a, int b) { if(a <= tl && tr <= b) return val; if(b <= tl || a >= tr) return 0; extend(); int tm = (tl + tr) >> 1; return l->get(a, b) + r->get(a, b); } }; int main() { cin.tie(0)->sync_with_stdio(0); ll n, m, z; cin >> n >> m >> z; for(int i = 0; i < n; i++) cin >> a[i]; int cur_m = -1, cur_z = -1; for(int i = 0; i < m + z; i++) { int t, p, d; cin >> t >> p >> d; if(t == 1) { upd[++cur_m] = {p, d}; } else { qr[++cur_z] = {p, d}; } op[i] = {t, cur_m, cur_z}; } const int bnd1 = 1e7 + 10; if((m + z) * n <= bnd1) { for(int i = 0; i < m + z; i++) { if(op[i][0] == 1) { auto [p, w] = upd[op[i][1]]; for(int j = 0; j < p; j++) val[j] += w; } else { auto [p, d] = qr[op[i][2]]; ll res = 0; for(int j = 0; j < p; j++) { if(a[j] >= d) res += val[j]; } cout << res << '\n'; } } } else if(1 || z * m <= bnd1) { vector<node*> t(n + 1); t[0] = new node(0, nax); for(int i = 0; i < n; i++) { t[i + 1] = t[i]->upd(a[i], 1); } for(int i = 0; i < m + z; i++) { if(op[i][0] == 2) { auto [p, d] = qr[op[i][2]]; int id = op[i][1]; ll res = 0; for(int j = 0; j <= id; j++) { auto [q, w] = upd[j]; int cnt = t[min(p, q)]->get(d, nax); res += cnt * w; } cout << res << '\n'; } } } } |