結果
問題 | No.2421 entersys? |
ユーザー | SSRS |
提出日時 | 2023-08-12 14:01:48 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,134 bytes |
コンパイル時間 | 2,449 ms |
コンパイル使用メモリ | 199,964 KB |
実行使用メモリ | 50,412 KB |
最終ジャッジ日時 | 2024-11-19 17:05:30 |
合計ジャッジ時間 | 16,472 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 4 ms
5,248 KB |
testcase_02 | AC | 5 ms
5,248 KB |
testcase_03 | AC | 3 ms
5,248 KB |
testcase_04 | AC | 3 ms
5,248 KB |
testcase_05 | AC | 5 ms
5,248 KB |
testcase_06 | AC | 4 ms
5,248 KB |
testcase_07 | AC | 4 ms
5,248 KB |
testcase_08 | AC | 6 ms
5,248 KB |
testcase_09 | AC | 7 ms
5,248 KB |
testcase_10 | AC | 4 ms
5,248 KB |
testcase_11 | AC | 670 ms
35,820 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 716 ms
42,092 KB |
testcase_21 | AC | 713 ms
39,020 KB |
testcase_22 | AC | 596 ms
36,592 KB |
testcase_23 | AC | 739 ms
50,412 KB |
testcase_24 | AC | 732 ms
50,408 KB |
testcase_25 | AC | 755 ms
50,152 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
ソースコード
#include <bits/stdc++.h> using namespace std; template <typename T> struct dual_invertible_binary_indexed_tree{ int N; vector<T> BIT; function<T(T, T)> f; function<T(T)> inv; T E; dual_invertible_binary_indexed_tree(int N, function<T(T, T)> f, function<T(T)> inv, T E): N(N), BIT(N + 1, E), f(f), inv(inv), E(E){ } void add(int i, T x){ while (i > 0){ BIT[i] = f(BIT[i], x); i -= i & -i; } } void add(int l, int r, T x){ add(l, inv(x)); add(r, x); } T operator [](int i){ i++; T ans = E; while (i <= N){ ans = f(ans, BIT[i]); i += i & -i; } return ans; } }; int main(){ int N; cin >> N; vector<string> X(N); vector<int> L(N), R(N); for (int i = 0; i < N; i++){ cin >> X[i] >> L[i] >> R[i]; R[i]++; } int Q; cin >> Q; vector<int> T(Q); vector<string> x(Q); vector<int> t(Q), l(Q), r(Q); for (int i = 0; i < Q; i++){ cin >> T[i]; if (T[i] == 1){ cin >> x[i] >> t[i]; } if (T[i] == 2){ cin >> t[i]; } if (T[i] == 3){ cin >> x[i] >> l[i] >> r[i]; r[i]--; } } vector<int> time; for (int i = 0; i < N; i++){ time.push_back(L[i]); time.push_back(R[i]); } for (int i = 0; i < Q; i++){ if (T[i] == 1){ time.push_back(t[i]); } if (T[i] == 2){ time.push_back(t[i]); } if (T[i] == 3){ time.push_back(l[i]); time.push_back(r[i]); } } sort(time.begin(), time.end()); time.erase(unique(time.begin(), time.end()), time.end()); for (int i = 0; i < N; i++){ L[i] = lower_bound(time.begin(), time.end(), L[i]) - time.begin(); R[i] = lower_bound(time.begin(), time.end(), R[i]) - time.begin(); } for (int i = 0; i < Q; i++){ if (T[i] == 1){ t[i] = lower_bound(time.begin(), time.end(), t[i]) - time.begin(); } if (T[i] == 2){ t[i] = lower_bound(time.begin(), time.end(), t[i]) - time.begin(); } if (T[i] == 3){ l[i] = lower_bound(time.begin(), time.end(), l[i]) - time.begin(); r[i] = lower_bound(time.begin(), time.end(), r[i]) - time.begin(); } } int M = time.size(); set<string> id; for (int i = 0; i < N; i++){ id.insert(X[i]); } for (int i = 0; i < Q; i++){ if (t[i] == 1 || t[i] == 3){ id.insert(x[i]); } } map<string, set<pair<int, int>>> st; for (string s : id){ st[s].insert(make_pair(-1, 1)); st[s].insert(make_pair(M + 1, 0)); } dual_invertible_binary_indexed_tree<int> BIT(M, plus<int>(), negate<int>(), 0); for (int i = 0; i < N; i++){ st[X[i]].insert(make_pair(L[i], 0)); st[X[i]].insert(make_pair(R[i], 1)); BIT.add(L[i], R[i], 1); } for (int i = 0; i < Q; i++){ if (T[i] == 1){ auto itr = st[x[i]].upper_bound(make_pair(t[i], 2)); if ((*itr).second == 1){ cout << "Yes" << endl; } else { cout << "No" << endl; } } if (T[i] == 2){ cout << BIT[t[i]] << endl; } if (T[i] == 3){ st[x[i]].insert(make_pair(l[i], 0)); st[x[i]].insert(make_pair(r[i], 1)); BIT.add(l[i], r[i], 1); } } }