mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-03 19:16:27 +00:00
P4269 [USACO18FEB]Snow Boots G
https://www.luogu.com.cn/record/86653460
This commit is contained in:
parent
9896659358
commit
226513485c
86
Luogu/P4269/P4269.cpp
Normal file
86
Luogu/P4269/P4269.cpp
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <deque>
|
||||||
|
#include <functional>
|
||||||
|
#include <tuple>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using std::cin;
|
||||||
|
using std::cout;
|
||||||
|
const char endl = '\n';
|
||||||
|
|
||||||
|
int n, b;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
|
cin >> n >> b;
|
||||||
|
|
||||||
|
std::vector<int> a(n), d(n);
|
||||||
|
|
||||||
|
for (int &x : a) cin >> x;
|
||||||
|
|
||||||
|
std::vector<std::pair<int, int>> shoes;
|
||||||
|
|
||||||
|
for (int i = 0, s; i < b; i++) {
|
||||||
|
cin >> s >> d[i];
|
||||||
|
|
||||||
|
shoes.emplace_back(i, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<int> ans(n);
|
||||||
|
|
||||||
|
auto solve = [&](int ql, int qr, int l, int r, auto &&solve) -> void {
|
||||||
|
if (ql > qr || l > r) return;
|
||||||
|
|
||||||
|
if (l == r) {
|
||||||
|
for (int i = ql; i <= qr; i++) {
|
||||||
|
ans[shoes[i].first] = l;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int mid = l + r >> 1;
|
||||||
|
std::deque<int> q{0};
|
||||||
|
std::vector<int> f(n);
|
||||||
|
|
||||||
|
for (int i = 1; i < n; i++) {
|
||||||
|
while (!q.empty() && i - q.front() > mid) q.pop_front();
|
||||||
|
f[i] = std::max(a[i], f[q.front()]);
|
||||||
|
while (!q.empty() && f[i] <= f[q.back()]) q.pop_back();
|
||||||
|
q.push_back(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shoes[ql].second < *f.rbegin()) {
|
||||||
|
solve(ql, qr, mid + 1, r, solve);
|
||||||
|
} else if (shoes[qr].second >= *f.rbegin()) {
|
||||||
|
solve(ql, qr, l, mid, solve);
|
||||||
|
} else {
|
||||||
|
int pos = std::lower_bound(
|
||||||
|
shoes.begin() + ql,
|
||||||
|
shoes.begin() + qr + 1,
|
||||||
|
std::make_pair(0, *f.rbegin()),
|
||||||
|
[](auto &&lhs, auto &&rhs) -> bool {
|
||||||
|
return lhs.second >= rhs.second;
|
||||||
|
})
|
||||||
|
- shoes.begin();
|
||||||
|
|
||||||
|
solve(ql, pos - 1, l, mid, solve);
|
||||||
|
solve(pos, qr, mid + 1, r, solve);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::sort(shoes.begin(), shoes.end(), [](auto &&lhs, auto &&rhs) -> bool {
|
||||||
|
return lhs.second > rhs.second;
|
||||||
|
});
|
||||||
|
|
||||||
|
solve(0, b - 1, 1, n, solve);
|
||||||
|
|
||||||
|
for (int i = 0; i < b; i++) {
|
||||||
|
cout << (ans[i] <= d[i]) << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
BIN
Luogu/P4269/data/P4269_1.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_1.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_10.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_10.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_11.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_11.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_11.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_12.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_12.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_12.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_2.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_2.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_3.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_3.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_4.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_4.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_5.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_5.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_6.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_6.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_7.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_7.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_8.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_8.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_9.in
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Luogu/P4269/data/P4269_9.out
(Stored with Git LFS)
Normal file
BIN
Luogu/P4269/data/P4269_9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user