結果
問題 | No.2421 entersys? |
ユーザー |
|
提出日時 | 2023-08-12 14:54:59 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,130 ms / 3,000 ms |
コード長 | 4,596 bytes |
コンパイル時間 | 2,463 ms |
コンパイル使用メモリ | 143,568 KB |
最終ジャッジ日時 | 2025-02-16 05:28:03 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 28 |
ソースコード
#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 valuepropagate(p, a, b);if (r <= a || b <= l) return; // out of rangeif (l <= a && b <= r) { // fully covereddata[p] += v;propFlag[p] = true;propagate(p, a, b);}else {update(l, r, v, p*2+1, a, (a + b) / 2); // leftupdate(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 valuepropagate(p, a, b);if (b - a == 1) return data[p];// reached to bottomif (x < (a + b) / 2) return query(x, p*2+1, a, (a + b) / 2); // leftelse 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 #2prop_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 #1unordered_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;}