結果
問題 | No.2421 entersys? |
ユーザー |
![]() |
提出日時 | 2023-08-29 17:33:28 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,614 bytes |
コンパイル時間 | 3,952 ms |
コンパイル使用メモリ | 150,776 KB |
実行使用メモリ | 814,656 KB |
最終ジャッジ日時 | 2024-12-30 23:41:13 |
合計ジャッジ時間 | 43,103 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 MLE * 25 |
ソースコード
#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 = 500000; 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; }