/** author: shobonvip created: 2025.12.11 16:28:50 **/ #include using namespace std; //* ATCODER #include using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) #define all(v) v.begin(), v.end() template bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template T max(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template T min(vector &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template T sum(vector &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, k, q; cin >> n >> k >> q; vector a(n); rep(i,0,n) { cin >> a[i]; } const int sz = 1 << 18; vector rt(k); vector p(k); // make range tree vector v(2*sz, vector(0)); rep(i,0,k) { cin >> p[i] >> rt[i]; p[i]--; int x = p[i] + sz; while (x > 0) { v[x].emplace_back(i); x >>= 1; } } rep(i,0,2*sz) { sort(all(v[i])); v[i].erase(unique(all(v[i])), v[i].end()); } vector> fw(2*sz, fenwick_tree(0)); rep(i,0,2*sz) { fw[i] = fenwick_tree((int)v[i].size()); } vector l(q),r(q); vector d(q),u(q); rep(i,0,q){ cin >> l[i] >> r[i] >> d[i] >> u[i]; l[i]--; d[i]--; } vector bucket(k, vector(0)); rep(i,0,q) { bucket[l[i]].emplace_back(i); } auto add = [&](int x, int y, ll hen) ->void { cout << x << ' ' << y << ' ' << hen << endl; x += sz; while (x > 0) { int t = int(lower_bound(all(v[x]), y) - v[x].begin()); fw[x].add(t, hen); x >>= 1; } }; auto que = [&](int l, int r, int mx) -> ll { l += sz; r += sz; ll ans = 0; while (l < r) { if (l & 1) { int t = int(lower_bound(all(v[l]), mx) - v[l].begin()); ans += fw[l].sum(0, t); l++; } if (r & 1) { r--; int t = int(lower_bound(all(v[r]), mx) - v[r].begin()); ans += fw[r].sum(0, t); } l >>= 1; r >>= 1; } return ans; }; vector ans(q); vector rui(n+1); rep(i,0,n) rui[i+1] = rui[i] + a[i]; vector val(n, vector(1, ll(1e18))); vector ind(n, vector(1, k)); vector sub(n, vector(1, 0LL)); rrep(i,0,k) { int x = p[i]; if (a[x] < rt[i]) { while (rt[i] >= val[x].back()) { add(x, ind[x].back(), - sub[x].back()); val[x].pop_back(); ind[x].pop_back(); sub[x].pop_back(); } val[x].push_back(rt[i]); ind[x].push_back(i); sub[x].push_back(rt[i] - a[x]); add( x, ind[x].back(), sub[x].back() ); ll new_sa = val[x][(int)val[x].size()-2] - val[x].back(); if (ind[x][(int)ind[x].size()-2] < k) { add( x, ind[x][(int)ind[x].size()-2], new_sa - sub[x][(int)sub[x].size()-2] ); sub[x][(int)sub[x].size() - 2] = new_sa; } } for (int ind: bucket[i]) { ans[ind] = que(d[ind], u[ind], r[ind]) + rui[u[ind]] - rui[d[ind]]; } } rep(i,0,q) { cout << ans[i] << '\n'; } }