QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#424778 | #149. Peru | Huasushis | 0 | 53ms | 40628kb | C++17 | 2.1kb | 2024-05-29 17:04:37 | 2024-09-10 16:46:10 |
Judging History
answer
#include <bits/stdc++.h>
#ifndef test
#include "peru.h"
#endif
using namespace std;
using ll = long long;
#define N 2500010
#define mod 1000000007ll
ll f[N];
int* s;
struct deq {
int stk[2][N], top[2];
ll minn[2][N];
deq() {minn[0][0] = minn[1][0] = 1e18;}
bool empty() const {return !(top[0] + top[1]);}
int front() const {
assert(!empty());
if (top[0]) return stk[0][top[0]];
return stk[1][1];
}
int back() const {
assert(!empty());
if (top[1]) return stk[1][top[1]];
return stk[0][1];
}
void pb(int x, ll v) {
stk[1][++top[1]] = x;
minn[1][top[1]] = min(v, minn[1][top[1] - 1]);
}
void pf(int x, ll v) {
stk[0][++top[0]] = x;
minn[0][top[0]] = min(v, minn[0][top[0] - 1]);
}
ll getmin() const { return min(minn[0][top[0]], minn[1][top[1]]); }
void rebuild(int flg = 0) {
int siz = top[0] + top[1];
int mid = (siz + flg) / 2;
vector<int> tmp;
for (int i = top[0]; i; --i) tmp.emplace_back(stk[0][i]);
for (int i = 1; i <= top[1]; ++i) tmp.emplace_back(stk[1][i]);
top[0] = top[1] = 0;
for (int i = mid - 1; ~i; --i) {
if (empty()) pf(tmp[i], 1e18);
else pf(tmp[i], f[tmp[i]] + s[front()]);
}
for (int i = mid; i < siz; ++i) {
if (empty()) pb(tmp[i], 1e18);
else pb(tmp[i], f[back()] + s[tmp[i]]);
}
}
void pop_front() {
assert(!empty());
if (!top[0]) rebuild(1);
--top[0];
}
void pop_back() {
assert(!empty());
if (!top[1]) rebuild();
--top[1];
}
}q;
int solve(int n, int k, int* s) {
::s = s;
ll res = 0;
for (int i = 0; i < n; ++i) {
if (!q.empty() && q.front() <= i - k) q.pop_front();
while (!q.empty() && s[q.back()] <= s[i]) q.pop_back();
if (q.empty()) q.pb(i, 1e18);
else q.pb(i, f[q.back()] + s[i]);
f[i] = min(q.getmin(), (i >= k ? f[i - k] : 0) + s[q.front()]);
res = (res * 23 + f[i]) % mod;
}
return res;
}
#ifdef test
int main() {
int n = 8, k = 3;
int s[] = {3, 2, 9, 8, 7, 11, 3, 4};
cout << solve(n, k, s);
return 0;
}
#endif
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 14268kb
input:
2000 170 1054018657 1037445664 1011691297 1009972317 1006506677 1002579733 999792775 999477541 975467893 970302369 968173111 957735623 953086083 938540451 932313113 930563895 924682633 917831575 913506401 908739591 905368525 899452913 894354220 890127447 885923007 583391543 880642788 878397752 87822...
output:
654952042
result:
wrong answer 1st lines differ - expected: '559335223', found: '654952042'
Subtask #2:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 10ms
memory: 18076kb
input:
400000 1000 1999989721 1999987224 1999984551 1999977673 1999977545 1999976801 1999975837 1999972607 1999956301 1999952801 1999942489 1999940593 1999940337 1999936353 1999936273 1999926073 1999925513 1999922980 1999918301 1999912501 1999909301 1999906125 1999902913 1999895622 1999893617 1999885490 19...
output:
404561745
result:
wrong answer 1st lines differ - expected: '677928817', found: '404561745'
Subtask #3:
score: 0
Wrong Answer
Test #34:
score: 0
Wrong Answer
time: 53ms
memory: 40628kb
input:
2500000 2000 1073315871 1073250349 1072791751 1072104046 1072071097 1071841833 1071809381 1071710686 1071580105 1071482003 1071383725 1071154701 1070499431 1070335288 1070334157 1069943617 1069681476 1069584279 1069581771 1069322519 1069189353 1069125955 1068832186 1068797487 1068662939 1068565681 1...
output:
347103873
result:
wrong answer 1st lines differ - expected: '12623259', found: '347103873'