| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1107139 | serifefedartar | 3단 점프 (JOI19_jumps) | C++17 | 285 ms | 14596 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
#define f first
#define s second
#define LOGN 21
const ll MOD = 998244353;
const ll MAXN = 5e5 + 100;
const ll SQRT = 700;
#define int long long
vector<array<int,3>> queries;
vector<int> A;
int ans[MAXN];
multiset<pair<int,int>> st;
void add(int x) {
st.insert({A[x], x});
}
void omit(int x) {
st.erase(st.find({A[x], x}));
}
signed main() {
fast;
int N, Q;
cin >> N;
vector<vector<int>> msk;
for (int mask = 0; mask < 1e6; mask++) {
vector<int> Q;
for (int bit = 0; bit < 25; bit++) {
if ((1<<bit) & mask)
Q.push_back(bit);
}
if (Q.size() == 3)
msk.push_back(Q);
}
A = vector<int>(N+1);
for (int i = 1; i <= N; i++)
cin >> A[i];
cin >> Q;
for (int i = 1; i <= Q; i++) {
int l, r;
cin >> l >> r;
queries.push_back({l, r, i});
}
sort(queries.begin(), queries.end(), [&](array<int,3> A, array<int,3> B) {
return make_pair(A[0] / SQRT, A[1]) < make_pair(B[0] / SQRT, B[1]);
});
int l = 1, r = 1;
st.insert({A[1], 1});
for (auto u : queries) {
array<int,3> Q = u;
while (Q[1] > r) {
r++;
add(r);
}
while (Q[0] < l) {
l--;
add(l);
}
while (Q[1] < r) {
omit(r);
r--;
}
while (Q[0] > l) {
omit(l);
l++;
}
vector<pair<int,int>> v;
int x = 0;
while (st.size() && x < 20) {
x++;
v.push_back(*prev(st.end()));
st.erase(prev(st.end()));
}
sort(v.begin(), v.end(), [&](pair<int,int> A, pair<int,int> B) {
return A.s < B.s;
});
int res = 0;
for (auto u : msk) {
if (u[1] - u[0] > u[2] - u[1] || u[2] >= v.size())
continue;
int now = 0;
for (auto q : u)
now += v[q].f;
res = max(res, now);
}
for (auto u : v)
st.insert(u);
ans[Q[2]] = res;
}
for (int i = 1; i <= Q; i++)
cout << ans[i] << "\n";
}컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
