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
// clang-format off
#include<bits/stdc++.h>
using namespace std;
using LL=long long;
#define FOR(i,l,r) for(auto i=(l);i<=(r);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define ssize(x) int(x.size())
template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<"("<<p.first<<", "<<p.second<<")";}
template<class T>auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<"}";}
#ifdef DEBUG
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<"\n";}(X)
#else
#define debug(...) {}
#endif
// clang-format on

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using ordered_set
  = __gnu_pbds::tree<pair<int, int>,
                     __gnu_pbds::null_type,
                     less<pair<int, int>>,
                     __gnu_pbds::rb_tree_tag,
                     __gnu_pbds::tree_order_statistics_node_update>;

int ndays, nmods, nqueries;
vector<int> tree_of_day;
vector<tuple<int, int, int>> operations;


int
main()
{
    cin.tie(0)->sync_with_stdio(0);
    cin >> ndays >> nmods >> nqueries;
    tree_of_day.resize(ndays);

    for (auto& x : tree_of_day) cin >> x;

    // Save operations and generate "greater or equal" queries to be answered
    vector<unordered_map<int, int>> ge_ans(ndays);
    operations.resize(nmods + nqueries);
    vector<pair<int, int>> mods;
    for (auto& operation : operations) {
        auto& [type, pref, param] = operation;
        cin >> type >> pref >> param;
        if (type == 1) {
            mods.emplace_back(pref, param);
        } else {
            for (const auto& mod : mods) {
                int p                = min(pref, mod.first);
                ge_ans[p - 1][param] = 0;

                // REP (day, p)
                //     if (tree_of_day[day] >= param) score += mod.second;
            }
        }
    }

    // Answer greater or equal questions
    ordered_set oset;
    REP (day, ndays) {
        oset.insert({tree_of_day[day], day});
        debug(day, oset);
        for (auto& entry : ge_ans[day]) {
            const auto& question = entry.first;
            entry.second = ssize(oset) - oset.order_of_key({question, 0});
            debug(day, entry);
        }
    }

    // Answer queries basing on data we now have
    mods.clear();
    for (auto& operation : operations) {
        auto& [type, pref, param] = operation;
        if (type == 1) {
            mods.emplace_back(pref, param);
        } else {
            LL score = 0;
            for (const auto& mod : mods) {
                int p = min(pref, mod.first);
                score += 1LL * mod.second * ge_ans[p - 1][param];
            }
            cout << score << "\n";
        }
    }
    return 0;
}