108262024-04-16 08:23:41TomaSajtTelefonközpontcpp17Accepted 100/100167ms18496 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;

struct segtree {
  int len = 0;
  vector<int> v;

  segtree(const vector<int>& data)
      : len(data.size()), v(data.size() * 4, INT_MIN) {
    build(data, 0, len, 0);
  }

  void build(const vector<int>& data, int lx, int rx, int x) {
    if (lx + 1 == rx) {
      v[x] = data[lx];
      return;
    }
    int m = (lx + rx) / 2;
    build(data, lx, m, 2 * x + 1);
    build(data, m, rx, 2 * x + 2);
    v[x] = max(v[2 * x + 1], v[2 * x + 2]);
  }

  int get(int ql, int qr) {
    return get(ql, qr, 0, len, 0);
  }

  int get(int ql, int qr, int xl, int xr, int x) {
    if (qr <= xl || xr <= ql) return INT_MIN;
    if (ql <= xl && xr <= qr) return v[x];
    int m = (xl + xr) / 2;
    return max(get(ql, qr, xl, m, 2 * x + 1), get(ql, qr, m, xr, 2 * x + 2));
  }
};

signed main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int m, n, q;
  cin >> m >> n >> q;

  vector<int> diffs(m + 2), x(m + 2);
  while (n--) {
    int s, e;
    cin >> s >> e;
    diffs[s]++;
    diffs[e + 1]--;
  }

  partial_sum(diffs.begin(), diffs.end(), x.begin());
  segtree st(x);

  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << st.get(l, r + 1) << '\n';
  }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1832 KiB
2Accepted3ms2056 KiB
subtask220/20
3Accepted3ms2292 KiB
4Accepted3ms2456 KiB
5Accepted3ms2676 KiB
6Accepted3ms2888 KiB
7Accepted3ms2976 KiB
8Accepted3ms3180 KiB
9Accepted3ms3068 KiB
subtask320/20
10Accepted3ms2292 KiB
11Accepted3ms2456 KiB
12Accepted3ms2676 KiB
13Accepted3ms2888 KiB
14Accepted3ms2976 KiB
15Accepted3ms3180 KiB
16Accepted3ms3068 KiB
17Accepted6ms3588 KiB
18Accepted6ms3880 KiB
19Accepted6ms3756 KiB
20Accepted6ms4028 KiB
21Accepted6ms4060 KiB
22Accepted6ms4000 KiB
23Accepted6ms4008 KiB
subtask460/60
24Accepted3ms2292 KiB
25Accepted3ms2456 KiB
26Accepted3ms2676 KiB
27Accepted3ms2888 KiB
28Accepted3ms2976 KiB
29Accepted3ms3180 KiB
30Accepted3ms3068 KiB
31Accepted6ms3588 KiB
32Accepted6ms3880 KiB
33Accepted6ms3756 KiB
34Accepted6ms4028 KiB
35Accepted6ms4060 KiB
36Accepted6ms4000 KiB
37Accepted6ms4008 KiB
38Accepted167ms17864 KiB
39Accepted165ms18196 KiB
40Accepted165ms18300 KiB
41Accepted160ms18260 KiB
42Accepted160ms18252 KiB
43Accepted162ms18368 KiB
44Accepted164ms18496 KiB