結果

問題 No.2421 entersys?
ユーザー takumi152takumi152
提出日時 2023-08-12 14:54:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 973 ms / 3,000 ms
コード長 4,596 bytes
コンパイル時間 2,064 ms
コンパイル使用メモリ 151,364 KB
実行使用メモリ 72,932 KB
最終ジャッジ日時 2024-04-30 07:29:57
合計ジャッジ時間 16,831 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 4 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 4 ms
6,940 KB
testcase_06 AC 4 ms
6,940 KB
testcase_07 AC 4 ms
6,940 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 AC 6 ms
6,940 KB
testcase_10 AC 4 ms
6,940 KB
testcase_11 AC 670 ms
54,660 KB
testcase_12 AC 675 ms
55,812 KB
testcase_13 AC 682 ms
54,836 KB
testcase_14 AC 673 ms
55,916 KB
testcase_15 AC 665 ms
55,316 KB
testcase_16 AC 707 ms
57,864 KB
testcase_17 AC 689 ms
58,128 KB
testcase_18 AC 692 ms
58,088 KB
testcase_19 AC 689 ms
57,800 KB
testcase_20 AC 690 ms
58,492 KB
testcase_21 AC 580 ms
51,244 KB
testcase_22 AC 573 ms
50,400 KB
testcase_23 AC 937 ms
72,416 KB
testcase_24 AC 958 ms
72,416 KB
testcase_25 AC 973 ms
72,932 KB
testcase_26 AC 475 ms
44,416 KB
testcase_27 AC 473 ms
44,416 KB
testcase_28 AC 466 ms
46,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0