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
136
#include "bits/stdc++.h"
using namespace std;

#define rep(i, b, e) for(int i = (b); i <= (e); i++)
#define per(i, b, e) for(int i = (e); i >= (b); i--)
#define FOR(i, b, e) rep(i, b, (e) - 1)
#define SZ(x) int(x.size())
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

auto &operator<<(auto &o, pair<auto, auto> p) {
    return o << "(" << p.st << ", " << p.nd << ")"; }
auto operator<<(auto &o, auto x)->decltype(end(x), o) {
    o << "{"; int i=0; for(auto e: x) o << ", " + 2*!i++ << e;
    return o << "}"; }
#ifdef LOCAL
#define deb(x...) cerr << "[" #x "]: ", [](auto...$) { \
    ((cerr << $ << "; "),...) << endl; }(x)
#else
#define deb(...)
#endif

const int RR = 1'000'002;

struct Kubel {
    int n;
    vi a, sVal, sPos, gdzie;
    vector<ll> cnt, suf;
    short smal[RR];
    ll shift = 0;

    Kubel() {}

    void init(vi _a) {
        a = _a;
        n = SZ(a);
        vector<pii> vals;
        FOR(i, 0, n) vals.pb({a[i], i});
        sort(all(vals));
        FOR(i, 0, n) sVal.pb(vals[i].st), sPos.pb(vals[i].nd);
        gdzie.resize(n);
        FOR(i, 0, n) gdzie[sPos[i]] = i;
        cnt.resize(n);
        suf.resize(n + 1);
        memset(smal, 0, sizeof(smal));
        FOR(i, 0, n) smal[a[i]]++;
        FOR(i, 1, RR) smal[i] += smal[i - 1];
    }

    void dod(int d, int p) {
        FOR(i, 0, p) cnt[gdzie[i]] += d;
        for(int i = n - 1; i >= 0; i--) suf[i] = suf[i + 1] + cnt[i];
    }

    ll queAll(int d) {
        int id = smal[d - 1];
        return suf[id] + (n - id) * shift;
    }

    ll que(int d, int p) {
        int id = smal[d - 1];
        ll sum = 0;
        FOR(i, id, n) sum += (sPos[i] < p ? cnt[i] + shift : 0);
        return sum;
    }
};

const int B = 2400;

inline char gc() { // like getchar()
	static char buf[1 << 16];
	static size_t bc, be;
	if (bc >= be) {
		buf[0] = 0, bc = 0;
		be = fread(buf, 1, sizeof(buf), stdin);
	}
	return buf[bc++]; // returns 0 on EOF
}

int readInt() {
	int a, c;
	while ((a = gc()) < 40);
	if (a == '-') return -readInt();
	while ((c = gc()) >= 48) a = a * 10 + c - 480;
	return a - 48;
}

void write(ll x) {
    char xd[64];
    int ptr = 0;
    do {
        xd[ptr++] = x % 10 + '0';
        x /= 10;
    } while(x > 0);
    while(ptr > 0) putchar_unlocked(xd[--ptr]);
    putchar_unlocked('\n');
}

void solve() {
    int n = readInt(), m = readInt(), q = readInt();
    vi a(n);
    for(auto &x: a) x = readInt();
    vector<Kubel> kubly((n + B - 1) / B);
    for(int i = 0, id = 0; i < n; i += B, id++) {
        kubly[id].init(vi(a.begin() + i, a.begin() + min(i + B, n)));
    }
    FOR(qq, 0, m + q) {
        int t = readInt(), p = readInt(), d = readInt();
        p--;
        int last = p / B;
        if(t == 1) {
            FOR(i, 0, last) kubly[i].shift += d;
            kubly[last].dod(d, p % B + 1);
        }
        else {
            ll ans = 0;
            FOR(i, 0, last) ans += kubly[i].queAll(d);
            ans += kubly[last].que(d, p % B + 1);
            write(ans);
        }
    }
}

int main() {
    cin.tie(0)->sync_with_stdio(0);
    int tt = 1;
    // cin >> tt;
    FOR(te, 0, tt) solve();
    return 0;
}