結果
問題 | No.2220 Range Insert & Point Mex |
ユーザー |
![]() |
提出日時 | 2023-01-31 04:23:41 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,403 bytes |
コンパイル時間 | 2,682 ms |
コンパイル使用メモリ | 227,624 KB |
実行使用メモリ | 21,512 KB |
最終ジャッジ日時 | 2024-07-21 12:38:21 |
合計ジャッジ時間 | 22,178 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 368 ms
12,120 KB |
testcase_14 | AC | 368 ms
11,912 KB |
testcase_15 | AC | 369 ms
12,096 KB |
testcase_16 | AC | 369 ms
12,040 KB |
testcase_17 | AC | 368 ms
11,988 KB |
testcase_18 | AC | 369 ms
12,084 KB |
testcase_19 | AC | 369 ms
12,020 KB |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | AC | 964 ms
20,996 KB |
testcase_24 | AC | 889 ms
18,648 KB |
testcase_25 | AC | 502 ms
14,000 KB |
testcase_26 | AC | 915 ms
21,228 KB |
testcase_27 | AC | 742 ms
16,252 KB |
testcase_28 | AC | 33 ms
8,332 KB |
testcase_29 | AC | 36 ms
8,332 KB |
testcase_30 | AC | 36 ms
8,328 KB |
testcase_31 | AC | 220 ms
12,192 KB |
testcase_32 | AC | 187 ms
9,872 KB |
testcase_33 | AC | 188 ms
10,004 KB |
testcase_34 | AC | 841 ms
15,248 KB |
testcase_35 | AC | 800 ms
15,244 KB |
testcase_36 | AC | 805 ms
14,836 KB |
testcase_37 | AC | 783 ms
14,720 KB |
testcase_38 | AC | 674 ms
17,032 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"; } }