QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#132686 | #149. Peru | somethingnew# | Compile Error | / | / | C++20 | 4.2kb | 2023-07-31 02:22:50 | 2024-07-04 01:02:29 |
Judging History
你现在查看的是测评时间为 2024-07-04 01:02:29 的历史记录
- [2024-07-04 01:02:29]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2023-07-31 02:22:50]
- 提交
answer
// ↘ ⬇ ⬇ ⬇ ⬇ ⬇ ↙
// ➡ @roadfromroi ⬅
// ↗ ⬆ ⬆ ⬆ ⬆ ⬆ ↖
#include <iostream>
#include "vector"
#include "algorithm"
#include "numeric"
#include "climits"
#include "iomanip"
#include "bitset"
#include "cmath"
#include "map"
#include "deque"
#include "array"
#include "set"
#include "queue"
#include "peru.h"
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
struct stackmax {
vector<pair<int, int>> stk;
int getval() {
if (stk.empty())
return 0;
return stk.back().second;
}
void push(int x) {
if (stk.empty())
stk.push_back({x, x});
else
stk.push_back({x, max(x, stk.back().second)});
}
int pop() {
int vl = stk.back().first;
stk.pop_back();
return vl;
}
bool empty() {
return stk.empty();
}
};
struct queuemax {
stackmax a, b;
int getval() {
return max(a.getval(), b.getval());
}
void push(int x) {
b.push(x);
}
void pop() {
if (a.empty()) {
while (!b.empty())
a.push(b.pop());
}
a.pop();
}
};
struct stackmin {
vector<pair<ll, ll>> stk;
ll getval() {
if (stk.empty())
return 1e18;
return stk.back().second;
}
void push(ll x) {
if (stk.empty())
stk.push_back({x, x});
else
stk.push_back({x, min(x, stk.back().second)});
}
ll pop() {
ll vl = stk.back().first;
stk.pop_back();
return vl;
}
bool empty() {
return stk.empty();
}
};
struct queuemin {
stackmin a, b;
ll getval() {
return min(a.getval(), b.getval());
}
void push(ll x) {
b.push(x);
}
void pop() {
if (a.empty()) {
while (!b.empty())
a.push(b.pop());
}
a.pop();
}
bool empty() {
return a.empty() and b.empty();
}
};
int solve(int n, int k, int* v){
vector<ll> dp(n + 1);
dp[0] = 0;
queuemax qmx;
vector<int> nxtmr(n);
for (int i = 0; i < n; ++i) {
qmx.push(v[i]);
if (i >= k) {
nxtmr[i-k] = qmx.getval();
qmx.pop();
}
}
stackmin stk;
queuemin que;
queue<int> ind;
for (int i = n; i < n + k; ++i) {
nxtmr[i-k] = qmx.getval();
qmx.pop();
}
int glbbeb = 0;
vector<pair<int, pair<int, int>>> st1;
for (int i = 0; i < n; ++i) {
while (!st1.empty() and st1.back().first < v[i]) {
st1.pop_back();
stk.pop();
}
int bep = 0;
if (st1.empty()) {
bep = max(glbbeb, i - k + 1);
} else {
bep = st1.back().second.second + 1;
}
if (st1.empty()) {
while (nxtmr[bep] == v[i] and bep <= i) {
que.push(v[i] + dp[bep]);
ind.push(bep);
bep++;
}
glbbeb = bep;
}
while (!ind.empty() and ind.front() + k < i + 1) {
ind.pop();
que.pop();
}
if (bep <= i) {
st1.push_back({v[i], {bep, i}});
//cout << "I " << i << endl;
//for (auto t : st1)
// cout << t.first << ' ' << "{" << t.second.first << ' ' << t.second.second << "}\n";
//cout << i << ' ' << st1.back().second.first << '\n';
stk.push(v[i] + dp[st1.back().second.first]);
}
dp[i + 1] = min(que.getval(), stk.getval());
}
ll res = 0;
ll mod = 1e9 + 7;
ll tomlt = 1;
for (int i = n; i > 0; --i) {
res += dp[i] % mod * tomlt % mod;
tomlt = tomlt * 23 % mod;
}
//for (int i = 0; i < n; ++i) {
// cout << dp[i + 1] << ' ';
//}
//cout << endl;
return res % mod;
}
#ifdef __APPLE__
static int s[2500005];
static int n, k;
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> s[i];
}
int ans = solve(n, k, s);
cout << ans << "\n";
return 0;
}
#endif
Details
implementer.cpp: In function ‘int main()’: implementer.cpp:34:13: error: ‘fout’ was not declared in this scope; did you mean ‘out’? 34 | fprintf(fout, "%d\n", sol); | ^~~~ | out implementer.cpp: In function ‘char nextch()’: implementer.cpp:15:31: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 15 | if (pos == BUF_SIZE) fread(buf, BUF_SIZE, 1, fin), pos = 0; | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~