結果

問題 No.2421 entersys?
ユーザー a01sa01toa01sa01to
提出日時 2023-08-12 14:37:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,593 ms / 3,000 ms
コード長 2,687 bytes
コンパイル時間 2,999 ms
コンパイル使用メモリ 248,956 KB
実行使用メモリ 56,992 KB
最終ジャッジ日時 2024-04-30 06:40:00
合計ジャッジ時間 27,781 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 4 ms
6,816 KB
testcase_02 AC 6 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 6 ms
6,944 KB
testcase_06 AC 5 ms
6,940 KB
testcase_07 AC 5 ms
6,944 KB
testcase_08 AC 6 ms
6,940 KB
testcase_09 AC 9 ms
6,940 KB
testcase_10 AC 5 ms
6,940 KB
testcase_11 AC 1,281 ms
43,148 KB
testcase_12 AC 1,284 ms
43,156 KB
testcase_13 AC 1,282 ms
43,152 KB
testcase_14 AC 1,286 ms
43,152 KB
testcase_15 AC 1,276 ms
43,068 KB
testcase_16 AC 1,327 ms
46,156 KB
testcase_17 AC 1,347 ms
46,100 KB
testcase_18 AC 1,306 ms
46,108 KB
testcase_19 AC 1,316 ms
45,932 KB
testcase_20 AC 1,360 ms
45,952 KB
testcase_21 AC 1,292 ms
42,212 KB
testcase_22 AC 1,062 ms
40,060 KB
testcase_23 AC 1,586 ms
56,828 KB
testcase_24 AC 1,593 ms
56,992 KB
testcase_25 AC 1,558 ms
56,836 KB
testcase_26 AC 909 ms
39,872 KB
testcase_27 AC 922 ms
40,012 KB
testcase_28 AC 925 ms
39,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
  #include "settings/debug.cpp"
  #define _GLIBCXX_DEBUG
#else
  #define Debug(...) void(0)
#endif
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)

#include <atcoder/fenwicktree>

int main() {
  int n;
  cin >> n;

  vector<tuple<string, int, int>> info(n);
  rep(i, n) {
    string x;
    int l, r;
    cin >> x >> l >> r;
    info[i] = { x, l, r + 1 };
  }
  int q;
  cin >> q;
  vector<tuple<int, string, int, int>> query(q);
  rep(i, q) {
    int qtype;
    cin >> qtype;
    if (qtype == 1) {
      string x;
      int t;
      cin >> x >> t;
      query[i] = { qtype, x, t, -1 };
    }
    if (qtype == 2) {
      int t;
      cin >> t;
      query[i] = { qtype, "", t, -1 };
    }
    if (qtype == 3) {
      string x;
      int l, r;
      cin >> x >> l >> r;
      query[i] = { qtype, x, l, r + 1 };
    }
  }

  int comp_cnt = 0;
  {  // compress
    set<int> st;
    rep(i, n) {
      auto [_, l, r] = info[i];
      st.insert(l), st.insert(r);
    }
    rep(i, q) {
      auto [_, __, l, r] = query[i];
      st.insert(l), st.insert(r);
    }
    st.erase(-1);
    map<int, int> mp;
    for (int x : st) mp[x] = comp_cnt++;
    mp[-1] = -1;
    rep(i, n) {
      auto&& [_, l, r] = info[i];
      l = mp[l], r = mp[r];
    }
    rep(i, q) {
      auto&& [_, __, l, r] = query[i];
      l = mp[l], r = mp[r];
    }
  }

  map<string, set<int>> entered, exited;
  atcoder::fenwick_tree<int> fw(comp_cnt + 1);
  rep(i, n) {
    auto [x, l, r] = info[i];
    if (exited[x].count(l)) {
      exited[x].erase(l);
    }
    else {
      entered[x].insert(l);
    }
    if (entered[x].count(r)) {
      entered[x].erase(r);
    }
    else {
      exited[x].insert(r);
    }
    entered[x].insert(2e9);
    exited[x].insert(2e9);
    fw.add(l, 1);
    fw.add(r, -1);
  }
  rep(i, q) {
    int qtype = get<0>(query[i]);
    if (qtype == 1) {
      auto [_, x, t, __] = query[i];
      int l = *entered[x].upper_bound(t);
      int r = *exited[x].upper_bound(t);
      if (r < l) {
        cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl;
      }
    }
    if (qtype == 2) {
      auto [_, __, t, ___] = query[i];
      cout << fw.sum(0, t + 1) << endl;
    }
    if (qtype == 3) {
      auto [_, x, l, r] = query[i];
      if (exited[x].count(l)) {
        exited[x].erase(l);
      }
      else {
        entered[x].insert(l);
      }
      if (entered[x].count(r)) {
        entered[x].erase(r);
      }
      else {
        exited[x].insert(r);
      }
      entered[x].insert(2e9);
      exited[x].insert(2e9);
      fw.add(l, 1);
      fw.add(r, -1);
    }
  }
  return 0;
}
0