結果

問題 No.2421 entersys?
ユーザー simansiman
提出日時 2023-08-29 17:35:11
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,614 bytes
コンパイル時間 4,420 ms
コンパイル使用メモリ 111,880 KB
実行使用メモリ 814,608 KB
最終ジャッジ日時 2023-08-29 17:35:21
合計ジャッジ時間 7,399 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
31,268 KB
testcase_01 MLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

const int MAX_N = 300000;

class RangeAddQuery {
  public:
    vector<ll> bit0;
    vector<ll> bit1;

    RangeAddQuery(int N = MAX_N) {
      bit0.resize(N + 1);
      bit1.resize(N + 1);
    }

    void update(int l, int r, ll x) {
      add(bit0, l, -x * (l - 1));
      add(bit1, l, x);
      add(bit0, r + 1, x * r);
      add(bit1, r + 1, -x);
    }

    ll get(int i) {
      return get(i, i);
    }

    ll get(int l, int r) {
      ll res = 0;
      res += sum(bit0, r) + sum(bit1, r) * r;
      res -= sum(bit0, l - 1) + sum(bit1, l - 1) * (l - 1);

      return res;
    }

  private:
    void add(vector<ll> &b, int i, ll v) {
      while (i <= MAX_N) {
        b[i] += v;
        i += i & -i;
      }
    }

    ll sum(vector<ll> &b, int i) {
      ll s = 0;
      while (i > 0) {
        s += b[i];
        i -= i & -i;
      }
      return s;
    }
};

int main() {
  int N;
  cin >> N;
  string X[N];
  int L[N];
  int R[N];
  set<int> S;
  set<string> names;
  for (int i = 0; i < N; ++i) {
    cin >> X[i] >> L[i] >> R[i];

    names.insert(X[i]);
    S.insert(L[i]);
    S.insert(R[i]);
  }

  int Q;
  cin >> Q;
  int types[Q];
  string X2[Q];
  int T[Q];
  int L2[Q];
  int R2[Q];

  for (int i = 0; i < Q; ++i) {
    int type;
    cin >> type;

    types[i] = type;

    if (type == 1) {
      cin >> X2[i] >> T[i];
      S.insert(T[i]);
    } else if (type == 2) {
      cin >> T[i];
      S.insert(T[i]);
    } else {
      cin >> X2[i] >> L2[i] >> R2[i];
      names.insert(X2[i]);
      S.insert(L2[i]);
      S.insert(R2[i]);
    }
  }

  map<int, int> pos;
  int idx = 1;
  for (int s : S) {
    pos[s] = idx;
    ++idx;
  }

  map<string, RangeAddQuery> memo;
  RangeAddQuery raq;

  for (int i = 0; i < N; ++i) {
    string x = X[i];
    int l = pos[L[i]];
    int r = pos[R[i]];

    raq.update(l, r, 1);
    memo[x].update(l, r, 1);
  }

  for (int i = 0; i < Q; ++i) {
    int type = types[i];

    if (type == 1) {
      string x = X2[i];
      int t = pos[T[i]];

      if (memo[x].get(t)) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    } else if (type == 2) {
      int t = pos[T[i]];
      cout << raq.get(t) << endl;
    } else {
      string x = X2[i];
      int l = pos[L2[i]];
      int r = pos[R2[i]];
      raq.update(l, r, 1);
      memo[x].update(l, r, 1);
    }
  }

  return 0;
}
0