QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#875352 | #2747. Meetings | Wansur# | 17 | 186ms | 196984kb | C++20 | 2.6kb | 2025-01-29 16:32:38 | 2025-01-29 16:32:38 |
Judging History
answer
#include "meetings.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 12;
ll sum[maxn];
ll a[maxn], pref[maxn];
int nxtl[maxn][21], nxtr[maxn][21];
int lg[maxn];
int n, m, k;
struct sparse {
int mx[20][maxn];
sparse() {
for(int i = 0; i <= n; i++) {
for(int k = 0; k < 20; k++) {
mx[k][i] = 0;
}
}
}
void build(vector<int> a) {
for(int i = 1; i <= n; i++) {
mx[0][i] = a[i - 1];
if(i > 1) lg[i] = lg[i / 2] + 1;
}
for(int k = 1; k < 20; k++) {
for(int i = 1; i + (1 << k) - 1 <= n; i++) {
mx[k][i] = max(mx[k - 1][i], mx[k - 1][i + (1 << (k - 1))]);
}
}
}
int get(int l, int r) {
int k = lg[r - l + 1];
return max(mx[k][l], mx[k][r - (1 << k) + 1]);
}
} st[21], t;
int get(int l, int r) {
int mx = t.get(l, r), ans = 0;
int tl = l, tr = r;
if(a[l] < mx) {
tl = nxtr[l][mx];
ans = max(ans, get(l, tl - 1) + (mx - t.get(l, tl - 1)) * (tl - l));
}
if(a[r] < mx) {
tr = nxtl[r][mx];
ans = max(ans, get(tr + 1, r) + (mx - t.get(tr + 1, r)) * (r - tr));
}
ans = max(ans, st[mx].get(tl, tr));
return ans;
}
vector<long long> minimum_costs(vector<int> H, vector<int> L, vector<int> R) {
n = (int)H.size(), m = (int)L.size();
for(int i = 1; i <= n; i++) {
a[i] = H[i - 1];
pref[i] = pref[i - 1] + a[i];
}
for(int i = 1; i <= n; i++) {
for(int x = 1; x <= 20; x++) {
nxtl[i][x] = nxtl[i - 1][x];
}
nxtl[i][a[i]] = i;
}
for(int x = 0; x <= 20; x++) {
nxtr[n + 1][x] = n + 1;
}
for(int i = n; i; i--) {
for(int x = 1; x <= 20; x++) {
nxtr[i][x] = nxtr[i + 1][x];
}
nxtr[i][a[i]] = i;
}
t.build(H);
for(int i = 1; i <= n; i++) {
for(int x = 19; x >= 1; x--) {
nxtl[i][x] = max(nxtl[i][x + 1], nxtl[i][x]);
nxtr[i][x] = min(nxtr[i][x + 1], nxtr[i][x]);
}
}
for(int k = 1; k <= 20; k++) {
vector<int> v;
for(int i = 1; i <= n; i++) {
int val = 0;
for(int x = 1; x < k; x++) {
val += (k - x) * (nxtl[i][x] - nxtl[i][x + 1]);
val += (k - x) * (nxtr[i][x + 1] - nxtr[i][x]);
}
v.push_back(val - (k - a[i]));
}
st[k].build(v);
}
vector<ll> ans(m);
for(int i = 0; i < m; i++) {
L[i]++, R[i]++;
ans[i] = t.get(L[i], R[i]) * (R[i] - L[i] + 1) - get(L[i], R[i]);
}
return ans;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
1 1 877914575 0 0
output:
Unauthorized output
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 17
Accepted
Test #16:
score: 17
Accepted
time: 0ms
memory: 173864kb
input:
1 1 2 0 0
output:
2
result:
ok single line: '2'
Test #17:
score: 17
Accepted
time: 12ms
memory: 176348kb
input:
8014 48643 2 2 1 2 2 1 2 1 1 1 1 1 2 2 1 1 2 1 2 2 1 2 1 1 2 2 2 1 2 1 1 2 1 1 2 1 2 2 1 1 2 2 2 1 1 1 1 2 2 1 1 1 1 1 2 2 2 2 2 2 1 1 2 2 2 1 1 2 1 1 2 2 2 1 2 2 1 1 2 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 2 2 2 2 2 1 2 2 1 2 2 2 1 1 2 1 2 2 1 2 1 1 2 2 2 2 2 2 1 2 2 1 1 1 2 1 1 1 1 2 1 2 2 1 1 1 1 1 1 2...
output:
3556 2463 7389 1531 8055 565 9221 4957 4500 11001 4663 6013 10655 426 331 1495 3961 2197 3543 2786 773 13953 13077 6111 9863 7113 1576 12305 9019 9511 1019 10123 412 8015 13491 9367 7363 2001 5417 8827 361 815 5863 4607 173 6827 5345 5214 3430 2512 11655 3621 9051 290 583 4363 4694 2789 2865 613 464...
result:
ok 48643 lines
Test #18:
score: 17
Accepted
time: 79ms
memory: 196476kb
input:
100000 100000 1 2 1 1 2 1 1 2 2 2 2 1 1 1 2 2 1 1 2 2 2 1 1 2 2 1 2 2 1 2 2 1 1 1 2 2 1 2 2 2 1 1 1 1 1 2 2 2 2 2 1 1 2 2 2 2 2 1 2 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 2 2 1 1 1 2 2 1 1 1 2 2 2 2 2 1 1 1 1 2 2 1 1 1 1 1 2 2 1 2 1 2 1 2 2 2 2 2 2 2 1 1 1 1 2 2 2 1 1 2 1 1 1 1 2 2 2 1 1 1 2 2 2 1 1 2 2 1 2 ...
output:
168406 42134 67627 116194 47354 158012 95896 13652 69190 25189 58555 5891 39157 57985 58625 46834 7568 171074 30777 12773 22617 39621 135830 150402 35852 12238 23716 47584 40985 14212 52815 38157 143640 123162 99249 55757 19360 150426 73095 166458 841 90320 77842 10383 191290 20379 115790 134622 474...
result:
ok 100000 lines
Test #19:
score: 17
Accepted
time: 84ms
memory: 196332kb
input:
100000 100000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
15743 57781 66106 101101 36861 31252 10449 79635 92420 165205 146533 139493 39521 12850 137807 41264 58619 114891 26922 158531 14672 75092 23640 50018 50006 6319 4579 2374 88970 185401 102244 57954 54048 62615 29866 85908 129018 82033 95840 26771 14103 53794 61872 1189 95090 36596 29519 38167 41533 ...
result:
ok 100000 lines
Test #20:
score: 17
Accepted
time: 72ms
memory: 196232kb
input:
100000 100000 2 2 2 1 2 2 2 1 2 1 2 1 1 2 2 2 2 1 2 2 1 1 2 2 1 1 2 1 1 2 2 2 1 2 1 2 1 2 1 2 2 1 2 2 1 1 1 1 2 1 1 1 2 2 2 2 2 1 1 2 2 2 1 2 1 1 1 2 2 1 1 1 2 1 1 2 1 2 2 2 2 1 2 1 2 2 1 2 1 2 1 2 1 1 1 2 2 1 1 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 2 1 1 2 1 2 2 1 2 1 2 1 2 1 2 1 2 2 2 2 2 2 2 1 1 1 ...
output:
2 1 1 1 1 1 2 1 1 2 1 2 2 2 1 2 2 2 2 1 1 2 2 1 1 1 1 1 1 2 1 2 2 2 1 2 1 2 2 2 2 1 2 2 2 2 2 1 1 1 1 2 2 1 2 2 1 2 2 2 2 2 1 2 2 1 1 2 1 1 2 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 2 2 2 2 1 2 2 1 2 2 1 2 1 1 1 1 2 1 2 1 1 2 1 1 1 1 2 2 1 1 1 2 2 1 1 2 1 2 2 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 1 2 2 2 1 2 2 1 1 ...
result:
ok 100000 lines
Test #21:
score: 17
Accepted
time: 70ms
memory: 196076kb
input:
100000 100000 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
output:
551 1102 1102 1102 619 551 551 784 1102 1102 898 1102 615 1102 1102 560 935 1102 1104 1102 1102 551 1102 551 1102 794 1102 765 551 1102 551 801 917 741 1102 1102 1102 1102 551 1047 726 748 1102 1102 551 660 551 1010 1102 551 1102 893 551 848 551 1102 551 1102 1102 551 1102 913 1013 733 575 1102 551 ...
result:
ok 100000 lines
Test #22:
score: 17
Accepted
time: 77ms
memory: 196276kb
input:
100000 100000 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ...
output:
93072 10048 127454 7287 10697 48837 23960 38279 52605 83423 38556 45086 41906 74620 12478 24472 18593 338 86059 43004 26175 49213 6017 3782 50721 48508 59681 112042 7237 42567 103692 32514 64561 6857 34165 33644 80940 62943 82703 78504 93112 5189 23728 84158 128054 49624 15315 45684 55108 54868 5523...
result:
ok 100000 lines
Subtask #4:
score: 0
Time Limit Exceeded
Dependency #3:
100%
Accepted
Test #23:
score: 24
Accepted
time: 147ms
memory: 196112kb
input:
100000 100000 7 8 10 1 18 12 13 14 17 15 9 5 1 15 15 9 20 15 9 16 11 16 20 13 14 5 20 8 16 12 20 1 12 11 11 5 13 12 17 20 7 2 11 17 15 13 7 14 19 17 14 9 20 20 3 15 2 19 11 17 8 14 16 10 5 13 8 15 8 15 20 4 13 3 7 4 9 18 6 20 2 18 7 4 13 6 3 16 3 4 6 17 12 9 19 2 7 1 6 8 15 20 8 6 19 2 14 5 4 8 2 5 ...
output:
243321 699105 645251 998445 35782 1043118 796231 55270 240059 879491 37347 118783 585805 1554185 436421 496278 994351 188775 604898 1079211 449993 42631 1218305 878411 708938 147618 781638 46004 556585 763825 270450 1136151 761471 602651 419226 483635 288111 1675258 178643 1792498 68762 158291 15841...
result:
ok 100000 lines
Test #24:
score: 24
Accepted
time: 101ms
memory: 195444kb
input:
100000 100000 10 14 1 15 3 17 17 17 12 16 14 4 5 6 9 5 11 13 18 8 20 20 15 10 8 14 12 8 6 17 13 9 16 3 14 19 18 1 14 14 19 15 2 3 12 17 19 3 19 6 19 18 18 7 1 9 9 13 20 8 8 16 16 20 14 8 4 6 11 16 9 6 11 6 6 2 20 4 18 8 9 2 14 19 1 14 16 3 8 7 9 4 19 3 11 15 6 20 12 5 1 6 5 10 16 4 8 19 10 3 19 12 3...
output:
1998416 1991656 1992376 1993696 1997936 1990676 1992916 1997656 1990956 1994616 1991696 1991856 1996576 1991616 1995716 1994916 1995156 1991556 1997056 1991376 1994936 1991396 1994596 1995176 1991436 1992876 1995656 1993696 1994136 1992956 1995556 1995656 1991816 1992116 1992436 1992116 1993736 1992...
result:
ok 100000 lines
Test #25:
score: 24
Accepted
time: 147ms
memory: 196484kb
input:
100000 100000 2 6 19 10 2 3 9 5 15 3 8 12 18 6 16 14 20 1 13 9 4 4 19 1 14 11 9 15 13 17 7 6 18 20 16 14 7 15 5 4 9 20 20 20 15 2 6 11 16 5 9 9 9 9 14 20 17 10 16 19 11 19 11 12 7 10 14 14 1 9 19 7 1 9 13 3 9 10 8 20 19 8 13 16 12 1 6 18 1 12 8 13 2 4 5 4 10 19 2 16 17 11 5 1 10 13 16 6 17 4 4 16 10...
output:
10655 10818 10820 10802 10694 10793 10779 10758 10800 10832 10776 10817 10744 10805 10741 10808 10803 10801 10819 10750 10766 10801 10805 10840 10871 10829 10840 10787 10846 10801 10731 10787 10849 10790 10794 10759 10750 10776 10765 10798 10803 10771 10793 10844 10825 10741 10745 10811 10791 10815 ...
result:
ok 100000 lines
Test #26:
score: 24
Accepted
time: 186ms
memory: 195496kb
input:
100000 100000 11 13 11 7 12 13 4 10 15 19 8 16 2 4 11 17 15 12 3 5 17 5 6 6 9 19 7 8 19 10 15 13 6 17 19 11 14 19 17 17 5 8 13 4 13 8 18 2 14 5 9 17 2 17 11 6 6 14 10 18 3 4 7 11 7 16 13 9 6 12 13 5 17 10 3 5 4 13 4 9 13 7 13 7 6 7 16 6 18 10 9 1 5 4 3 1 6 2 3 3 11 13 10 6 12 12 6 17 3 4 8 11 9 4 18...
output:
113723 641767 643306 1394327 14127 374077 1340567 1145808 1133627 63624 1273227 1138867 1892627 236477 754787 747247 1120487 177376 643307 270247 567446 1844227 372268 40902 1369167 16493 913487 267467 1230347 748106 583147 403287 558008 174249 151767 431408 294306 1049726 1297167 1641347 406688 736...
result:
ok 100000 lines
Test #27:
score: 24
Accepted
time: 119ms
memory: 196984kb
input:
100000 100000 8 4 19 14 11 9 14 11 13 14 6 4 13 5 8 19 8 3 5 1 7 8 5 5 13 16 19 8 12 17 17 4 8 1 7 7 8 11 16 1 14 15 11 9 9 3 15 8 18 6 17 6 15 16 13 2 6 14 7 17 16 12 7 1 1 1 12 2 13 5 14 11 1 19 5 2 1 16 8 8 12 3 2 12 6 10 5 10 8 1 1 7 6 18 11 19 10 3 13 12 5 5 10 9 18 18 1 5 18 15 17 17 1 19 16 1...
output:
1991399 1995779 1992499 1990579 1994299 1994779 1991739 1991799 1990799 1990059 1993699 1989839 1993159 1993879 1994359 1993419 1992759 1990579 1993219 1992499 1992019 1989819 1991859 1994879 1993139 1990459 1993059 1992239 1992279 1990359 1996779 1989919 1992779 1993459 1994199 1990439 1992099 1990...
result:
ok 100000 lines
Test #28:
score: 24
Accepted
time: 181ms
memory: 195500kb
input:
100000 100000 6 3 3 12 3 1 18 13 16 6 12 7 6 7 18 11 10 1 12 16 9 17 1 15 4 5 8 2 6 10 17 5 5 1 11 5 6 6 2 11 5 13 12 2 1 8 3 18 9 9 3 1 15 9 8 19 10 12 8 17 12 18 13 18 5 6 19 16 8 17 9 9 9 18 16 13 12 17 7 2 15 4 2 7 11 13 5 14 18 1 7 15 14 8 17 15 16 18 15 6 7 7 11 17 14 14 5 17 2 14 16 13 12 11 ...
output:
10367 10411 10280 10351 10275 10214 10496 10467 10527 10275 10374 10489 10504 10228 10243 10282 10381 10257 10477 10216 10526 10592 10451 10410 10496 10467 10698 10237 10511 10296 10274 10414 10286 10325 10310 10504 10243 10350 10509 10218 10228 10313 10602 10364 10311 10419 10464 10251 10437 10517 ...
result:
ok 100000 lines
Test #29:
score: 24
Accepted
time: 84ms
memory: 196160kb
input:
100000 100000 5 20 9 20 2 20 7 20 4 20 17 20 17 20 9 20 18 20 8 20 8 20 18 20 4 20 11 20 4 20 9 20 9 20 15 20 16 20 11 20 7 20 19 20 10 20 12 20 19 20 10 20 2 20 1 20 7 20 18 20 17 20 6 20 9 20 3 20 15 20 2 20 4 20 11 20 5 20 15 20 7 20 12 20 12 20 5 20 4 20 17 20 17 20 6 20 11 20 15 20 8 20 19 20 1...
output:
136041 1167941 580301 1013161 68641 76221 249901 739461 557721 123201 109161 641681 370581 24441 2821 217801 499101 410961 1148341 1475841 16341 299061 452121 372621 304981 629001 1013841 555461 728541 74281 90961 285841 187541 78201 533381 438961 730901 117621 6701 138241 322201 500281 593281 99724...
result:
ok 100000 lines
Test #30:
score: 0
Time Limit Exceeded
input:
100000 100000 1 3 1 4 1 3 1 5 1 3 1 4 1 3 1 6 1 3 1 4 1 3 1 5 1 3 1 4 1 3 1 7 1 3 1 4 1 3 1 5 1 3 1 4 1 3 1 6 1 3 1 4 1 3 1 5 1 3 1 4 1 3 1 9 1 3 1 4 1 3 1 5 1 3 1 4 1 3 1 6 1 3 1 4 1 3 1 5 1 3 1 4 1 3 1 7 1 3 1 4 1 3 1 5 1 3 1 4 1 3 1 6 1 3 1 4 1 3 1 5 1 3 1 4 1 3 1 10 1 3 1 4 1 3 1 5 1 3 1 4 1 3 1...
output:
Unauthorized output
result:
Subtask #5:
score: 0
Skipped
Dependency #1:
0%