QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#719573 | #2179. Dungeon 3 | makrav | 0 | 1626ms | 5208kb | C++20 | 1.8kb | 2024-11-07 04:00:51 | 2024-11-07 04:00:52 |
Judging History
answer
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second
#define int ll
mt19937 rnd(time(NULL));
template<typename T>
void shuf(vector<T>& a) {
for (int i = 1; i < sz(a); i++) swap(a[i], a[rnd() % (i + 1)]);
}
void solve() {
int n, q; cin >> n >> q;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i =0; i < n; i++) cin >> b[i];
vector<int> pref(n + 1);
for (int i = 1; i <= n; i++) pref[i] = pref[i - 1] + a[i - 1];
vector<int> nxt(n + 1, -1);
stack<int> st;
for (int i = n - 1; i >= 0; i--) {
while (!st.empty() && b[st.top()] >= b[i]) st.pop();
nxt[i] = (st.empty() ? -1 : st.top());
st.push(i);
}
while (q--) {
int s, t, u; cin >> s >> t >> u;
s--; t--;
int cango = s, benz = 0, ans = 0;
for (int i = s; i <= t; i++) {
int vr1 = u - benz;
int vr2 = max(0ll, (nxt[i] == -1 ? pref[t] : pref[nxt[i]]) - pref[i] - benz);
if (vr1 < vr2) {
ans += b[i] * (u - benz);
benz = u;
if (i < t) benz -= a[i];
} else {
ans += b[i] * vr2;
benz += vr2;
if (i < t) benz -= a[i];
}
if (benz < 0) ans = -1e18;
}
cout << (ans < 0 ? -1 : ans) << '\n';
}
}
signed main() {
int tt = 1;
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
//cin >> tt;
#else
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
#endif
while (tt--) {
solve();
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 10ms
memory: 3724kb
input:
2968 3000 195694 114761 84601 149164 83572 166860 83871 71067 14931 22597 45549 26862 29127 9421 126511 19869 175633 47521 181323 38646 178807 186054 31799 173648 106553 94698 98918 149462 95647 145666 121002 178141 154888 183449 176438 194661 97265 28777 98620 113016 49316 125390 35010 31772 159928...
output:
673905195705 -1 708919975778 194523923061 504008311572 149979021015 796442141553 1878449468250 -1 84616478444 237463366745 280208315310 180579301247 765653874690 602790224906 -1 3653998038325 -1 1769195701471 1868960713566 1664139827362 815621644509 2498800982494 1549588548286 2101818046472 48904770...
result:
wrong answer 1st lines differ - expected: '646758143905', found: '673905195705'
Subtask #2:
score: 0
Wrong Answer
Test #21:
score: 0
Wrong Answer
time: 1626ms
memory: 5208kb
input:
49414 50000 1 2 3 4 17 22 23 24 29 30 35 42 47 48 55 57 63 65 67 68 72 74 78 94 99 105 106 107 113 115 115 115 121 122 123 124 128 132 133 139 148 154 160 160 166 167 169 172 172 176 180 185 185 186 191 192 201 202 206 208 213 214 229 230 233 239 240 244 251 252 255 258 263 267 269 270 273 273 274 2...
output:
229369844564916 691614079275875 212266669246001 436705472288236 47669369890454 152722978828959 162282046361926 12778413213092 203223846826276 824999272510334 824849184473983 825180130901292 200964638548422 301264027833166 44299118128900 532902622424837 681943283592450 315470569454273 148029744786175...
result:
wrong answer 1st lines differ - expected: '229351781114038', found: '229369844564916'
Subtask #3:
score: 0
Time Limit Exceeded
Test #36:
score: 0
Time Limit Exceeded
input:
200000 200000 28646 30154 5388 22119 32077 11843 22185 20457 4284 19797 14537 18426 21420 13034 28504 15056 17391 26651 4316 44669 34999 17336 14427 42183 25112 29907 16908 32904 23781 27635 44514 36024 12435 14555 40422 25692 43414 12346 3329 31641 29115 14449 12127 40639 1576 37164 13309 31976 113...
output:
7450981853127 27293062194659 110364549999546 7125556246842 116279620730 19109542894069 -1 2272372077636 68246604637944 23503319546799 811993199574 -1 525547926571 1654302033014 213109416873758 -1 1951754477279 60240802359572 2318612470778 6347007399747 427696556322 -1 42455737680576 155367200626716 ...
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
0%