QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#870069 | #9686. 士兵 | hhoppitree | 0 | 0ms | 0kb | C++17 | 3.0kb | 2025-01-25 14:40:53 | 2025-01-25 14:40:58 |
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const long long INF = 1e18;
int n, m;
int a[N], b[N];
long long mx[N * 4], lz[N * 4], rm[N * 4];
vector<int> lsh;
void build(int k, int l, int r) {
mx[k] = -INF;
lz[k] = 0;
rm[k] = lsh[r - 1];
if (l == r) return;
int mid = (l + r) / 2;
build(k * 2, l, mid);
build(k * 2 + 1, mid + 1, r);
}
void pushdown(int k) {
if (lz[k]) {
mx[k * 2] += lz[k];
mx[k * 2 + 1] += lz[k];
lz[k * 2] += lz[k];
lz[k * 2 + 1] += lz[k];
lz[k] = 0;
}
}
long long query1(int k, int l, int r, int x, int y, long long cur = -INF) {
if (x > r || y < l || mx[k] - 2LL * (y - rm[k]) * m <= cur) return -INF;
if (l == r) return mx[k] - 1LL * (y - rm[k]) * m;
pushdown(k);
int mid = (l + r) / 2;
cur = max(cur, query1(k * 2, l, mid, x, y, cur));
cur = max(cur, query1(k * 2 + 1, mid + 1, r, x, y, cur));
return cur;
}
long long query2(int k, int l, int r, int x) {
if (l > x) return -INF;
if (r <= x) return mx[k];
pushdown(k);
int mid = (l + r) / 2;
return max(query2(k * 2, l, mid, x), query2(k * 2 + 1, mid + 1, r, x));
}
void modify(int k, int l, int r, int x, long long y) {
if (l == r) {
mx[k] = max(mx[k], y);
return;
}
pushdown(k);
int mid = (l + r) / 2;
if (x <= mid) modify(k * 2, l, mid, x, y);
else modify(k * 2 + 1, mid + 1, r, x, y);
mx[k] = max(mx[k * 2], mx[k * 2 + 1]);
}
void add(int k, int l, int r, int x, int y) {
if (r < x) return;
if (l >= x) {
mx[k] += y;
lz[k] += y;
return;
}
pushdown(k);
int mid = (l + r) / 2;
add(k * 2, l, mid, x, y);
add(k * 2 + 1, mid + 1, r, x, y);
mx[k] = max(mx[k * 2], mx[k * 2 + 1]);
}
int getId(int x) {
return lower_bound(lsh.begin(), lsh.end(), x) - lsh.begin() + 1;
}
int main() {
freopen("soldier.in", "r", stdin);
freopen("soldier.out", "w", stdout);
int T;
scanf("%d", &T);
while (T--) {
scanf("%d %d", &n, &m);
lsh.clear();
for (int i = 1; i <= n; ++i) {
scanf("%d %d", &a[i], &b[i]);
if (b[i] > 0) lsh.push_back(a[i]);
else lsh.push_back(a[i] + 1);
}
sort(lsh.begin(), lsh.end());
lsh.erase(unique(lsh.begin(), lsh.end()), lsh.end());
build(1, 1, lsh.size());
modify(1, 1, lsh.size(), getId(0), 0);
for (int i = 1; i <= n; ++i) {
if (b[i] > 0) {
modify(1, 1, lsh.size(), getId(a[i]), query1(1, 1, lsh.size(), getId(a[i]), a[i]));
} else {
modify(1, 1, lsh.size(), getId(a[i] + 1), query2(1, 1, lsh.size(), getId(a[i]) - 1));
}
add(1, 1, lsh.size(), getId(a[i]), b[i]);
}
printf("%lld\n", mx[1]);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Dangerous Syscalls
Test #1:
score: 0
Dangerous Syscalls
input:
12 400000 215331 32634593 161413124 11430130 630188586 215159059 12789246 181156889 228549524 981499941 223418810 352275618 169560913 44477842 463549487 811410089 903359412 824711516 611158435 295107834 85539182 327533322 109743342 641057838 88328676 920713758 477897249 720713041 347272545 372388659...
output:
result:
Subtask #2:
score: 0
Dangerous Syscalls
Test #6:
score: 0
Dangerous Syscalls
input:
6 4000 55 438 -1672 4920 -694 9 -4515 2892 4721 4948 4935 3944 677 2915 -652 890 893 3761 1477 143 4944 3967 -2370 2829 67 2370 1345 3892 3370 4708 -3461 834 4318 2277 -4390 192 -209 3080 2003 3538 3350 1067 -4779 1317 1962 3221 -4535 3009 -3801 4407 1446 2697 4623 2842 3270 1694 2843 1428 -4000 657...
output:
result:
Subtask #3:
score: 0
Dangerous Syscalls
Test #11:
score: 0
Dangerous Syscalls
input:
6 4000 40 845657770 -724310339 314790762 -566202228 187061691 -849927809 881904926 159041058 958604341 -584625938 732309461 -496364578 102825909 -280420619 984389141 -643824457 464469583 398420805 531965757 -421979933 986707233 -101542333 589119003 427359050 856508269 493450680 276095634 -802021302 ...
output:
result:
Subtask #4:
score: 0
Dangerous Syscalls
Test #16:
score: 0
Dangerous Syscalls
input:
10 80000 278 989724232 684111881 387651979 995302974 935116319 -763307536 357312084 -992764231 691346506 179082856 673738821 -447838734 715542279 963718765 152553078 -96440380 619692385 18180027 538482960 873901814 622934033 -173705491 873338483 177298769 503597801 185822983 282786465 165743421 7701...
output:
result:
Subtask #5:
score: 0
Dangerous Syscalls
Test #21:
score: 0
Dangerous Syscalls
input:
11 160000 250 466377051 -617201470 709746153 18809363 499278797 -710523377 15106343 357127850 957417981 815655483 548989540 857011432 342064971 -461130568 679069515 592000112 590334260 324962484 551405428 -659075943 157123277 -193688122 387315357 512108123 852827874 -346582430 412123423 -656604422 3...
output:
result:
Subtask #6:
score: 0
Dangerous Syscalls
Test #26:
score: 0
Dangerous Syscalls
input:
12 400000 317 193208489 -270750940 582242598 -29443406 314213399 -242002909 311093779 -328422545 632402493 213048254 811395226 940669675 898004477 320489888 768923060 772646467 409062473 740531861 746345655 -160152674 198610379 579865887 656915491 833962170 146211597 496968125 263883352 836697145 28...