#include <bits/stdc++.h>
using namespace std;
#define fwd(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) fwd(i, 0, n)
#define all(X) X.begin(), X.end()
#define sz(X) int(size(X))
#define pb push_back
#define eb emplace_back
#define st first
#define nd second
using pii = pair<int, int>; using vi = vector<int>;
using ll = long long; using ld = long double;
#ifdef LOC
auto SS = signal(6, [](int) { *(int *)0 = 0; });
#define DTP(x, y) auto operator << (auto &o, auto a) -> decltype(y, o) { o << "("; x; return o << ")"; }
DTP(o << a.st << ", " << a.nd, a.nd);
DTP(for (auto i : a) o << i << ", ", all(a));
void dump(auto... x) { (( cerr << x << ", " ), ...) <<
'\n'; }
#define deb(x...) cerr << setw(4) << __LINE__ << ":[" #x "]: ", dump(x)
#else
#define deb(...) 0
#endif
const int K = 1e6;
void brute(int n, int m, int z){
vector<int> a(n);
vector<ll> v(n, 0);
rep(i, n)cin >> a[i];
rep(it, m + z){
int x, p, w; cin >> x >> p >> w;
if(x == 1){
rep(i, p)v[i] += w;
}else if(x == 2){
ll res = 0;
rep(i, p){
if(a[i] >= w)res += v[i];
}
cout << res << "\n";
}
}
}
struct SegTree{
vector<int> v;
int N = 2;
SegTree(int n){
while(N < n)N*=2;
v.resize(2*N, 0);
}
void update(int pos){
v[pos] = v[2*pos] + v[2*pos + 1];
}
int rangeSum(int a, int b, int l, int r, int pos){
if(b < l || r < a)return 0;
if(a <= l && r <= b){
return v[pos];
}
int m = (l + r)/2;
return rangeSum(a, b, l, m, 2*pos) + rangeSum(a, b, m+1, r, 2*pos + 1);
}
void add(int pos, int x){
pos += N;
v[pos] += x;
while(pos > 1){
pos /= 2;
update(pos);
}
}
int get(int a, int b){
return rangeSum(a, b, 0, N-1, 1);
}
};
void case2(int n, int m, int z){
vector<int> a(n);
rep(i, n)cin >> a[i];
int q = 0;
vector<vi> ids(z);
vector<pii> mod;
vector<array<int, 4>> query;
int zId = 0;
rep(i, m+z){
int t, p, d;
cin >> t >> p >> d;
if(t == 1){
mod.push_back({p, d});
}else{
for(auto [p1, w] : mod){
ids[zId].push_back(q);
query.push_back({min(p1, p), d, w, q});
q++;
}
zId++;
}
}
vector<ll> queryAns(q);
sort(all(query));
SegTree tree(K+1);
int pos = 0;
deb(query);
for(auto [p, d, w, qId] : query){
while(pos < p){
tree.add(a[pos], 1);
pos++;
}
queryAns[qId] = 1ll * w * tree.get(d, K);
}
rep(i, z){
ll res = 0;
for(auto id : ids[i])res += queryAns[id];
cout << res << "\n";
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(10);
int n, m, z; cin >> n >> m >> z;
int d = 1e7;
if(1ll * (m+z) * n <= d){
brute(n, m, z);
}else{
case2(n, m, z);
}
return 0;
}
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 123 124 125 126 127 128 129 130 131 132 133 134 135 | #include <bits/stdc++.h> using namespace std; #define fwd(i, a, n) for (int i = (a); i < (n); i++) #define rep(i, n) fwd(i, 0, n) #define all(X) X.begin(), X.end() #define sz(X) int(size(X)) #define pb push_back #define eb emplace_back #define st first #define nd second using pii = pair<int, int>; using vi = vector<int>; using ll = long long; using ld = long double; #ifdef LOC auto SS = signal(6, [](int) { *(int *)0 = 0; }); #define DTP(x, y) auto operator << (auto &o, auto a) -> decltype(y, o) { o << "("; x; return o << ")"; } DTP(o << a.st << ", " << a.nd, a.nd); DTP(for (auto i : a) o << i << ", ", all(a)); void dump(auto... x) { (( cerr << x << ", " ), ...) << '\n'; } #define deb(x...) cerr << setw(4) << __LINE__ << ":[" #x "]: ", dump(x) #else #define deb(...) 0 #endif const int K = 1e6; void brute(int n, int m, int z){ vector<int> a(n); vector<ll> v(n, 0); rep(i, n)cin >> a[i]; rep(it, m + z){ int x, p, w; cin >> x >> p >> w; if(x == 1){ rep(i, p)v[i] += w; }else if(x == 2){ ll res = 0; rep(i, p){ if(a[i] >= w)res += v[i]; } cout << res << "\n"; } } } struct SegTree{ vector<int> v; int N = 2; SegTree(int n){ while(N < n)N*=2; v.resize(2*N, 0); } void update(int pos){ v[pos] = v[2*pos] + v[2*pos + 1]; } int rangeSum(int a, int b, int l, int r, int pos){ if(b < l || r < a)return 0; if(a <= l && r <= b){ return v[pos]; } int m = (l + r)/2; return rangeSum(a, b, l, m, 2*pos) + rangeSum(a, b, m+1, r, 2*pos + 1); } void add(int pos, int x){ pos += N; v[pos] += x; while(pos > 1){ pos /= 2; update(pos); } } int get(int a, int b){ return rangeSum(a, b, 0, N-1, 1); } }; void case2(int n, int m, int z){ vector<int> a(n); rep(i, n)cin >> a[i]; int q = 0; vector<vi> ids(z); vector<pii> mod; vector<array<int, 4>> query; int zId = 0; rep(i, m+z){ int t, p, d; cin >> t >> p >> d; if(t == 1){ mod.push_back({p, d}); }else{ for(auto [p1, w] : mod){ ids[zId].push_back(q); query.push_back({min(p1, p), d, w, q}); q++; } zId++; } } vector<ll> queryAns(q); sort(all(query)); SegTree tree(K+1); int pos = 0; deb(query); for(auto [p, d, w, qId] : query){ while(pos < p){ tree.add(a[pos], 1); pos++; } queryAns[qId] = 1ll * w * tree.get(d, K); } rep(i, z){ ll res = 0; for(auto id : ids[i])res += queryAns[id]; cout << res << "\n"; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); int n, m, z; cin >> n >> m >> z; int d = 1e7; if(1ll * (m+z) * n <= d){ brute(n, m, z); }else{ case2(n, m, z); } return 0; } |
English