結果
問題 | No.2220 Range Insert & Point Mex |
ユーザー | ぷら |
提出日時 | 2023-01-31 04:23:41 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,943 ms / 2,000 ms |
コード長 | 3,403 bytes |
コンパイル時間 | 2,609 ms |
コンパイル使用メモリ | 223,352 KB |
実行使用メモリ | 21,564 KB |
最終ジャッジ日時 | 2023-09-28 17:58:59 |
合計ジャッジ時間 | 22,458 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,380 KB |
testcase_07 | AC | 2 ms
4,376 KB |
testcase_08 | AC | 2 ms
4,380 KB |
testcase_09 | AC | 2 ms
4,380 KB |
testcase_10 | AC | 2 ms
4,376 KB |
testcase_11 | AC | 1 ms
4,376 KB |
testcase_12 | AC | 2 ms
4,376 KB |
testcase_13 | AC | 366 ms
12,004 KB |
testcase_14 | AC | 365 ms
11,820 KB |
testcase_15 | AC | 365 ms
11,972 KB |
testcase_16 | AC | 365 ms
11,752 KB |
testcase_17 | AC | 363 ms
11,928 KB |
testcase_18 | AC | 363 ms
11,868 KB |
testcase_19 | AC | 364 ms
12,024 KB |
testcase_20 | AC | 1,943 ms
21,268 KB |
testcase_21 | AC | 1,934 ms
21,308 KB |
testcase_22 | AC | 1,873 ms
21,564 KB |
testcase_23 | AC | 914 ms
20,732 KB |
testcase_24 | AC | 855 ms
18,676 KB |
testcase_25 | AC | 481 ms
13,668 KB |
testcase_26 | AC | 894 ms
21,112 KB |
testcase_27 | AC | 730 ms
15,840 KB |
testcase_28 | AC | 32 ms
8,112 KB |
testcase_29 | AC | 35 ms
7,940 KB |
testcase_30 | AC | 35 ms
8,052 KB |
testcase_31 | AC | 211 ms
12,008 KB |
testcase_32 | AC | 180 ms
9,792 KB |
testcase_33 | AC | 181 ms
9,752 KB |
testcase_34 | AC | 789 ms
14,872 KB |
testcase_35 | AC | 775 ms
14,936 KB |
testcase_36 | AC | 751 ms
14,468 KB |
testcase_37 | AC | 734 ms
14,624 KB |
testcase_38 | AC | 657 ms
16,760 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; template <typename T> struct BinaryIndexedTree { int N; vector<T>bit; BinaryIndexedTree(){} BinaryIndexedTree(int x) { N = x; bit.resize(x+1); } void add(int x,T y) { x++; while(x <= N) { bit[x] += y; x += x&-x; } } T sum(int x) { x++; T res = 0; while(x) { res += bit[x]; x -= x&-x; } return res; } inline T sum(int l, int r) {//[l,r) return sum(r-1)-sum(l-1); } inline T operator[](int k) { return sum(k)-sum(k-1); } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<int>L(N),R(N),a(N),cmp; for(int i = 0; i < N; i++) { cin >> L[i] >> R[i] >> a[i]; cmp.push_back(L[i]); cmp.push_back(R[i]+1); } int Q; cin >> Q; vector<int>x(Q); for(int i = 0; i < Q; i++) { cin >> x[i]; cmp.push_back(x[i]); } sort(cmp.begin(),cmp.end()); cmp.erase(unique(cmp.begin(),cmp.end()),cmp.end()); for(int i = 0; i < N; i++) { L[i] = lower_bound(cmp.begin(),cmp.end(),L[i])-cmp.begin(); R[i] = lower_bound(cmp.begin(),cmp.end(),R[i]+1)-cmp.begin(); } for(int i = 0; i < Q; i++) { x[i] = lower_bound(cmp.begin(),cmp.end(),x[i])-cmp.begin(); } vector<int>l(Q),r(Q,N+3); while(true) { bool flag = false; for(int i = 0; i < Q; i++) { if(l[i]+1 < r[i]) { flag = true; } } if(!flag) break; map<int,vector<pair<int,int>>>mp; for(int i = 0; i < N; i++) { mp[a[i]].push_back({L[i],R[i]}); } for(int i = 0; i < Q; i++) { if(l[i]+1 < r[i]) { int mid = (l[i]+r[i])/2; mp[mid].push_back({i,-1}); } } BinaryIndexedTree<int>bit(cmp.size()); for(auto i:mp) { auto j = i.second; vector<pair<int,int>>tmp; for(auto k:j) { if(k.second != -1) { tmp.push_back(k); } else { if(bit.sum(x[k.first]) == i.first) { l[k.first] = i.first; } else { r[k.first] = i.first; } } } sort(tmp.begin(),tmp.end()); vector<pair<int,int>>res; int mi = -1,mx = -1; for(int k = 0; k < tmp.size(); k++) { if(mx == -1) { mi = tmp[k].first; mx = tmp[k].second; } else if(mx <= tmp[k].first) { res.push_back({mi,mx}); mi = tmp[k].first; mx = tmp[k].second; } else { mx = max(mx,tmp[k].second); } } if(mi != -1) { res.push_back({mi,mx}); } for(int k = 0; k < res.size(); k++) { bit.add(res[k].first,1); bit.add(res[k].second,-1); } } } for(int i = 0; i < Q; i++) { cout << l[i] << "\n"; } }