Submission #1063529

# Submission time Handle Problem Language Result Execution time Memory
1063529 2024-08-17T20:00:54 Z nima_aryan Examination (JOI19_examination) C++17
100 / 100
733 ms 66724 KB
/**
 *    author:  NimaAryan
 *    created: 2024-08-17 22:57:42  
**/
#include <bits/stdc++.h>

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
template <typename T, class C = less<>>
using indexed_set = tree<T, null_type, C, rb_tree_tag,
      tree_order_statistics_node_update>;

#ifdef LOCAL
#include "algo/debug.h"
#endif

using i64 = long long;

struct Solver {
  int n;
  vector<indexed_set<int, less_equal<>>> a;

  Solver(int n) : n(n) {
    a.resize(n + 1);
  }

  void add(int x, int v) {
    for (int i = x + 1; i <= n; i += i & -i) {
      a[i].insert(v);
    }
  }

  int query(int x, int v) {
    int res = 0;
    for (int i = x + 1; i > 0; i -= i & -i) {
      res += a[i].size() - a[i].order_of_key(v);
    }
    return res;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int N, Q;
  cin >> N >> Q;

  vector<int> S(N), T(N);
  for (int i = 0; i < N; ++i) {
    cin >> S[i] >> T[i];
  }

  vector<int> X(Q), Y(Q), Z(Q);
  for (int i = 0; i < Q; ++i) {
    cin >> X[i] >> Y[i] >> Z[i];
  }

  vector<int> p(Q);
  iota(p.begin(), p.end(), 0);
  sort(p.begin(), p.end(), [&](int i, int j) {
    return Z[i] > Z[j];
  });

  vector<int> q(N);
  iota(q.begin(), q.end(), 0);
  sort(q.begin(), q.end(), [&](int i, int j) {
    return S[i] + T[i] > S[j] + T[j];
  });

  auto xs = S;
  xs.insert(xs.end(), X.begin(), X.end());
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  auto id = [&](int x) {
    return xs.end() - lower_bound(xs.begin(), xs.end(), x) - 1;
  };

  vector<int> ans(Q);

  Solver f(xs.size());
  int x = 0;
  for (int i : p) {
    while (x < N && S[q[x]] + T[q[x]] >= Z[i]) {
      f.add(id(S[q[x]]), T[q[x]]);
      ++x;
    }
    ans[i] = f.query(id(X[i]), Y[i]);
  }

  for (int i = 0; i < Q; ++i) {
    cout << ans[i] << "\n";
  }

  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 7 ms 1880 KB Output is correct
8 Correct 7 ms 1884 KB Output is correct
9 Correct 6 ms 1884 KB Output is correct
10 Correct 6 ms 1964 KB Output is correct
11 Correct 3 ms 860 KB Output is correct
12 Correct 3 ms 856 KB Output is correct
13 Correct 7 ms 1880 KB Output is correct
14 Correct 10 ms 1972 KB Output is correct
15 Correct 6 ms 1884 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 5 ms 1884 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 667 ms 52440 KB Output is correct
2 Correct 718 ms 52424 KB Output is correct
3 Correct 686 ms 52428 KB Output is correct
4 Correct 468 ms 52284 KB Output is correct
5 Correct 153 ms 15052 KB Output is correct
6 Correct 112 ms 15184 KB Output is correct
7 Correct 634 ms 52624 KB Output is correct
8 Correct 614 ms 52508 KB Output is correct
9 Correct 571 ms 52424 KB Output is correct
10 Correct 68 ms 9420 KB Output is correct
11 Correct 338 ms 52276 KB Output is correct
12 Correct 68 ms 9164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 667 ms 52440 KB Output is correct
2 Correct 718 ms 52424 KB Output is correct
3 Correct 686 ms 52428 KB Output is correct
4 Correct 468 ms 52284 KB Output is correct
5 Correct 153 ms 15052 KB Output is correct
6 Correct 112 ms 15184 KB Output is correct
7 Correct 634 ms 52624 KB Output is correct
8 Correct 614 ms 52508 KB Output is correct
9 Correct 571 ms 52424 KB Output is correct
10 Correct 68 ms 9420 KB Output is correct
11 Correct 338 ms 52276 KB Output is correct
12 Correct 68 ms 9164 KB Output is correct
13 Correct 583 ms 52404 KB Output is correct
14 Correct 694 ms 52428 KB Output is correct
15 Correct 682 ms 52308 KB Output is correct
16 Correct 394 ms 52428 KB Output is correct
17 Correct 142 ms 15052 KB Output is correct
18 Correct 117 ms 15052 KB Output is correct
19 Correct 600 ms 52720 KB Output is correct
20 Correct 648 ms 52464 KB Output is correct
21 Correct 527 ms 52680 KB Output is correct
22 Correct 68 ms 9416 KB Output is correct
23 Correct 356 ms 52428 KB Output is correct
24 Correct 67 ms 9160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 7 ms 1880 KB Output is correct
8 Correct 7 ms 1884 KB Output is correct
9 Correct 6 ms 1884 KB Output is correct
10 Correct 6 ms 1964 KB Output is correct
11 Correct 3 ms 860 KB Output is correct
12 Correct 3 ms 856 KB Output is correct
13 Correct 7 ms 1880 KB Output is correct
14 Correct 10 ms 1972 KB Output is correct
15 Correct 6 ms 1884 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 5 ms 1884 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 667 ms 52440 KB Output is correct
20 Correct 718 ms 52424 KB Output is correct
21 Correct 686 ms 52428 KB Output is correct
22 Correct 468 ms 52284 KB Output is correct
23 Correct 153 ms 15052 KB Output is correct
24 Correct 112 ms 15184 KB Output is correct
25 Correct 634 ms 52624 KB Output is correct
26 Correct 614 ms 52508 KB Output is correct
27 Correct 571 ms 52424 KB Output is correct
28 Correct 68 ms 9420 KB Output is correct
29 Correct 338 ms 52276 KB Output is correct
30 Correct 68 ms 9164 KB Output is correct
31 Correct 583 ms 52404 KB Output is correct
32 Correct 694 ms 52428 KB Output is correct
33 Correct 682 ms 52308 KB Output is correct
34 Correct 394 ms 52428 KB Output is correct
35 Correct 142 ms 15052 KB Output is correct
36 Correct 117 ms 15052 KB Output is correct
37 Correct 600 ms 52720 KB Output is correct
38 Correct 648 ms 52464 KB Output is correct
39 Correct 527 ms 52680 KB Output is correct
40 Correct 68 ms 9416 KB Output is correct
41 Correct 356 ms 52428 KB Output is correct
42 Correct 67 ms 9160 KB Output is correct
43 Correct 660 ms 64044 KB Output is correct
44 Correct 663 ms 63944 KB Output is correct
45 Correct 733 ms 63944 KB Output is correct
46 Correct 470 ms 64140 KB Output is correct
47 Correct 145 ms 15048 KB Output is correct
48 Correct 136 ms 14832 KB Output is correct
49 Correct 678 ms 66724 KB Output is correct
50 Correct 673 ms 64140 KB Output is correct
51 Correct 717 ms 66648 KB Output is correct
52 Correct 104 ms 9456 KB Output is correct
53 Correct 392 ms 63944 KB Output is correct