QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#114470 | #4590. Happy Travelling | berarchegas | WA | 43ms | 20832kb | C++17 | 3.2kb | 2023-06-22 07:18:28 | 2023-06-22 07:18:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const ll INF = 2e18;
ll a[4*MAXN], lz1[4*MAXN], lz2[4*MAXN], a1[4*MAXN], a2[4*MAXN];
void build(int node, int i, int j) {
if (i == j) a[node] = -INF;
else {
int m = (i+j)/2;
build(2*node, i, m), build(2*node+1, m+1, j);
a[node] = max(a[2*node], a[2*node+1]);
}
}
void push(int node, int i, int j) {
if (a1[node]) {
a[node] = lz1[node];
if (i != j) {
lz1[2*node] = lz1[2*node+1] = lz1[node];
a1[2*node] = a1[2*node+1] = 1;
lz2[2*node] = lz2[2*node+1] = a2[2*node] = a2[2*node+1] = 0;
}
lz2[node] = lz1[node] = a2[node] = a1[node] = 0;
}
if (a2[node]) {
a[node] += lz2[node];
if (i != j) {
if (a1[2*node]) {
lz1[2*node] += lz2[node];
lz2[2*node] = 0;
a2[2*node] = 0;
}
else {
lz2[2*node] += lz2[node];
a2[2*node] = 1;
}
if (a1[2*node+1]) {
lz1[2*node+1] += lz2[node];
lz2[2*node+1] = 0;
a2[2*node+1] = 0;
}
else {
lz2[2*node+1] += lz2[node];
a2[2*node+1] = 1;
}
}
lz2[node] = 0;
a2[node] = 0;
}
}
ll query(int node, int i, int j, int ini, int fim) {
push(node, i, j);
if (j < ini || i > fim) return -INF;
if (ini <= i && j <= fim) return a[node];
else {
int m = (i+j)/2;
return max(query(2*node, i, m, ini, fim), query(2*node+1, m+1, j, ini, fim));
}
}
void update(int node, int i, int j, int ini, int fim, ll val, bool set) {
push(node, i, j);
if (j < ini || i > fim) return;
if (ini <= i && j <= fim) {
if (set) {
lz1[node] = val;
a1[node] = true;
}
else {
if (a1[node]) lz1[node] += val;
else {
lz2[node] += val;
a2[node] = true;
}
}
push(node, i, j);
}
else {
int m = (i+j)/2;
update(2*node, i, m, ini, fim, val ,set);
update(2*node+1, m+1, j, ini, fim, val, set);
a[node] = max(a[2*node], a[2*node+1]);
}
}
ll n, k, d, h[MAXN], t[MAXN], id[MAXN], dp[MAXN];
vector<int> del[MAXN];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k >> d;
for (int i = 0; i < n; i++) {
cin >> h[i];
}
for (int i = 0; i < n - 1; i++) {
cin >> t[i];
}
build(1, 0, n - 1);
int at = 0;
for (int i = 0; i < k; i++) {
int x = i;
while (x < n) {
id[x] = at++;
x += k;
}
}
dp[0] = h[0];
update(1, 0, n - 1, id[0], id[0], dp[0], true);
del[0 + t[0]].push_back(0);
for (int i = 1; i < n; i++) {
// update the dudes
if (i >= k)
update(1, 0, n - 1, id[i % k], id[i] - 1, -d, false);
// calc dp[i]
dp[i] = h[i] + query(1, 0, n - 1, 0, n - 1);
// update seg
update(1, 0, n - 1, id[i], id[i], dp[i], true);
// delete elements
for (int x : del[i]) {
update(1, 0, n - 1, id[x], id[x], -INF, true);
}
}
cout << dp[n - 1] << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 15696kb
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: 2ms
memory: 16756kb
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: 4ms
memory: 16988kb
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: 4ms
memory: 15400kb
input:
2 1 0 -10000 10000 1
output:
0
result:
ok single line: '0'
Test #5:
score: -100
Wrong Answer
time: 43ms
memory: 20832kb
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:
-79111
result:
wrong answer 1st lines differ - expected: '-84108', found: '-79111'