結果

問題 No.2421 entersys?
ユーザー eve__fuyuki
提出日時 2024-11-15 00:10:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 455 ms / 3,000 ms
コード長 2,023 bytes
コンパイル時間 2,527 ms
コンパイル使用メモリ 218,028 KB
最終ジャッジ日時 2025-02-25 04:14:08
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

void fast_io() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
}

#include <atcoder/fenwicktree>
using namespace atcoder;
int main() {
	fast_io();
	int n;
	cin >> n;
	vector<string> X(n);
	vector<int> L(n), R(n);
	vector<int> times;
	for (int i = 0; i < n; i++) {
		cin >> X[i] >> L[i] >> R[i];
		times.push_back(L[i]);
		times.push_back(R[i]);
	}
	int q;
	cin >> q;
	vector<int> com(q);
	vector<string> x(q);
	vector<int> t(q), l(q), r(q);
	for (int i = 0; i < q; i++) {
		cin >> com[i];
		if (com[i] == 1) {
			cin >> x[i] >> t[i];
			times.push_back(t[i]);
		} else if (com[i] == 2) {
			cin >> t[i];
			times.push_back(t[i]);
		} else {
			cin >> x[i] >> l[i] >> r[i];
			times.push_back(l[i]);
			times.push_back(r[i]);
		}
	}
	sort(times.begin(), times.end());
	times.erase(unique(times.begin(), times.end()), times.end());
	int m = times.size();
	fenwick_tree<int> fw(m + 1);
	map<string, set<pair<int, int>>> mp;
	for (int i = 0; i < n; i++) {
		L[i] = lower_bound(times.begin(), times.end(), L[i]) - times.begin();
		R[i] = lower_bound(times.begin(), times.end(), R[i]) - times.begin();
		fw.add(L[i], 1);
		fw.add(R[i] + 1, -1);
		mp[X[i]].insert({L[i], R[i]});
	}
	for (int i = 0; i < q; i++) {
		if (com[i] == 1) {
			t[i] =
				lower_bound(times.begin(), times.end(), t[i]) - times.begin();
			auto it = mp[x[i]].lower_bound({t[i] + 1, -1});
			if (it == mp[x[i]].begin()) {
				cout << "No\n";
			} else {
				it--;
				int l = it->first, r = it->second;
				if (l <= t[i] && t[i] <= r) {
					cout << "Yes\n";
				} else {
					cout << "No\n";
				}
			}
		} else if (com[i] == 2) {
			t[i] =
				lower_bound(times.begin(), times.end(), t[i]) - times.begin();
			cout << fw.sum(0, t[i] + 1) << "\n";
		} else {
			l[i] =
				lower_bound(times.begin(), times.end(), l[i]) - times.begin();
			r[i] =
				lower_bound(times.begin(), times.end(), r[i]) - times.begin();
			fw.add(l[i], 1);
			fw.add(r[i] + 1, -1);
			mp[x[i]].insert({l[i], r[i]});
		}
	}
}
0