Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- using namespace std;
- ifstream in ("tnia.in");
- ofstream out ("tnia.out");
- long long h [100001];
- int cbin (long long x, int st, int dr) {
- int m;
- while (st < dr) {
- m = (st + dr) / 2;
- if (h [m] - h [m - 1] >= x)
- dr = m;
- else
- st = m + 1;
- }
- return st;
- }
- int main() {
- long long n, m, a, b, c, d, s;
- int q, c1, c2;
- in >> n >> m;
- for (int i = 1; i <= n; i ++) {
- in >> h [i];
- h [i] += h [i - 1];
- }
- in >> q;
- for (int i = 1; i <= q; i ++) {
- in >> a >> b >> c >> d;
- c1 = cbin (b, a, c);
- c2 = cbin (d + 1, a, c);
- cout << c1 << " " << c2 << '\n';
- s = (h [c2] - h [c1 - 1]) - ((b - 1) * (c2 - c1 + 1)) + ((d - b + 1) * (c - c2));
- out << s << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement