結果
問題 | No.2421 entersys? |
ユーザー | SSRS |
提出日時 | 2023-08-12 14:08:18 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 804 ms / 3,000 ms |
コード長 | 3,270 bytes |
コンパイル時間 | 2,720 ms |
コンパイル使用メモリ | 204,340 KB |
実行使用メモリ | 53,860 KB |
最終ジャッジ日時 | 2024-11-19 17:33:02 |
合計ジャッジ時間 | 17,249 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 4 ms
6,816 KB |
testcase_02 | AC | 6 ms
6,816 KB |
testcase_03 | AC | 3 ms
6,816 KB |
testcase_04 | AC | 4 ms
6,816 KB |
testcase_05 | AC | 5 ms
6,820 KB |
testcase_06 | AC | 4 ms
6,816 KB |
testcase_07 | AC | 5 ms
6,820 KB |
testcase_08 | AC | 5 ms
6,820 KB |
testcase_09 | AC | 7 ms
6,816 KB |
testcase_10 | AC | 5 ms
6,816 KB |
testcase_11 | AC | 701 ms
39,068 KB |
testcase_12 | AC | 698 ms
39,036 KB |
testcase_13 | AC | 724 ms
40,344 KB |
testcase_14 | AC | 707 ms
39,080 KB |
testcase_15 | AC | 731 ms
39,316 KB |
testcase_16 | AC | 739 ms
45,424 KB |
testcase_17 | AC | 748 ms
45,412 KB |
testcase_18 | AC | 749 ms
46,268 KB |
testcase_19 | AC | 759 ms
45,568 KB |
testcase_20 | AC | 754 ms
46,520 KB |
testcase_21 | AC | 754 ms
42,708 KB |
testcase_22 | AC | 622 ms
39,840 KB |
testcase_23 | AC | 804 ms
53,856 KB |
testcase_24 | AC | 767 ms
53,848 KB |
testcase_25 | AC | 781 ms
53,860 KB |
testcase_26 | AC | 553 ms
27,016 KB |
testcase_27 | AC | 561 ms
27,532 KB |
testcase_28 | AC | 550 ms
27,064 KB |
ソースコード
#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<long long> L(N), R(N); for (int i = 0; i < N; i++){ cin >> X[i] >> L[i] >> R[i]; L[i] = L[i] * 10 - 1; R[i] = R[i] * 10 + 1; } int Q; cin >> Q; vector<int> T(Q); vector<string> x(Q); vector<long long> 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]; t[i] *= 10; } if (T[i] == 2){ cin >> t[i]; t[i] *= 10; } if (T[i] == 3){ cin >> x[i] >> l[i] >> r[i]; l[i] = l[i] * 10 - 1; r[i] = r[i] * 10 + 1; } } vector<long long> 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); } } }