結果
問題 | No.2421 entersys? |
ユーザー | SSRS |
提出日時 | 2023-08-12 14:06:45 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,264 bytes |
コンパイル時間 | 2,574 ms |
コンパイル使用メモリ | 203,524 KB |
実行使用メモリ | 44,304 KB |
最終ジャッジ日時 | 2024-11-19 17:24:42 |
合計ジャッジ時間 | 15,058 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
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 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
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<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<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); } } }