結果

問題 No.2421 entersys?
ユーザー siro53siro53
提出日時 2023-08-12 16:13:43
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 507 ms / 3,000 ms
コード長 2,016 bytes
コンパイル時間 2,799 ms
コンパイル使用メモリ 232,732 KB
実行使用メモリ 17,424 KB
最終ジャッジ日時 2024-11-20 05:14:39
合計ジャッジ時間 11,520 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/fenwicktree>
using namespace std;
using ll = long long;

struct E {
  int type, time, uid, qid;
};

int main() {
  int N;
  cin >> N;
  map<string, int> ID;
  auto get_id = [&](string x) -> int {
    if(ID.count(x)) return ID[x];
    int res = ID.size();
    ID[x] = res;
    return res;
  };
  vector<E> es;
  for(int i = 0; i < N; i++) {
    string x;
    int L, R;
    cin >> x >> L >> R;
    int uid = get_id(x);
    es.push_back(E{1, L, uid, -1});
    es.push_back(E{2, R+1, uid, -1});
  }
  int Q;
  cin >> Q;
  for(int i = 0; i < Q; i++) {
    int t;
    cin >> t;
    if(t == 1) {
      string x;
      int time;
      cin >> x >> time;
      int uid = get_id(x);
      es.emplace_back(E{3, time, uid, i});
    } else if(t == 2) {
      int time;
      cin >> time;
      es.emplace_back(E{4, time, -1, i});
    } else {
      string x;
      int L, R;
      cin >> x >> L >> R;
      int uid = get_id(x);
      es.emplace_back(E{1, L, uid, i});
      es.emplace_back(E{2, R+1, uid, i});
    }
  }
  sort(es.begin(), es.end(), [](const E& l, const E& r) {
    if(l.time != r.time) return (l.time < r.time);
    return (l.type < r.type);
  });
  multiset<pair<int, int>> id_set;
  atcoder::fenwick_tree<int> bt(Q+1);
  vector<tuple<int, int, int>> ans;
  for(const auto& e : es) {
    if(e.type == 1) {
      id_set.insert({e.uid, -e.qid});
      bt.add(e.qid + 1, 1);
    } else if(e.type == 2) {
      id_set.erase(id_set.find({e.uid, -e.qid}));
      bt.add(e.qid + 1, -1);
    } else if(e.type == 3) {
      auto it = id_set.upper_bound({e.uid, -e.qid});
      if(e.qid != -1) {
      	if(it != id_set.end() and it->first == e.uid) ans.emplace_back(e.qid, 1, 1);
      	else ans.emplace_back(e.qid, 1, 0);
      }
    } else {
      if(e.qid != -1) ans.emplace_back(e.qid, 2, bt.sum(0, e.qid + 1));
    }
  }
  sort(ans.begin(), ans.end());
  for(const auto& [_, t, v] : ans) {
    if(t == 1) cout << (v ? "Yes" : "No") << '\n';
    else cout << v << '\n';
  }
}
0