結果

問題 No.2421 entersys?
ユーザー KudeKude
提出日時 2023-08-12 14:06:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 500 ms / 3,000 ms
コード長 2,971 bytes
コンパイル時間 3,611 ms
コンパイル使用メモリ 258,812 KB
実行使用メモリ 34,052 KB
最終ジャッジ日時 2024-04-30 04:59:01
合計ジャッジ時間 11,958 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 4 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 391 ms
27,520 KB
testcase_12 AC 372 ms
27,520 KB
testcase_13 AC 384 ms
27,520 KB
testcase_14 AC 369 ms
27,520 KB
testcase_15 AC 374 ms
27,584 KB
testcase_16 AC 376 ms
28,668 KB
testcase_17 AC 364 ms
28,924 KB
testcase_18 AC 364 ms
28,804 KB
testcase_19 AC 371 ms
28,796 KB
testcase_20 AC 372 ms
28,668 KB
testcase_21 AC 373 ms
28,036 KB
testcase_22 AC 271 ms
24,044 KB
testcase_23 AC 492 ms
34,052 KB
testcase_24 AC 458 ms
33,912 KB
testcase_25 AC 500 ms
33,920 KB
testcase_26 AC 282 ms
25,156 KB
testcase_27 AC 288 ms
25,088 KB
testcase_28 AC 274 ms
25,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

template <class S>
struct value_compression : vector<S> {
  bool built = false;
  using VS = vector<S>;
  using VS::VS;
  value_compression(vector<S> v) : vector<S>(move(v)) {}
  void build() {
    sort(this->begin(), this->end());
    this->erase(unique(this->begin(), this->end()), this->end());
    built = true;
  }
  template <class T>
  void convert(T first, T last) {
    assert(built);
    for (; first != last; ++first) *first = (*this)(*first);
  }
  int operator()(S x) {
    assert(built);
    return lower_bound(this->begin(), this->end(), x) - this->begin();
  }
  void clear() {
    this->clear();
    built = false;
  }
};

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<tuple<string, int, int>> xlr(n);
  value_compression<string> name2id;
  value_compression<int> vc;
  for(auto& [x, l, r] : xlr) {
    cin >> x >> l >> r, l--;
    name2id.emplace_back(x);
    vc.emplace_back(l);
    vc.emplace_back(r);
  }
  int q;
  cin >> q;
  struct Q {
    int type;
    string x;
    int l, r;
  };
  vector<Q> queries(q);
  for(auto& [type, x, l, r] : queries) {
    cin >> type;
    if (type == 1) {
      cin >> x >> l;
      l--;
      name2id.emplace_back(x);
      vc.emplace_back(l);
    } else if (type == 2) {
      cin >> l;
      l--;
      vc.emplace_back(l);
    } else {
      cin >> x >> l >> r;
      l--;
      name2id.emplace_back(x);
      vc.emplace_back(l);
      vc.emplace_back(r);
    }
  }
  name2id.build();
  vc.build();
  int pcnt = name2id.size();
  int tcnt = vc.size();
  vector<map<int, int>> segs(pcnt);
  fenwick_tree<int> ft(tcnt);
  for(auto& [x, l, r] : xlr) {
    int p = name2id(x);
    l = vc(l);
    r = vc(r);
    segs[p][r] = l;
    ft.add(l, 1);
    ft.add(r, -1);
  }
  for(auto& [type, x, l, r] : queries) {
    if (type == 1) {
      int p = name2id(x);
      l = vc(l);
      auto it = segs[p].upper_bound(l);
      bool ok = it != segs[p].end() && it->second <= l;
      cout << (ok ? "Yes\n" : "No\n");
    } else if (type == 2) {
      l = vc(l);
      cout << ft.sum(0, l + 1) << '\n';
    } else {
      int p = name2id(x);
      l = vc(l);
      r = vc(r);
      segs[p][r] = l;
      ft.add(l, 1);
      ft.add(r, -1);
    }
  }
}
0