ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#1029 | #211. 「CSP-S2019」划分 | FiraCode | 100 | 3178ms | 1031756kb | C++14 | 3.1kb | 2025-07-05 14:55:55 | 2025-07-05 14:55:57 |
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1 << 30;
int n, type;
ll a[40000010];
int ia[40000010];
struct node {
ll g;
int id;
} stk[40000010];
void print(__int128 x) {
if (x >= 10) print(x / 10);
putchar(x % 10 + '0');
}
ll read() {
ll x = 0;
char c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') x = x * 10ll + c - '0', c = getchar();
return x;
}
int main() {
scanf("%d%d", &n, &type);
if (type == 0) {
for (int i = 1; i <= n; ++i) a[i] = read();
for (int i = 1; i <= n; ++i) a[i] += a[i - 1];
int tt = 0;
stk[++tt] = {0, 0};
int la = 1;
for (int i = 1; i <= n; ++i) {
// cout << stk[la + 1].g + a[stk[la + 1].id] << ' ' << a[i] << endl;
la = min(la, tt);
while (la + 1 <= tt && stk[la + 1].g + a[stk[la + 1].id] <= a[i]) ++la;
int l = la;
ll g = (a[i] - a[stk[l].id]);
// cout << stk[l].id << ' ' << l << endl;
// cout << la << ' ' << g << ' ' << l << ' ' << a[i] << endl;
ia[i] = stk[l].id;
while (g + a[i] <= stk[tt].g + a[stk[tt].id]) --tt;
stk[++tt] = {g, i};
}
__int128 ans = 0;
int id = n;
while (id) {
// cout << id << ' ' << ia[id] << endl;
ans += (__int128)(a[id] - a[ia[id]]) * (a[id] - a[ia[id]]);
id = ia[id];
}
print(ans);
} else {
ll x = read(), y = read(), z = read(); a[1] = read(), a[2] = read(); ll m = read();
for (int i = 1; i <= m; ++i) ia[i] = read(), stk[i].g = read(), stk[i].id = read();
for (int i = 3; i <= n; ++i) a[i] = (a[i - 1] * x + a[i - 2] * y + z) % mod;
for (int i = 1; i <= m; ++i) {
int len = stk[i].id - stk[i].g + 1;
for (int j = ia[i - 1] + 1; j <= ia[i]; ++j) {
a[j] = (a[j] - a[j] / len * len) + stk[i].g;
}
}
for (int i = 1; i <= n; ++i) a[i] += a[i - 1];
int tt = 0;
stk[++tt] = {0, 0};
int la = 1;
for (int i = 1; i <= n; ++i) {
// cout << stk[la + 1].g + a[stk[la + 1].id] << ' ' << a[i] << endl;
la = min(la, tt);
while (la + 1 <= tt && stk[la + 1].g + a[stk[la + 1].id] <= a[i]) ++la;
int l = la;
ll g = (a[i] - a[stk[l].id]);
// cout << stk[l].id << ' ' << l << endl;
// cout << la << ' ' << g << ' ' << l << ' ' << a[i] << endl;
ia[i] = stk[l].id;
while (g + a[i] <= stk[tt].g + a[stk[tt].id]) --tt;
stk[++tt] = {g, i};
}
__int128 ans = 0;
int id = n;
while (id) {
// cout << id << ' ' << ia[id] << endl;
ans += (__int128)(a[id] - a[ia[id]]) * (a[id] - a[ia[id]]);
id = ia[id];
}
print(ans);
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 4
Accepted
time: 2ms
memory: 7424kb
input:
1 0 1
output:
1
result:
ok "1"
Test #2:
score: 4
Accepted
time: 1ms
memory: 7612kb
input:
10 0 5 1 2 1 1 1 1 1 2 3
output:
108
result:
ok "108"
Test #3:
score: 4
Accepted
time: 1ms
memory: 7468kb
input:
10 0 5 1 1 4 3 2 1 6 5 6
output:
254
result:
ok "254"
Test #4:
score: 4
Accepted
time: 1ms
memory: 7544kb
input:
50 0 488 19 20 6 7 8 9 10 11 171 172 173 174 64 64 64 64 64 64 64 64 64 64 64 64 218 219 220 221 222...
output:
4485725
result:
ok "4485725"
Test #5:
score: 4
Accepted
time: 0ms
memory: 7552kb
input:
50 0 657 83 80 81 86 60 84 85 63 64 61 335 13 14 6 7 6 7 6 7 6 7 6 17 17 17 17 17 135 136 130 131 10...
output:
3963358
result:
ok "3963358"
Test #6:
score: 4
Accepted
time: 0ms
memory: 7696kb
input:
50 0 538 3 4 3 4 3 4 3 128 89 90 131 72 79 76 71 84 81 82 73 76 83 74 83 82 71 72 71 74 81 8 3 2 13 ...
output:
3376710
result:
ok "3376710"
Test #7:
score: 4
Accepted
time: 0ms
memory: 7716kb
input:
400 0 3009 356 438 551 606 387 2073 2777 2778 824 404 394 554 248 545 261 262 548 253 561 403 415 27...
output:
3170248737
result:
ok "3170248737"
Test #8:
score: 4
Accepted
time: 1ms
memory: 7480kb
input:
400 0 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633...
output:
6979363199
result:
ok "6979363199"
Test #9:
score: 4
Accepted
time: 1ms
memory: 7716kb
input:
400 0 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444...
output:
3318244868
result:
ok "3318244868"
Test #10:
score: 4
Accepted
time: 0ms
memory: 7560kb
input:
5000 0 26416 26417 26418 26419 26420 26421 26422 26423 26424 26425 26426 26427 26428 26429 26430 264...
output:
33887118980393
result:
ok "33887118980393"
Test #11:
score: 4
Accepted
time: 0ms
memory: 7508kb
input:
5000 0 23207 23208 23209 23210 23211 23212 23213 23214 23215 23216 23217 23218 23219 23220 23221 232...
output:
33248894141865
result:
ok "33248894141865"
Test #12:
score: 4
Accepted
time: 0ms
memory: 7548kb
input:
5000 0 66757 66758 66759 66760 66761 66762 66763 66764 66765 66766 66767 66768 66769 66770 66771 667...
output:
37723392435267
result:
ok "37723392435267"
Test #13:
score: 4
Accepted
time: 1ms
memory: 7464kb
input:
5000 0 27900 27901 27902 27903 27904 27905 27906 27907 27908 27909 27910 27911 27912 27913 27914 279...
output:
32475835026360
result:
ok "32475835026360"
Test #14:
score: 4
Accepted
time: 1ms
memory: 7508kb
input:
5000 0 88538 88539 88540 88541 88542 88543 88544 88545 88546 88547 88548 88549 88550 88551 88552 885...
output:
46614887221321
result:
ok "46614887221321"
Test #15:
score: 4
Accepted
time: 0ms
memory: 7468kb
input:
5000 0 57597 57598 57599 57600 57601 57602 57603 57604 57605 57606 57607 57608 57609 57610 57611 576...
output:
42148252068110
result:
ok "42148252068110"
Test #16:
score: 4
Accepted
time: 0ms
memory: 7504kb
input:
5000 0 32091 32092 32093 32094 32095 32096 32097 32098 32099 32100 32101 32102 32103 32104 32105 321...
output:
36356787333837
result:
ok "36356787333837"
Test #17:
score: 4
Accepted
time: 20ms
memory: 19740kb
input:
500000 0 232520 232521 232522 232523 232524 232525 232526 232527 232528 232529 232530 232531 232532 ...
output:
3404048031740228391
result:
ok "3404048031740228391"
Test #18:
score: 4
Accepted
time: 13ms
memory: 19988kb
input:
500000 0 171097 171098 171099 171100 171101 171102 171103 171104 171105 171106 171107 171108 171109 ...
output:
3274086928325086647
result:
ok "3274086928325086647"
Test #19:
score: 4
Accepted
time: 16ms
memory: 21920kb
input:
500000 0 507482 507483 507484 507485 507486 507487 507488 507489 507490 507491 507492 507493 507494 ...
output:
3313623507696416665
result:
ok "3313623507696416665"
Test #20:
score: 4
Accepted
time: 15ms
memory: 19892kb
input:
500000 0 184967 184968 184969 184970 184971 184972 184973 184974 184975 184976 184977 184978 184979 ...
output:
3136834726987393666
result:
ok "3136834726987393666"
Test #21:
score: 4
Accepted
time: 16ms
memory: 21936kb
input:
500000 0 532977 532978 532979 532980 532981 532982 532983 532984 532985 532986 532987 532988 532989 ...
output:
3194381893489801230
result:
ok "3194381893489801230"
Test #22:
score: 4
Accepted
time: 16ms
memory: 19684kb
input:
500000 0 599257 599258 599259 599260 599261 599262 599263 599264 599265 599266 599267 599268 599269 ...
output:
3354933513897756362
result:
ok "3354933513897756362"
Test #23:
score: 4
Accepted
time: 1027ms
memory: 894452kb
input:
40000000 1 825772993 851948608 851948609 23077817 23077818 100000 10000000 446359966 479914397 10000...
output:
3794994452005049854674339
result:
ok "3794994452005049854674339"
Test #24:
score: 4
Accepted
time: 1019ms
memory: 957892kb
input:
40000000 1 843670282 1068932343 1068932344 12005507 12005508 100000 20000000 191508704 225063135 200...
output:
2875588265896779695426252
result:
ok "2875588265896779695426252"
Test #25:
score: 4
Accepted
time: 1027ms
memory: 1031756kb
input:
40000000 1 308437383 27106938 27106939 1520476 1520477 100000 30000000 7283395 40837826 30000152 202...
output:
2049762805232475409502206
result:
ok "2049762805232475409502206"