結果
問題 | No.2421 entersys? |
ユーザー | SSRS |
提出日時 | 2023-08-12 14:02:32 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,134 bytes |
コンパイル時間 | 2,417 ms |
コンパイル使用メモリ | 199,900 KB |
実行使用メモリ | 50,408 KB |
最終ジャッジ日時 | 2024-11-19 17:09:09 |
合計ジャッジ時間 | 16,607 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 3 ms
5,248 KB |
testcase_02 | AC | 6 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 | 5 ms
5,248 KB |
testcase_08 | AC | 5 ms
5,248 KB |
testcase_09 | AC | 8 ms
5,248 KB |
testcase_10 | AC | 4 ms
5,248 KB |
testcase_11 | AC | 670 ms
35,820 KB |
testcase_12 | AC | 655 ms
35,820 KB |
testcase_13 | AC | 656 ms
35,824 KB |
testcase_14 | AC | 667 ms
35,820 KB |
testcase_15 | AC | 669 ms
35,816 KB |
testcase_16 | AC | 704 ms
42,092 KB |
testcase_17 | AC | 700 ms
42,220 KB |
testcase_18 | AC | 689 ms
42,092 KB |
testcase_19 | AC | 711 ms
42,216 KB |
testcase_20 | AC | 706 ms
42,220 KB |
testcase_21 | AC | 720 ms
39,020 KB |
testcase_22 | AC | 605 ms
36,716 KB |
testcase_23 | AC | 752 ms
50,288 KB |
testcase_24 | AC | 743 ms
50,408 KB |
testcase_25 | AC | 708 ms
50,284 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); } } }