Running_a_way @ 2023-10-13 14:23:08
检查一下单调队列弹出队首的边界有没有写错,参考下列代码:
for (int i = l; i <= n; i++) {
while(q.size() && dp[q.back()] <= dp[i - l]) q.pop_back();
while(q.size() && (i - l) - q.front() > (r - l)) q.pop_front(); // AC
q.push_back(i - l);
dp[i] = dp[q.front()] + a[i];
if(i + r > n) ans = max(ans, dp[i]);
}
for (int i = l; i <= n; i++) {
while(q.size() && dp[q.back()] <= dp[i - l]) q.pop_back();
while(q.size() && (i - l) - q.front() > (r - l + 1)) q.pop_front(); // WA on HACK
q.push_back(i - l);
dp[i] = dp[q.front()] + a[i];
if(i + r > n) ans = max(ans, dp[i]);
}
不得不说 hack 真挺强的。
by GClock_519 @ 2023-10-13 18:01:33
tql %%%
by Running_a_way @ 2023-10-13 18:13:08
@lonely_cyx 啊?
我能撤回我的话吗 qwq
by Running_a_way @ 2023-10-13 18:14:15
我不应该说 hack 太强了,应该说数据太弱了是吧(