Submission #61826772


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
/*
[5, 7, 3, 4]
*/
class fenTree {
int n;
vector <i64> tree;
public:
fenTree(int n) {
this -> n = n;
tree.resize(n + 1);
}
void upd(int pos, int del) {
for (int i = pos; i <= n; i += i & -i) {
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

/*
  [5, 7, 3, 4]

*/


class fenTree {
  int n;
  vector <i64> tree;
public:
  fenTree(int n) {
    this -> n = n;
    tree.resize(n + 1);
  }
  void upd(int pos, int del) {
    for (int i = pos; i <= n; i += i & -i) {
      tree[i] += del;
    }
  }
  i64 qry(int r) {
    i64 res = 0;
    for (int i = r; i >= 1; i -= i & -i) {
      res += tree[i];
    }
    return res;
  }
  i64 range(int l, int r) {
    return qry(r) - qry(l - 1);
  }
};

const int N = 5e5;

void solve() {
  int n;
  cin >> n;

  vector <array <int, 2>> a (n);
  for (int i = 0; i < n; ++i) {
    auto &[x, y] = a[i];
    cin >> x >> y;
  }

  fenTree tree(N + 5);
  for (int i = 1; i <= N; ++i) {
    tree.upd(i, i);
    tree.upd(i + 1, -i);
  }

  auto pr = [&] () -> void {
    for (int i = 1; i <= n; ++i) {
      cout << tree.qry(i) << ' ';
    }
    cout << '\n';
  };

  // pr();

  for (int i = 0; i < n; ++i) {
    auto [x, y] = a[i];
    int L = N + 1, R = 0;
    int lo = 0, hi = N + 1;
    while (hi - lo > 1) {
      int mid = (lo + hi) >> 1;
      int at = tree.qry(mid);
      if (at >= x) hi = mid;
      else lo = mid;
    }
    L = hi;

    lo = 0, hi = N + 1;
    while (hi - lo > 1) {
      int mid = (lo + hi) >> 1;
      int at = tree.qry(mid);
      if (at <= y) lo = mid;
      else hi = mid;
    }
    R = lo;

    if (L <= R) {
      tree.upd(L, 1);
      tree.upd(R + 1, -1);
    }
    // pr();
  }

  int q;
  cin >> q;
  while(q--) {
    int x;
    cin >> x;

    int ans = tree.qry(x);
    cout << ans << '\n';
  }
}

int main() {
  ios_base::sync_with_stdio(0);cin.tie(0);
  int tests = 1;
  // cin >> tests;
  for (int test = 0; test < tests; ++test) {
    solve();
  }
}

Submission Info

Submission Time
Task F - Rated Range
User coleworld223
Language C++ 20 (gcc 12.2)
Score 525
Code Size 1859 Byte
Status AC
Exec Time 248 ms
Memory 8720 KB

Compile Error

Main.cpp: In function ‘void solve()’:
Main.cpp:55:8: warning: variable ‘pr’ set but not used [-Wunused-but-set-variable]
   55 |   auto pr = [&] () -> void {
      |        ^~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 3
AC × 36
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 11 ms 7004 KB
00_sample_01.txt AC 12 ms 6984 KB
00_sample_02.txt AC 11 ms 7012 KB
01_test_00.txt AC 12 ms 7048 KB
01_test_01.txt AC 12 ms 6952 KB
01_test_02.txt AC 12 ms 6984 KB
01_test_03.txt AC 11 ms 6996 KB
01_test_04.txt AC 102 ms 7664 KB
01_test_05.txt AC 248 ms 8596 KB
01_test_06.txt AC 195 ms 8296 KB
01_test_07.txt AC 234 ms 8536 KB
01_test_08.txt AC 208 ms 8628 KB
01_test_09.txt AC 235 ms 8660 KB
01_test_10.txt AC 95 ms 7540 KB
01_test_11.txt AC 237 ms 8720 KB
01_test_12.txt AC 131 ms 7824 KB
01_test_13.txt AC 236 ms 8616 KB
01_test_14.txt AC 152 ms 8084 KB
01_test_15.txt AC 237 ms 8588 KB
01_test_16.txt AC 30 ms 7044 KB
01_test_17.txt AC 232 ms 8592 KB
01_test_18.txt AC 162 ms 8196 KB
01_test_19.txt AC 231 ms 8560 KB
01_test_20.txt AC 143 ms 8628 KB
01_test_21.txt AC 145 ms 8604 KB
01_test_22.txt AC 140 ms 8628 KB
01_test_23.txt AC 152 ms 8540 KB
01_test_24.txt AC 216 ms 8580 KB
01_test_25.txt AC 214 ms 8564 KB
01_test_26.txt AC 219 ms 8592 KB
01_test_27.txt AC 221 ms 8532 KB
01_test_28.txt AC 11 ms 7136 KB
01_test_29.txt AC 11 ms 6952 KB
01_test_30.txt AC 11 ms 7004 KB
01_test_31.txt AC 11 ms 7136 KB
01_test_32.txt AC 11 ms 7080 KB


2025-03-05 (Wed)
20:49:38 +00:00