이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
struct sparse {
using T = int;
int n, h;
vector<vector<T>> table;
T func(T x, T y) {
return max(x, y);
}
sparse(const vector<T> &v) {
n = (int) v.size();
h = 32 - __builtin_clz(n);
table.resize(h);
table[0] = v;
for (int j = 1; j < h; j++) {
table[j].resize(n - (1 << j) + 1);
for (int i = 0; i <= n - (1 << j); i++) {
table[j][i] = func(table[j - 1][i], table[j - 1][i + (1 << (j - 1))]);
}
}
}
T get(int from, int to) { // [from, to]
int k = 32 - __builtin_clz(to - from + 1) - 1;
return func(table[k][from], table[k][to - (1 << k) + 1]);
}
};
int GetBestPosition(int n, int c, int r, int k[], int beg[], int end[]) {
pbds st;
for (int i = 0; i <= n; i++) {
st.insert(i);
}
for (int i = 0; i < c; i++) {
beg[i] = *st.find_by_order(beg[i]);
end[i] = *st.find_by_order(end[i] + 1);
auto it = st.upper_bound(beg[i]);
while ((*it) < end[i]) {
st.erase(it);
it = st.upper_bound(beg[i]);
}
}
vector<int> a(n - 1);
for (int i = 0; i < n - 1; i++) {
a[i] = k[i];
}
sparse sp(a);
a = vector<int>(n + 1);
for (int i = 0; i < c; i++) {
if (sp.get(beg[i], end[i] - 2) < r) {
a[beg[i]]++;
a[end[i]]--;
}
}
for (int i = 0; i < n; i++) {
a[i + 1] += a[i];
}
return *max_element(a.begin(), a.end());
}
#ifdef tabr
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, c, r, k[100], beg[100], end[100];
cin >> n >> c >> r;
for (int i = 0; i < n - 1; i++) {
cin >> k[i];
}
for (int i = 0; i < c; i++) {
cin >> beg[i] >> end[i];
}
cout << GetBestPosition(n, c, r, k, beg, end) << '\n';
return 0;
}
#endif
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |