結果
問題 | No.2421 entersys? |
ユーザー | takumi152 |
提出日時 | 2023-08-12 14:54:59 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,069 ms / 3,000 ms |
コード長 | 4,596 bytes |
コンパイル時間 | 2,117 ms |
コンパイル使用メモリ | 151,960 KB |
実行使用メモリ | 72,488 KB |
最終ジャッジ日時 | 2024-11-19 22:11:31 |
合計ジャッジ時間 | 17,254 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 3 ms
5,248 KB |
testcase_02 | AC | 4 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 3 ms
5,248 KB |
testcase_05 | AC | 4 ms
5,248 KB |
testcase_06 | AC | 4 ms
5,248 KB |
testcase_07 | AC | 4 ms
5,248 KB |
testcase_08 | AC | 4 ms
5,248 KB |
testcase_09 | AC | 6 ms
5,248 KB |
testcase_10 | AC | 4 ms
5,248 KB |
testcase_11 | AC | 717 ms
54,492 KB |
testcase_12 | AC | 729 ms
54,360 KB |
testcase_13 | AC | 709 ms
54,496 KB |
testcase_14 | AC | 718 ms
54,364 KB |
testcase_15 | AC | 724 ms
54,380 KB |
testcase_16 | AC | 728 ms
57,692 KB |
testcase_17 | AC | 742 ms
57,564 KB |
testcase_18 | AC | 734 ms
57,564 KB |
testcase_19 | AC | 738 ms
57,564 KB |
testcase_20 | AC | 738 ms
57,564 KB |
testcase_21 | AC | 621 ms
49,760 KB |
testcase_22 | AC | 593 ms
50,016 KB |
testcase_23 | AC | 1,069 ms
72,488 KB |
testcase_24 | AC | 1,060 ms
72,416 KB |
testcase_25 | AC | 1,068 ms
72,484 KB |
testcase_26 | AC | 508 ms
44,384 KB |
testcase_27 | AC | 512 ms
44,384 KB |
testcase_28 | AC | 515 ms
44,384 KB |
ソースコード
#include <iostream> #include <iomanip> #include <vector> #include <algorithm> #include <utility> #include <string> #include <queue> #include <stack> #include <unordered_set> #include <unordered_map> #include <set> #include <map> using namespace std; typedef long long int ll; typedef pair<int, int> Pii; const ll mod = 998244353; template <class T> struct prop_segtree { int n; vector<T> data; vector<bool> propFlag; prop_segtree(const int s) { init(s); } prop_segtree(const int s, const T u) { init(s); for (int i = 0; i < s; i++) { data[i+n-1] = u; } for (int i = n-2; i >= 0; i--) { data[i] = 0; } } prop_segtree(const vector<T> &v) { int s = v.size(); init(s); for (int i = 0; i < s; i++) { data[i+n-1] = v[i]; } for (int i = n-2; i >= 0; i--) { data[i] = 0; } } void init(const int s) { n = 1; while (n < s) n <<= 1; data = vector<T>(2*n-1); propFlag = vector<bool>(2*n-1); } void propagate(int p, int a, int b) { if (propFlag[p]) { if (b - a > 1) { data[p*2+1] += data[p]; data[p*2+2] += data[p]; propFlag[p*2+1] = true; propFlag[p*2+2] = true; data[p] = 0; } propFlag[p] = false; } } void update(int l, int r, T v, int p = 0, int a = 0, int b = -1) { if (b < 0) b = n; // init // propagate value propagate(p, a, b); if (r <= a || b <= l) return; // out of range if (l <= a && b <= r) { // fully covered data[p] += v; propFlag[p] = true; propagate(p, a, b); } else { update(l, r, v, p*2+1, a, (a + b) / 2); // left update(l, r, v, p*2+2, (a + b) / 2, b); // right } return; } T query(int x, T p = 0, int a = 0, int b = -1) { if (b < 0) b = n; // init // propagate value propagate(p, a, b); if (b - a == 1) return data[p];// reached to bottom if (x < (a + b) / 2) return query(x, p*2+1, a, (a + b) / 2); // left else return query(x, p*2+2, (a + b) / 2, b); // right } }; struct query { int type; string x; int t, l, r; }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<tuple<string, int, int>> xlr(n); for (int i = 0; i < n; i++) { cin >> get<0>(xlr[i]) >> get<1>(xlr[i]) >> get<2>(xlr[i]); } int q; cin >> q; vector<query> que(q); for (int i = 0; i < q; i++) { query qu; cin >> qu.type; if (qu.type == 1) { cin >> qu.x >> qu.t; } else if (qu.type == 2) { cin >> qu.t; } else if (qu.type == 3) { cin >> qu.x >> qu.l >> qu.r; } que[i] = qu; } unordered_set<int> time_in_query_set; for (auto &[_, l, r]: xlr) { time_in_query_set.insert(l); time_in_query_set.insert(r + 1); } for (auto &qu: que) { if (qu.type == 3) { time_in_query_set.insert(qu.l); time_in_query_set.insert(qu.r + 1); } } vector<int> time_in_query_vector; for (auto &x: time_in_query_set) time_in_query_vector.push_back(x); sort(time_in_query_vector.begin(), time_in_query_vector.end()); int time_index_num = time_in_query_vector.size(); unordered_map<int, int> time_index; for (int i = 0; i < time_index_num; i++) time_index[time_in_query_vector[i]] = i; // for query #2 prop_segtree<int> room_people_count(time_index_num); for (auto &[_, l, r]: xlr) { int l_idx = time_index[l]; int r_idx = time_index[r + 1]; room_people_count.update(l_idx, r_idx, 1); } // for query #1 unordered_map<string, set<Pii>> people_room_info; for (auto &[x, l, r]: xlr) { people_room_info[x].emplace(l, r); } vector<string> ans; for (auto &qu: que) { if (qu.type == 1) { auto it = people_room_info[qu.x].lower_bound(make_pair(qu.t, 2e9)); if (it == people_room_info[qu.x].begin()) { ans.push_back("No"); } else { it--; int r = it->second; if (qu.t <= r) ans.push_back("Yes"); else ans.push_back("No"); } } else if (qu.type == 2) { int t_idx = distance(time_in_query_vector.begin(), upper_bound(time_in_query_vector.begin(), time_in_query_vector.end(), qu.t)) - 1; if (t_idx < 0) ans.push_back("0"); else ans.push_back(to_string(room_people_count.query(t_idx))); } else if (qu.type == 3) { int l_idx = time_index[qu.l]; int r_idx = time_index[qu.r + 1]; room_people_count.update(l_idx, r_idx, 1); people_room_info[qu.x].emplace(qu.l, qu.r); } } for (auto &x: ans) cout << x << endl; return 0; }