QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#250236 | #4590. Happy Travelling | warner1129 | TL | 93ms | 18148kb | C++20 | 2.9kb | 2023-11-12 23:37:52 | 2023-11-12 23:37:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
template<class... T> void dbg(T... x) { char e{}; ((cerr << e << x, e = ' '), ...); }
template<class T> void org(T l, T r) { while (l != r) cerr << ' ' << *l++; cerr << '\n'; }
#define debug(x...) dbg(#x, '=', x, '\n')
#define olist(x...) dbg(#x, '='), org(x)
#else
#define debug(...) ((void)0)
#define olist(...) ((void)0)
#endif
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define ff first
#define ss second
using i64 = long long;
using u64 = unsigned long long;
using i128 = __int128;
using u128 = unsigned __int128;
template<class T>
inline constexpr T inf = numeric_limits<T>::max() / 2;
constexpr int mod = 998244353;
template<class T> bool chmin(T &a, T b) { return (b < a and (a = b, true)); }
template<class T> bool chmax(T &a, T b) { return (a < b and (a = b, true)); }
template<class... T> int add(T... x) { int t{}; return (((t += x) %= mod), ...), t; }
template<class... T> int mul(T... x) { i64 t{1}; return (((t *= x) %= mod), ...), t; }
void solve() {
int n, K, D;
cin >> n >> K >> D;
vector<int> H(n);
vector<int> T(n - 1);
for (int &x : H) cin >> x;
for (int &x : T) cin >> x;
if (K * K <= 1e5) {
vector<vector<int>> stk(K);
vector<i64> dp(n, -inf<i64>);
dp[n - 1] = H[n - 1];
stk[(n - 1) % K].push_back(n - 1);
for (int i = n - 2; i >= 0; i--) {
for (int j = 0; j < K; j++) {
auto it = lower_bound(all(stk[j]), i + T[i], greater<int>{});
if (it != stk[j].end()) {
chmax(dp[i], dp[*it] - (*it - i) / K * D + H[i]);
}
}
int s = i % K;
while (!stk[s].empty() and dp[stk[s].back()] - stk[s].back() / K * D < dp[i] - i / K * D) {
stk[s].pop_back();
}
stk[s].push_back(i);
}
cout << dp[0] << '\n';
} else {
const int lgK = __lg(K);
vector st(lgK + 1, vector<i64>(n, -inf<i64>));
vector<i64> dp(n, -inf<i64>);
dp[n - 1] = H[n - 1];
auto upd = [&](int idx) -> void {
st[0][idx] = dp[idx];
for (int i = 0; i + 1 <= lgK and idx + (2 << i) <= n; i++) {
st[i + 1][idx] = max(st[i][idx], st[i][idx + (1 << i)]);
}
};
auto qry = [&](int l, int r) -> i64 {
int s = __lg(r - l);
return max(st[s][l], st[s][r - (1 << s)]);
};
upd(n - 1);
for (int i = n - 2; i >= 0; i--) {
for (int j = i; j <= i + T[i]; j += K) {
chmax(dp[i], qry(max(j, i + 1), min(j + K, i + T[i] + 1)) - (j - i) / K * D + H[i]);
}
upd(i);
}
cout << dp[0] << '\n';
}
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
cin.exceptions(cin.failbit);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3748kb
input:
6 2 1 8 -7 -8 9 0 2 5 3 3 2 1
output:
18
result:
ok single line: '18'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
8 8 8 10 -5 -5 -5 -5 -5 -5 10 5 2 5 3 2 1 1
output:
15
result:
ok single line: '15'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3792kb
input:
13 2 2 -5 -4 -4 -1 7 -6 -5 -4 -3 -2 -1 5 -7 3 10 9 8 7 6 5 4 3 2 1 1
output:
-9
result:
ok single line: '-9'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3740kb
input:
2 1 0 -10000 10000 1
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 14ms
memory: 4748kb
input:
98987 4 3 -8225 -8961 -5537 -5621 -8143 -5214 -5538 -6912 -6601 -8839 -7872 -7867 -9553 -9793 -7333 -7360 -5820 -7459 -8824 -9716 -9757 -5846 -5300 -5912 -7953 -8360 -7609 -5937 -5525 -9748 -7326 -8311 -9979 -9292 -8542 -7589 -7939 -5914 -7985 -9999 -9212 -8274 -8084 -6620 -5991 -7826 -6327 -5228 -6...
output:
-84108
result:
ok single line: '-84108'
Test #6:
score: 0
Accepted
time: 9ms
memory: 4748kb
input:
98467 2 3 -5677 -9080 -6665 -5838 -5755 -8938 -6286 -5160 -7147 -8370 -8214 -6088 -9763 -5183 -7123 -7264 -5298 -8855 -6381 -6592 -9216 -8429 -9598 -7443 -7393 -8712 -5545 -6778 -6010 -5717 -9102 -7968 -6140 -9592 -7917 -5217 -5015 -7798 -9339 -5678 -7073 -7607 -7961 -6185 -9941 -6421 -8779 -5388 -8...
output:
-150169
result:
ok single line: '-150169'
Test #7:
score: 0
Accepted
time: 12ms
memory: 4616kb
input:
96173 2 1 -6463 -9099 -6269 -6169 -8273 -9839 -9929 -5447 -5908 -6884 -6908 -8359 -6477 -9414 -9207 -8180 -6264 -9293 -8981 -6557 -9260 -9700 -6785 -7121 -8382 -9712 -5178 -5821 -9107 -9004 -7472 -9306 -9311 -7160 -7965 -5394 -8048 -7415 -5233 -7746 -7390 -5298 -7721 -7915 -9646 -5371 -5712 -6234 -5...
output:
-45780
result:
ok single line: '-45780'
Test #8:
score: 0
Accepted
time: 11ms
memory: 4604kb
input:
96905 1 1 -7933 -5685 -6201 -5415 -7294 -9904 -8968 -8433 -6287 -6727 -5933 -5418 -8953 -6743 -7057 -7087 -7244 -5302 -5130 -8934 -5053 -9811 -8695 -5989 -7785 -5991 -8351 -9463 -7037 -8867 -8956 -8194 -5272 -6270 -7737 -7793 -8851 -5839 -5178 -7009 -8018 -7375 -6091 -9226 -7117 -9522 -9248 -6036 -8...
output:
-72336
result:
ok single line: '-72336'
Test #9:
score: 0
Accepted
time: 13ms
memory: 4692kb
input:
97070 2 1 -6843 -9736 -7145 -9801 -6733 -7807 -8835 -5776 -6971 -7101 -8428 -7429 -9250 -9405 -6152 -7904 -5761 -8347 -6597 -8875 -8741 -7759 -8905 -9136 -8820 -9272 -9124 -6384 -7302 -5351 -8660 -5499 -9551 -9598 -9332 -7226 -5354 -9753 -7657 -5512 -7806 -5845 -5320 -9052 -8654 -9068 -5744 -7548 -7...
output:
-52581
result:
ok single line: '-52581'
Test #10:
score: 0
Accepted
time: 18ms
memory: 17268kb
input:
95643 95643 0 -5396 -7667 -7724 -8395 -5929 -5814 -6879 -7612 -6487 -5657 -6266 -7551 -8950 -6584 -5148 -7025 -7570 -6296 -6031 -7598 -5852 -5859 -7943 -6304 -6896 -5652 -9303 -5869 -9073 -6843 -7438 -6428 -8896 -5239 -7793 -6730 -7331 -7202 -8118 -9344 -8450 -8315 -8402 -8705 -5246 -9043 -7347 -872...
output:
-13774
result:
ok single line: '-13774'
Test #11:
score: 0
Accepted
time: 12ms
memory: 18148kb
input:
100000 99999 476 -109 -1014 -1404 -1837 -712 -1500 -1760 -751 184 -333 -860 -418 -1676 -1499 -1506 -456 -1692 -1473 -1872 -1523 -599 461 -583 -1685 -94 121 53 -385 192 -562 -1169 220 366 -746 -584 -1395 325 -502 98 -1773 -293 -72 -1894 -449 416 -1001 -1350 -1842 -1279 -528 323 -1196 32 -83 -1112 410...
output:
4735350
result:
ok single line: '4735350'
Test #12:
score: 0
Accepted
time: 40ms
memory: 4592kb
input:
93009 101 191 -278 -103 -706 -686 -521 -375 -330 -183 -381 -91 -686 -683 -89 -448 -724 -71 -374 -470 -214 -475 -505 -599 -108 -157 -199 -541 -509 -477 -62 -96 -415 -49 -524 -93 -230 -745 -561 -47 -451 -165 -763 -461 -357 -555 -757 -52 -246 -297 -145 -599 -36 -366 -157 -200 -38 -344 -105 -509 -54 -41...
output:
1532
result:
ok single line: '1532'
Test #13:
score: 0
Accepted
time: 93ms
memory: 4600kb
input:
97621 313 252 -459 -973 -853 -287 -579 -817 -629 -187 -509 -814 -628 -742 -369 -503 -519 -213 -393 -708 -776 -222 -147 -760 -558 -926 -439 -437 -729 -16 -932 -964 -508 -809 -434 -186 -440 -142 -828 -11 -521 -282 -718 -976 -832 -760 -574 -461 -432 -219 -182 -2 -27 -638 -598 -800 -907 -510 -127 -429 -...
output:
3749
result:
ok single line: '3749'
Test #14:
score: 0
Accepted
time: 66ms
memory: 4752kb
input:
95287 250 112 -46 -248 -159 -372 -271 -352 -296 -31 -3 -397 -32 -73 -276 -443 -246 -236 -265 -102 -435 -398 -211 -376 -78 -277 -272 -446 -54 -345 -89 -73 -286 -210 -79 -424 -171 -260 -45 -341 -257 -300 -301 -19 4 -52 -223 -280 1 -99 -88 -143 -433 -72 -46 -333 -189 -115 -147 -401 -73 -365 -398 -152 -...
output:
9254
result:
ok single line: '9254'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
7 7 10000 7 3 -1 -6 3 4 1 6 5 4 3 2 1
output:
18
result:
ok single line: '18'
Test #16:
score: 0
Accepted
time: 9ms
memory: 12532kb
input:
93094 1415 354 -362 -297 12 34 -37 -924 265 -34 -835 -884 -245 -323 -856 -1166 -386 -642 288 -92 -275 -446 -121 -1345 -126 -13 -1378 -442 -24 -479 171 256 -582 -223 -65 -1114 -614 -197 -862 -552 -908 -718 -489 -585 -1148 -356 322 276 -252 -1295 104 86 332 -918 -1407 -1393 -336 -413 -1186 -1348 -435 ...
output:
3296610
result:
ok single line: '3296610'
Test #17:
score: 0
Accepted
time: 11ms
memory: 12544kb
input:
93543 1224 505 370 58 -1403 -1253 184 -2011 -1632 -1565 -978 -1908 -923 270 96 -1851 -897 -1278 -780 -957 -1674 -68 390 -256 -335 -977 -470 -1412 364 -1737 -951 336 -1487 -1266 -1326 400 -1748 -134 -1626 -1400 -163 226 4 -1401 -346 -1168 -1094 391 -1285 -701 -1550 -1443 343 -580 -1836 -1717 306 -161...
output:
4722004
result:
ok single line: '4722004'
Test #18:
score: 0
Accepted
time: 15ms
memory: 16828kb
input:
97347 39394 566 481 -427 -858 -726 -1285 -1337 -1253 -1080 -1990 -773 -1921 -1616 -463 310 -1447 -106 -1377 -2061 -565 -1444 -1412 353 -973 -1891 231 -70 -962 40 -1746 -1315 -1653 -4 375 -1719 464 238 -1516 -1331 -1244 -144 -1660 -1814 -179 -2150 -374 -113 -1578 -146 -131 -1946 -558 -222 -1253 -1308...
output:
5535209
result:
ok single line: '5535209'
Test #19:
score: -100
Time Limit Exceeded
input:
90834 53418 728 -9217 -6814 2547 -12 -6989 -1516 7814 159 -7793 -5319 6381 -904 3222 3010 -8266 -3940 1083 1871 -7986 4337 5752 3998 -6748 9530 2165 798 7563 -8385 -6673 2314 -6850 -6010 -4575 -319 -3432 -6025 500 -8768 -9599 9413 6230 -6120 6854 8981 1721 9406 -3615 5754 -3131 -601 -9062 -7899 5998...