QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#797572 | #8951. 澡堂 | hhoppitree | 0 | 5ms | 4004kb | C++14 | 2.2kb | 2024-12-03 13:45:11 | 2024-12-03 13:45:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
struct op {
vector<long long> p;
void append(long long x) {
p.push_back(x);
}
void Init() {
}
long long query(int l, int r, long long &x, int D) {
if (l > r) return 0;
pair<long long, long long> res = {0, x};
for (int i = l; i <= r; ++i) {
res.second = min(res.second, p[i] + D);
res.first += res.second;
}
x = res.second;
return res.first;
}
} o[5];
long long query(int p, int q, int L, int R, long long &x, int D) {
int l = (L - q) / p * p - 1, r = (R - q) / p * p + 1;
while (l * p + q < L) ++l;
while (r * p + q > R) --r;
return o[q].query(l, r, x, D);
}
int a[N];
signed main() {
int n, m, q, T; scanf("%d%d%d%d", &n, &m, &q, &T);
long long S = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
o[i % m].append(1ll * (i / m) * T - a[i]);
S += 1ll * (i / m) * T - a[i];
}
for (int i = 0; i < m; ++i) {
o[i].Init();
}
while (q--) {
int x, y; scanf("%d%d", &x, &y), --x;
long long res = S + a[x] - y;
int t = lower_bound(a, a + n, y) - a;
if (t <= x) {
for (int i = 0; i < m; ++i) {
long long now = 1e18;
res -= query(m, i, 0, t - 1, now, 0);
if (t % m == i) {
now = min(now, 1ll * (t / m) * T - y);
res -= now;
}
res -= query(m, (i - 1 + m) % m, t, x - 1, now, (i % m == 0 ? T : 0));
res -= query(m, i, x + 1, n - 1, now, 0);
}
} else {
for (int i = 0; i < m; ++i) {
long long now = 1e18;
res -= query(m, i, 0, x - 1, now, 0);
res -= query(m, (i + 1) % m, x + 1, t - 1, now, (i % m == m - 1 ? -T : 0));
if ((t - 1) % m == i) {
now = min(now, 1ll * ((t - 1) / m) * T - y);
res -= now;
}
res -= query(m, i, t, n - 1, now, 0);
}
}
printf("%lld\n", res);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 5ms
memory: 4004kb
input:
1000 5 1000 1969617 59993 133807 154199 240894 438118 483699 540258 892751 922552 1049554 1092961 1153394 1287745 1315664 1372758 1550447 1634967 1817853 1825455 2023239 2064188 2117896 2250036 2453036 2492474 2794776 2917935 3047993 3153958 3163156 3237767 3443614 3664074 3716235 3801008 3822067 40...
output:
145376762527 145219862385 145228748610 145372214673 145340663403 145390880078 145237023916 145299631166 145355471020 145305510768 145332804555 145298776457 145224349541 145238707189 145329914775 145263387049 145353694869 145202217346 145238451574 145270159106 145411389627 145292873725 145292443896 1...
result:
wrong answer 1st lines differ - expected: '145473107761', found: '145376762527'
Subtask #2:
score: 0
Time Limit Exceeded
Test #6:
score: 0
Time Limit Exceeded
input:
1000000 1 100000 1165 83 197 266 277 299 529 538 601 629 760 792 1081 1208 1211 1387 1726 1873 1932 2198 2437 2448 2584 2715 2813 3113 3169 3207 3386 3934 4013 4032 4057 4137 4213 4396 4666 4754 4786 4856 4917 4966 5054 5124 5151 5196 5505 5548 5583 5730 5763 6031 6161 6169 6372 6446 6517 6712 6744 ...
output:
532526465394304 532526382684731 532526432382169 532526335149396 532526336776485 532526441654485 532526419072018 532526448365904 532526461590885 532526446716107 532526451559614 532526448428416 532526467783803 532526436578785 532526455446447 532526418608776 532526437618228 532526421765463 532526361938...
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Time Limit Exceeded
Test #36:
score: 0
Time Limit Exceeded
input:
1000000 5 100000 1887 112 168 223 393 535 558 577 631 631 678 682 1043 1099 1268 1337 1396 1437 1472 1510 1587 1804 1984 2013 2290 2294 2392 2474 2547 2694 2717 2742 2841 2880 2906 2985 3030 3047 3064 3108 3275 3375 3440 3451 3488 3950 3957 3963 4047 4086 4335 4378 4448 4490 4544 4622 4864 4875 4897...
output:
138785002671312 138785020540848 138785114639541 138784846486989 138784967438577 138785010854691 138784922288405 138784882384258 138784946490329 138784907655978 138784872765269 138785022466898 138784999852184 138784972532501 138784954171119 138785035317313 138784852091651 138784904368989 138784986375...
result:
Subtask #6:
score: 0
Skipped
Dependency #3:
0%