#include using namespace std; using ll=long long; const ll ILL=2167167167167167167; const int INF=2100000000; #define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++) #define all(p) p.begin(),p.end() template using _pq = priority_queue, greater>; template int LB(vector &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template int UB(vector &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template bool chmin(T &a,T b){if(b bool chmax(T &a,T b){if(a void So(vector &v) {sort(v.begin(),v.end());} template void Sore(vector &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} bool yneos(bool a,bool upp=false){if(a){cout<<(upp?"YES\n":"Yes\n");}else{cout<<(upp?"NO\n":"No\n");}return a;} template void vec_out(vector &p,int ty=0){ if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'< T vec_min(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;} template T vec_max(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;} template T vec_sum(vector &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;} int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;} template T square(T a){return a * a;} // https://nyaannyaan.github.io/library/segment-tree/segment-tree-beats.hpp.html #line 2 "segment-tree/segment-tree-beats.hpp" struct AngelBeats { using i64 = long long; static constexpr i64 INF = numeric_limits::max() / 2.1; struct alignas(32) Node { i64 sum = 0, g1 = 0, l1 = 0; i64 g2 = -INF, gc = 1, l2 = INF, lc = 1, add = 0; }; vector v; i64 n, log; AngelBeats() {} AngelBeats(int _n) : AngelBeats(vector(_n)) {} AngelBeats(const vector& vc) { n = 1, log = 0; while (n < (int)vc.size()) n <<= 1, log++; v.resize(2 * n); for (i64 i = 0; i < (int)vc.size(); ++i) { v[i + n].sum = v[i + n].g1 = v[i + n].l1 = vc[i]; } for (i64 i = n - 1; i; --i) update(i); } void range_chmin(int l, int r, i64 x) { inner_apply<1>(l, r, x); } void range_chmax(int l, int r, i64 x) { inner_apply<2>(l, r, x); } void range_add(int l, int r, i64 x) { inner_apply<3>(l, r, x); } void range_update(int l, int r, i64 x) { inner_apply<4>(l, r, x); } i64 range_min(int l, int r) { return inner_fold<1>(l, r); } i64 range_max(int l, int r) { return inner_fold<2>(l, r); } i64 range_sum(int l, int r) { return inner_fold<3>(l, r); } private: void update(int k) { Node& p = v[k]; Node& l = v[k * 2 + 0]; Node& r = v[k * 2 + 1]; p.sum = l.sum + r.sum; if (l.g1 == r.g1) { p.g1 = l.g1; p.g2 = max(l.g2, r.g2); p.gc = l.gc + r.gc; } else { bool f = l.g1 > r.g1; p.g1 = f ? l.g1 : r.g1; p.gc = f ? l.gc : r.gc; p.g2 = max(f ? r.g1 : l.g1, f ? l.g2 : r.g2); } if (l.l1 == r.l1) { p.l1 = l.l1; p.l2 = min(l.l2, r.l2); p.lc = l.lc + r.lc; } else { bool f = l.l1 < r.l1; p.l1 = f ? l.l1 : r.l1; p.lc = f ? l.lc : r.lc; p.l2 = min(f ? r.l1 : l.l1, f ? l.l2 : r.l2); } } void push_add(int k, i64 x) { Node& p = v[k]; p.sum += x << (log + __builtin_clz(k) - 31); p.g1 += x; p.l1 += x; if (p.g2 != -INF) p.g2 += x; if (p.l2 != INF) p.l2 += x; p.add += x; } void push_min(int k, i64 x) { Node& p = v[k]; p.sum += (x - p.g1) * p.gc; if (p.l1 == p.g1) p.l1 = x; if (p.l2 == p.g1) p.l2 = x; p.g1 = x; } void push_max(int k, i64 x) { Node& p = v[k]; p.sum += (x - p.l1) * p.lc; if (p.g1 == p.l1) p.g1 = x; if (p.g2 == p.l1) p.g2 = x; p.l1 = x; } void push(int k) { Node& p = v[k]; if (p.add != 0) { push_add(k * 2 + 0, p.add); push_add(k * 2 + 1, p.add); p.add = 0; } if (p.g1 < v[k * 2 + 0].g1) push_min(k * 2 + 0, p.g1); if (p.l1 > v[k * 2 + 0].l1) push_max(k * 2 + 0, p.l1); if (p.g1 < v[k * 2 + 1].g1) push_min(k * 2 + 1, p.g1); if (p.l1 > v[k * 2 + 1].l1) push_max(k * 2 + 1, p.l1); } void subtree_chmin(int k, i64 x) { if (v[k].g1 <= x) return; if (v[k].g2 < x) { push_min(k, x); return; } push(k); subtree_chmin(k * 2 + 0, x); subtree_chmin(k * 2 + 1, x); update(k); } void subtree_chmax(int k, i64 x) { if (x <= v[k].l1) return; if (x < v[k].l2) { push_max(k, x); return; } push(k); subtree_chmax(k * 2 + 0, x); subtree_chmax(k * 2 + 1, x); update(k); } template inline void _apply(int k, i64 x) { if constexpr (cmd == 1) subtree_chmin(k, x); if constexpr (cmd == 2) subtree_chmax(k, x); if constexpr (cmd == 3) push_add(k, x); if constexpr (cmd == 4) subtree_chmin(k, x), subtree_chmax(k, x); } template void inner_apply(int l, int r, i64 x) { if (l == r) return; l += n, r += n; for (int i = log; i >= 1; i--) { if (((l >> i) << i) != l) push(l >> i); if (((r >> i) << i) != r) push((r - 1) >> i); } { int l2 = l, r2 = r; while (l < r) { if (l & 1) _apply(l++, x); if (r & 1) _apply(--r, x); l >>= 1; r >>= 1; } l = l2; r = r2; } for (int i = 1; i <= log; i++) { if (((l >> i) << i) != l) update(l >> i); if (((r >> i) << i) != r) update((r - 1) >> i); } } template inline i64 e() { if constexpr (cmd == 1) return INF; if constexpr (cmd == 2) return -INF; return 0; } template inline void op(i64& a, const Node& b) { if constexpr (cmd == 1) a = min(a, b.l1); if constexpr (cmd == 2) a = max(a, b.g1); if constexpr (cmd == 3) a += b.sum; } template i64 inner_fold(int l, int r) { if (l == r) return e(); l += n, r += n; for (int i = log; i >= 1; i--) { if (((l >> i) << i) != l) push(l >> i); if (((r >> i) << i) != r) push((r - 1) >> i); } i64 lx = e(), rx = e(); while (l < r) { if (l & 1) op(lx, v[l++]); if (r & 1) op(rx, v[--r]); l >>= 1; r >>= 1; } if constexpr (cmd == 1) lx = min(lx, rx); if constexpr (cmd == 2) lx = max(lx, rx); if constexpr (cmd == 3) lx += rx; return lx; } }; /** * @brief Range Chmin Chmax Add Update Range Min Max Sum Segment Tree Beats! * @docs docs/segment-tree/segment-tree-beats.md */ void solve(); // POP'N ROLL MUSIC / TOMOO int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; rep(i, 0, t) solve(); } void solve(){ int N, K, Q; cin >> N >> K >> Q; vector A(N); rep(i, 0, N) cin >> A[i]; struct F{ int l, r; ll X; }; vector upd(K), que(Q); rep(i, 0, K) cin >> upd[i].l >> upd[i].r >> upd[i].X, upd[i].l--; rep(i, 0, Q) cin >> que[i].l >> que[i].r >> que[i].X, que[i].l--; vector ansL(Q, -1), ansR(Q, K + 1); while (true){ bool emp = true; vector> G(K + 1); rep(i, 0, Q){ if (ansL[i] + 1 != ansR[i]){ emp = false; G[(ansL[i] + ansR[i]) / 2].push_back(i); } } if (emp) break; AngelBeats seg(A); rep(i, 0, K + 1){ for (auto id : G[i]){ if (seg.range_sum(que[id].l, que[id].r) >= que[id].X){ ansR[id] = i; } else{ ansL[id] = i; } } if (i != K){ seg.range_chmax(upd[i].l, upd[i].r, upd[i].X); } } } for (auto ans : ansR){ if (ans == K + 1) cout << "-1\n"; else cout << ans << "\n"; } }