ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#197054 | #3421. A | smwtcat | 100 | 1766ms | 31536kb | C++11 | 2.0kb | 2023-11-05 12:12:54 | 2023-11-05 13:03:28 |
answer
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int Mod = 998244353;
inline void uadd(int &a, int b){ a += b-Mod; a += (a>>31) & Mod; }
inline void usub(int &a, int b){ a -= b, a += (a>>31) & Mod; }
inline void umul(int &a, int b){ a = (int)(1ll * a * b % Mod); }
inline int add(int a, int b){ a += b-Mod; a += (a>>31) & Mod; return a; }
inline int sub(int a, int b){ a -= b, a += (a>>31) & Mod; return a; }
inline int mul(int a, int b){ return (int)(1ll * a * b % Mod); }
int read(){
int x = 0, c = getchar();
while(c < '0' || c > '9') c = getchar();
while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x;
}
void putint(ll x){
if(x < 0) putchar('-'), x = -x;
static int cur[22], p; static ll nx;
do{ nx = x / 10, cur[p++] = (int)(x - 10 * nx), x = nx; } while(x);
while(p) putchar('0' + cur[--p]);
}
int n, m, c[1000100], a[1000100], d[1000100];
ll dis[1000100], ans[1000100];
int ord[1000100];
int main(){
//ios::sync_with_stdio(false);
//cin.tie(0);
n = read(), m = read();
rep(i, n) c[i] = read();
rep(i, m) a[i] = read() - 1, d[i] = read(), dis[a[i]] += d[i];
for(int i = n-2; i >= 0; --i) dis[i] += dis[i+1];
rep(i, n) ord[i] = i;
sort(ord, ord+n, [&](int lh, int rh){ return c[lh] < c[rh]; });
int mnid = n;
ll sum = 0;
rep(i, n){
int u = ord[i];
mnid = min(mnid, u), sum += c[u];
ans[i+1] = sum - dis[mnid];
//cout << i+1 << " " << u << ": " << sum << " " << mnid << "\n";
}
mnid = ord[n-1];
for(int i = n-1; i >= 0; --i){
int u = ord[i];
sum -= c[u];
if(c[u] - dis[u] < c[mnid] - dis[mnid])
mnid = u;
//cout << i+1 << " " << mnid << ": " << sum << " + " << c[mnid] << " - " << dis[mnid] << "\n";
ans[i+1] = min(ans[i+1], sum + c[mnid] - dis[mnid]);
}
for(int i = 1; i <= n; ++i) putint(ans[i]), putchar(' ');
putchar('\n');
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 1160kb
input:
18 18 886554641 247388609 262972135 237324097 380496258 624891473 567152737 956692830 182487365 4071...
output:
68376730 184669817 367157128 604481217 851869819 1114841954 1468607549 1824590356 2185532232 2566028...
result:
ok single line: '68376730 184669817 367157128 6...05867919 6892422556 7849115386 '
Test #2:
score: 0
Accepted
time: 0ms
memory: 1164kb
input:
18 18 998747840 902839213 717558720 790072519 576580911 546397456 863819834 451611091 377921829 7338...
output:
53775181 136551755 256709161 407130471 591364162 821593381 1199515074 1651126165 2197523488 27741043...
result:
ok single line: '53775181 136551755 256709161 4...33452271 8490442524 9489190351 '
Test #3:
score: 0
Accepted
time: 0ms
memory: 1160kb
input:
18 20 292345402 348917508 239255318 376910472 737713328 657954923 396584102 777279990 141297969 7231...
output:
89698296 220945597 353921151 495216534 734470403 1026815003 1341475319 1690392827 2067303299 2463887...
result:
ok single line: '89698296 220945597 353921151 4...17013997 7606023136 8603156012 '
Test #4:
score: 0
Accepted
time: 0ms
memory: 1164kb
input:
20 18 628943170 836531151 284136359 744513731 205407227 733491529 112120799 92641092 682832891 53362...
output:
34183365 78421602 131736576 224377668 336491305 541888026 826002407 1324745683 1864618651 2450333466...
result:
ok single line: '34183365 78421602 131736576 22...49160293 8985691444 9954817870 '
Subtask #2:
score: 20
Accepted
Test #5:
score: 20
Accepted
time: 0ms
memory: 1184kb
input:
908 903 744733469 400394929 274695089 653860040 354250834 611135454 273779769 443353702 271924447 95...
output:
311580 2103392 4631638 7167879 11906872 17414668 27042610 37309747 48437586 60096402 73037449 875397...
result:
ok single line: '311580 2103392 4631638 7167879...8024 437896926103 438895954705 '
Test #6:
score: 0
Accepted
time: 0ms
memory: 1180kb
input:
976 922 773505910 297478209 695472579 930591920 900960035 793104705 296779957 296743168 296253858 29...
output:
1329647 2864928 5127564 7742616 11573547 15480739 19429199 23536334 28210529 33296870 39283121 48323...
result:
ok single line: '1329647 2864928 5127564 774261...0095 466503150903 467502537984 '
Test #7:
score: 0
Accepted
time: 0ms
memory: 1180kb
input:
914 988 547780745 344869621 243088032 393474450 971910021 853107029 629995954 323148883 670975765 76...
output:
243108 1631588 3927429 6582003 10747662 15249582 19873793 26128408 32632892 42594383 54265906 661531...
result:
ok single line: '243108 1631588 3927429 6582003...5223 418557012195 419551975760 '
Test #8:
score: 0
Accepted
time: 0ms
memory: 1184kb
input:
921 953 972027851 282977805 573538013 341812031 282798470 280666874 443028031 278937162 278229701 27...
output:
347443 2050242 4119284 6706452 10434432 14578147 20531991 26528839 33429135 46326959 59778777 738267...
result:
ok single line: '347443 2050242 4119284 6706452...6131 429407598610 430407561328 '
Subtask #3:
score: 30
Accepted
Test #9:
score: 30
Accepted
time: 30ms
memory: 4148kb
input:
97037 91906 465440737 287027270 930092863 582535323 415429449 603060880 294780552 287015635 28698173...
output:
10569 21424 58105 103043 168672 236896 315467 394836 474771 577535 690119 813302 940156 1069894 1227...
result:
ok single line: '10569 21424 58105 103043 16867... 46244787993544 46245787965602 '
Test #10:
score: 0
Accepted
time: 34ms
memory: 4028kb
input:
91262 93572 486947882 288944105 620301263 543010497 288939673 674563729 378540646 295524162 43815624...
output:
8647 31159 59290 109497 160225 224236 299122 377908 468167 577438 702453 843245 998839 1161060 13235...
result:
ok single line: '8647 31159 59290 109497 160225... 43525411266771 43526411262844 '
Test #11:
score: 0
Accepted
time: 33ms
memory: 4104kb
input:
93569 96897 283003693 283003117 282988084 282975193 635743914 912385084 956488448 282970026 67283163...
output:
6425 13677 26018 49662 80597 128786 177590 227603 278669 348986 427294 510725 596164 684308 777543 8...
result:
ok single line: '6425 13677 26018 49662 80597 1... 44236592663398 44237592653882 '
Test #12:
score: 0
Accepted
time: 28ms
memory: 4096kb
input:
92184 99327 687590372 330532922 419175688 465479454 895170452 555905298 284658672 310777617 28465378...
output:
-212118448 -212110721 -212069742 -212024872 -211972901 -211918696 -211857452 -211790711 -211722028 -...
result:
ok single line: '-212118448 -212110721 -2120697... 43833471091381 43834471090271 '
Subtask #4:
score: 40
Accepted
Test #13:
score: 40
Accepted
time: 368ms
memory: 29532kb
input:
905990 914088 285459076 898213731 901996880 690623988 285458528 962881611 397318590 698656227 285455...
output:
704 4253 8440 14210 20047 27508 35144 43089 51364 60058 68899 78066 88503 99077 113141 127241 141815...
result:
ok single line: '704 4253 8440 14210 20047 2750...30727981362954 430728981359632 '
Test #14:
score: 0
Accepted
time: 394ms
memory: 30088kb
input:
901185 999721 700864313 579085036 677352135 940311742 285490041 874999213 285489200 497342302 719353...
output:
411 4372 10725 18190 27186 36584 46464 57088 67888 79080 90380 101876 113833 126050 140416 156770 17...
result:
ok single line: '411 4372 10725 18190 27186 365...28695038652173 428696038648682 '
Test #15:
score: 0
Accepted
time: 428ms
memory: 31144kb
input:
948820 992079 285934518 285934183 572417292 697063599 560608894 285933922 438095791 285933767 921982...
output:
-211014600 -211014493 -211013795 -211012510 -211006861 -211001132 -210995265 -210989284 -210983198 -...
result:
ok single line: '-211014600 -211014493 -2110137...51251421117291 451252421116044 '
Test #16:
score: 0
Accepted
time: 451ms
memory: 31536kb
input:
994451 905799 285718404 921564399 724559787 434457429 285718269 943331435 285717960 686575963 745308...
output:
-4238061358 -4238061020 -4238059111 -4238056790 -4238053850 -4238050558 -4238045791 -4238040963 -423...
result:
ok single line: '-4238061358 -4238061020 -42380...72323825981442 472324825980006 '
Extra Test:
score: 0
Extra Test Passed