QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#187118 | #3850. DJ Darko | DuckDebuggian# | AC ✓ | 350ms | 45928kb | C++14 | 3.6kb | 2023-09-24 14:45:20 | 2023-09-24 14:45:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> Pii;
typedef double db;
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
template <class T> inline void cmin(T &a, T b){ ((a>b)&&(a=b)); }
template <class T> inline void cmax(T &a, T b){ ((a<b)&&(a=b)); }
template <class T = int> T rd() {
T s = 0; int f = 0; char c;
while(c = getchar(), c < 48) f = c == '-';
do s = s * 10 + c -48;
while(c = getchar(), c > 47);
return f? -s:s;
}
const int N = 1e6 + 10;
const ll LINF = 1e18 + 10;
int n, m;
int a[N];
ll b[N];
ll s1[N << 2], s2[N << 2];
ll t1[N<<2], t2[N<<2];
void push_up(int p) {
s1[p] = min(s1[p<<1],s1[p<<1|1]);
s2[p] = max(s2[p<<1],s2[p<<1|1]);
}
void uset(int p, ll x) {
t1[p] = s1[p] = s2[p] = x, t2[p] =0;
}
void add(int p, ll x) {
s1[p] += x, s2[p] += x, t2[p] += x;
}
void push_down(int p) {
if(t1[p] != LINF) uset(p << 1, t1[p]), uset(p << 1 | 1, t1[p]), t1[p] = LINF;
if(t2[p]) add(p << 1, t2[p]), add(p << 1| 1,t2[p]), t2[p]=0;
}
void build(int p, int l, int r) {
t1[p] = LINF;
if(l == r) {
s1[p] = s2[p] = a[l];
return;
}
int mid = (l + r) >> 1;
build(p << 1, l, mid);
build(p << 1 | 1, mid + 1, r);
push_up(p);
}
void uset(int p, int l, int r, int ql, int qr, ll x) {
// cout << "uset " << p << ' '<<l<<' ' <<r<< ' '<<ql << ' ' << qr<<endl;
if(ql <= l && r <= qr) return uset(p, x);
int mid=(l+r)>>1;
push_down(p);
if(ql<=mid) uset(p<<1,l,mid,ql,qr,x);
if(qr>mid) uset(p<<1|1,mid+1,r,ql,qr,x);
push_up(p);
}
void add(int p, int l, int r, int ql, int qr, ll x) {
if(ql <= l && r <= qr) return add(p, x);
int mid=(l+r)>>1;
push_down(p);
if(ql<=mid) add(p<<1,l,mid,ql,qr,x);
if(qr>mid) add(p<<1|1,mid+1,r,ql,qr,x);
push_up(p);
}
ll query(int p, int l, int r, int x) {
if(l == r) return s1[p];
int mid = (l + r) >> 1;
push_down(p);
return x <= mid ? query(p << 1, l, mid, x): query(p<<1|1,mid+1,r,x);
}
int get(int p, int l, int r, int x, ll y) {
if(l >= x) {
if(s1[p] == y && s2[p] == y) return r;
if(l == r) return l - 1;
push_down(p);
int mid=(l+r)>>1;
return s1[p << 1] == y && s2[p<<1] == y ? get(p<<1|1,mid+1,r,x,y) : get(p<<1,l,mid,x, y);
}
push_down(p);
int mid=(l+r)>>1;
if(x <= mid) {
int res = get(p<<1,l,mid,x,y);
if(res == mid) return get(p << 1 | 1, mid + 1, r, x, y);
else return res;
} else {
return get(p << 1 | 1, mid + 1, r,x, y);
}
}
using i128 = __int128;
struct Node{
ll x; int l, r;
bool operator < (const Node __ )const {
return x < __.x;
}
} T[N];
i128 LS[N], RS[N];
int C;
int main() {
n = rd(), m =rd();
rep(i,1,n) a[i] =rd();
rep(i,1,n) b[i] = b[i-1] + rd();
build(1,1,n);
while(m--) {
int op = rd(), l = rd(), r = rd();
if(op == 1) add(1,1,n,l,r,rd());
else {
C = 0;
for(int p = l; p <= r;) {
ll x = query(1,1,n,p);
int q = min(r, p == n ? n : get(1,1,n,p+1,x));
T[++C]=(Node){x, p, q};
// cout << "$" << x << ' '<<p << ' '<<q<<endl;
p = q + 1;
}
sort(T+1,T+C+1);
// b[i] * abs(x - v)
i128 s = 0;
rep(i,1,C) {
LS[i] = LS[i-1] + (i128)(T[i].x - T[i-1].x) * s;
s += b[T[i].r] - b[T[i].l-1];
}
s=0, RS[C+1]=0;
drep(i,C,1) {
RS[i] = RS[i+1] + (i128)(T[i+1].x - T[i].x) * s;
s += b[T[i].r] - b[T[i].l-1];
}
i128 res = (i128)LINF * LINF;
ll v = -1;
rep(i,1,C) {
i128 w = LS[i] + RS[i];
if(w < res) res= w, v = T[i].x;
}
printf("%lld\n", v);
uset(1,1,n,l,r,v);
// puts("uset over");
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 327ms
memory: 40236kb
input:
200000 200000 185413631 745038744 881479208 394948467 101727403 796960399 284541402 80768155 286582974 546327406 197495962 552359542 727479505 437895671 143092948 7626834 741609268 540494577 298656274 548860413 41137417 210529949 658779847 161355446 486548926 602900245 119414972 310187428 238177860 ...
output:
462406736 1749348519 1749348519 467651597 874061694 874061694 874061694 874061694 -1521749 874061694 -893932302 -425504259 -425504259 332034115 332034115 86195778 86195778 86195778 86195778 86195778 -425504259 -165776398 -165776398 -165776398 -916781043 -254293799 -254293799 -254293799 -254293799 -8...
result:
ok 100093 lines
Test #2:
score: 0
Accepted
time: 342ms
memory: 43964kb
input:
200000 200000 972602488 314379868 184424413 693297170 700590031 777123666 30306102 166401429 402684895 653689101 215770359 161277184 972006312 379507241 52836126 481985240 481425913 456361236 149694150 336596790 22492952 154063153 414263227 854090461 603168307 194806250 934267524 8018143 119175379 8...
output:
459983042 459983042 459983042 459983042 459983042 459983042 459983042 459983042 459983042 459983042 459983042 1337072802 1189453446 1337072802 1189453446 1337072802 1189453446 1189453446 1189453446 1189453446 1189453446 1189453446 1189453446 1189453446 1189453446 1189453446 1189453446 1189453446 118...
result:
ok 100009 lines
Test #3:
score: 0
Accepted
time: 340ms
memory: 40348kb
input:
200000 200000 54451649 780255224 110478287 601059692 134896126 720758367 64302994 897948958 504280517 267611424 47310537 600352950 155295586 22375940 972388036 8479064 47904993 413885666 778337500 61878536 883229478 949122833 150124767 904785808 3877919 68702856 282619557 29644659 326058655 43935186...
output:
960711412 464459420 466826314 755354030 755354030 1576987719 653317168 755354030 653317168 653317168 653317168 755354030 755354030 755354030 755354030 755354030 755354030 949620275 949620275 949620275 1079046141 1201296119 1079046141 427993693 427993693 427993693 427993693 427993693 427993693 735104...
result:
ok 100622 lines
Test #4:
score: 0
Accepted
time: 339ms
memory: 38932kb
input:
200000 200000 641592937 5142850 519935476 453679500 899482891 392746612 577738684 176507842 282856239 30049614 977295321 93713323 134385395 468023191 907137535 241164913 735689172 540449406 694001502 892420577 746715706 329549099 540170588 379333807 193414785 815744194 361858095 273429758 894795530 ...
output:
340894430 1088434316 1224075912 1027194255 1027194255 1027194255 381158633 1027194255 381158633 381158633 2725875130 566943856 566943856 1881266677 1396460195 932099985 1113183136 1113183136 1113183136 1113183136 1113183136 76951607 573102431 573102431 219169018 962404765 838433182 219169018 2191690...
result:
ok 99462 lines
Test #5:
score: 0
Accepted
time: 330ms
memory: 38960kb
input:
200000 200000 996193403 11908243 964493073 412667312 580369407 617168144 896265893 125558051 64592736 992662561 108160300 971134407 674224024 538988540 589565846 882830153 270571179 18194860 582464918 146423228 803264538 581975241 45388030 726462617 36973838 192326749 675999327 721544917 799772462 2...
output:
463454991 463454991 461051107 -369230050 -369230050 -369230050 -369230050 -369230050 -369230050 -369230050 -369230050 -369230050 -369230050 -369230050 -369230050 -369230050 -369230050 -369230050 -369230050 -262395636 -1199500446 -1199500446 -2224823946 -2224823946 -2224823946 -2263248269 -2263248269...
result:
ok 99904 lines
Test #6:
score: 0
Accepted
time: 347ms
memory: 36932kb
input:
200000 200000 304717406 237343984 849830928 307360459 42637288 428596134 610596971 133103232 93569179 230640945 70186585 95779131 183205122 32588005 669560120 938992309 656680237 291279209 333224112 358478216 511342021 265872030 750869870 506507460 49168665 431268189 47552261 580244698 563709874 375...
output:
461272409 461272409 469647052 -320614976 -308208122 -308208122 -308208122 -308208122 -308208122 -304864073 -308208122 -308208122 -308208122 -308208122 -308208122 -308208122 -308208122 -308208122 -308208122 -455740461 -455740461 -455740461 -455740461 -455740461 -1302254164 -1302254164 -1302254164 -13...
result:
ok 100040 lines
Test #7:
score: 0
Accepted
time: 342ms
memory: 43152kb
input:
200000 200000 884408920 739598414 345404821 145276498 120779856 486294013 199605830 27731725 52045838 630715671 548745038 574917560 731986697 345937417 84911270 878625106 572924969 331032692 117222866 151439937 407570366 821436222 267977245 865712203 147051876 41026991 817671771 828317371 281261294 ...
output:
662700437 641921238 794391476 641921238 641921238 797076699 628470386 439393429 439393429 439393429 303004001 303004001 303004001 303004001 303004001 303004001 303004001 440949479 440949479 440949479 440949479 440949479 440949479 440949479 440949479 439393429 440949479 440949479 440949479 1125572697...
result:
ok 100094 lines
Test #8:
score: 0
Accepted
time: 324ms
memory: 39956kb
input:
200000 200000 697473842 363963877 875605823 242505213 768556457 965817691 68388149 651237037 99662301 811843459 136091087 203215575 263845782 597805229 209364997 44769407 62049854 561695305 544167952 158645034 662926701 244775401 943011734 477135592 717460087 70062024 588476371 21840443 686156918 64...
output:
461225385 461225385 461225385 461225385 461225385 481822635 481822635 481822635 481822635 119431952 119431952 1048471007 1048471007 1238403957 1238403957 486155218 119431952 1238403957 350473535 619456448 423288579 423288579 423288579 423288579 423288579 423288579 -977758483 -467381734 -467381734 -4...
result:
ok 99955 lines
Test #9:
score: 0
Accepted
time: 340ms
memory: 43964kb
input:
200000 200000 770939031 100027260 26607761 257116003 578591842 14715002 384907161 795620277 663449705 957636396 10096110 943812773 623755413 463569240 256374227 575035974 694671980 12040143 499867349 59883086 892387709 341030679 120202394 623953614 83162554 97959151 118420680 509646592 337142424 226...
output:
461744442 461744442 461744442 461744442 90990822 461744442 67701665 67701665 67701665 558053703 67701665 67701665 86976984 86976984 86976984 -814349972 568189874 86976984 568189874 -482961203 -482961203 -482961203 -116624420 -1039425909 -1039425909 -1039425909 -1039425909 -1039425909 -776849798 -776...
result:
ok 99964 lines
Test #10:
score: 0
Accepted
time: 325ms
memory: 39652kb
input:
200000 200000 645173566 382406182 660739990 661732900 254492041 312566797 634221062 973124785 548792153 719001918 176618540 254313518 1889679 671711431 379496831 924374644 156981408 157417484 622650521 991246405 991417632 619007330 19295671 489115444 20808890 388714360 444121189 750243322 958851569 ...
output:
463523307 373769773 373769773 -610458708 -1376528040 361784304 -1376528040 253226071 -1376528040 -1377092592 -462399434 -2345643668 -462399434 -2345643668 222092140 -2345643668 -2345643668 603986833 -2879474155 -1739304496 -3241686059 -3241686059 -3241686059 -818035179 -3794115588 -3794115588 -37941...
result:
ok 100034 lines
Test #11:
score: 0
Accepted
time: 330ms
memory: 40172kb
input:
200000 200000 160502030 119759725 798676658 300396885 174025958 601936795 446659248 729324836 313996009 668408433 442238103 325558049 697132953 870188033 83998193 669206978 239009920 848336048 371687135 364351110 573369920 770375709 395530518 786720865 49835067 237450821 598125144 216464801 79836955...
output:
519670652 519670652 519670652 475833842 -395222489 -624604726 204618978 -323816753 -323816753 -754963814 -754963814 -754963814 -754963814 -1038109263 -1038109263 -1915928359 -1306385950 -2878600579 -2802829717 -1306385950 -3051510691 -3051510691 -3051510691 -3051510691 -3051510691 -2665954506 -26659...
result:
ok 100449 lines
Test #12:
score: 0
Accepted
time: 334ms
memory: 40300kb
input:
200000 200000 86875028 669937055 476073447 933569964 178416414 451078839 636542360 76937674 657195235 806982980 770785656 347062463 370680609 754788044 841023078 74938525 464340817 516927674 575989470 706718205 957613196 592592900 203736013 444132196 795066624 91067505 110524120 114644356 819091040 ...
output:
392683607 392683607 -1321818195 -1321818195 -1321818195 415642687 1047811667 981356398 -2002681543 -1817873034 -1817873034 -383618716 -383618716 -1275883571 -2527494262 -2527494262 434612927 -2759014858 -2759014858 -2759014858 -2690347390 -3122564765 -3122564765 -4023665547 -3032307343 -3340120760 -...
result:
ok 99897 lines
Test #13:
score: 0
Accepted
time: 333ms
memory: 37376kb
input:
200000 200000 785652853 503550567 228154569 932957884 327192800 712696422 195171931 624023959 189398699 862046400 532687954 899040550 407251999 994035649 250404947 469467985 957542885 536842140 500967247 327800612 242825986 605958337 70210551 892310963 804803674 318636089 994967851 670449745 2008151...
output:
-413025755 1811356147 2531845889 1699789656 911545579 -19033977 753597502 1089674803 1089674803 1089674803 1089674803 2337420754 1817139308 923308315 1512320374 2069572373 1250616770 1781232319 1781232319 1781232319 1781232319 967680913 -42342041 967680913 34141398 967680913 34141398 967680913 96768...
result:
ok 100000 lines
Test #14:
score: 0
Accepted
time: 348ms
memory: 45840kb
input:
200000 200000 608768115 736966859 819593934 323971936 541195107 315192320 762028119 565047846 282801268 471171762 95508616 88400448 59588393 827685968 254665841 673426991 789797680 684990206 456739900 920845769 599510191 882478668 51393051 356859053 88826980 49367935 302504221 104160826 476283133 53...
output:
464605672 464605672 464605672 1571548649 2094569548 1571548649 1571548649 1571548649 1571548649 425054309 425054309 425054309 425054309 425054309 425054309 425054309 425054309 502958493 502958493 69209899 425054309 425054309 425054309 -395318238 622831502 622831502 622831502 622831502 233971889 8820...
result:
ok 99871 lines
Test #15:
score: 0
Accepted
time: 325ms
memory: 39844kb
input:
200000 200000 77569822 631653323 459793123 6620890 298792880 769053016 750944556 328319364 786294344 149583492 74664579 755310394 234466434 136041123 323345602 342012131 45847528 878057833 370246837 888787561 862306812 762915546 236300106 584176088 42647030 466505036 680081076 937641729 633942286 15...
output:
470600864 463939254 1234783557 380704280 380704280 985983310 763295694 1153392310 2105960956 2105960956 2188143687 2188143687 2122388840 1774986297 1774986297 2122388840 1774986297 1816861622 1774986297 1774986297 1774986297 1774986297 1816861622 1774986297 1222188064 1774986297 1774986297 144694907...
result:
ok 99709 lines
Test #16:
score: 0
Accepted
time: 333ms
memory: 39160kb
input:
200000 200000 789037576 800347617 70191007 107492285 631485821 729021712 33592307 48526534 390826091 478508815 23745046 584789269 265384980 467589573 189970326 114157283 814939578 352789406 103456838 162406370 355950979 693358455 454135810 11719361 510030964 331423871 230585085 469843362 514957312 2...
output:
462837255 462837255 821619243 198603878 -481043299 821619243 1060665461 560398514 831908938 331641991 560398514 560398514 176732043 176732043 176732043 -233440658 -233440658 -233440658 -233440658 -233440658 -233440658 -173016275 -173016275 -173016275 -173016275 -173016275 -173016275 -173016275 -2365...
result:
ok 100117 lines
Test #17:
score: 0
Accepted
time: 341ms
memory: 36732kb
input:
200000 200000 527675170 94357349 324513768 322565029 739839404 981044119 725529563 45771114 775958886 861242744 466524470 468360560 876392436 782585079 604204999 732684631 802646907 502051003 27555500 541222315 51744449 951579538 321897976 412428743 20902631 706146372 947445164 67027158 814358550 45...
output:
469268304 457300901 387948828 996193045 779298170 779298170 779298170 779298170 779298170 1007483916 1007483916 649530331 1608996995 1608996995 1608996995 461647165 1608996995 1608996995 1608996995 1608996995 2496032925 2496032925 1544339670 1544339670 1544339670 1497171199 1497171199 1497171199 789...
result:
ok 100183 lines
Test #18:
score: 0
Accepted
time: 350ms
memory: 43344kb
input:
200000 200000 295623699 172596424 152966064 520584321 850539165 508076348 931554355 891278291 995371348 883414507 435646027 35478494 579769264 674960675 119379729 960008930 331987150 699838951 605846712 330912991 537668213 241589031 412527754 624898580 482573711 192198024 655414761 22448230 84542702...
output:
465155012 465155012 -974584193 365819332 365819332 365819332 365819332 -561742413 -561742413 -561742413 1284006523 -45285878 1284006523 1284006523 -45285878 -45285878 -45285878 -45285878 -45285878 84219784 -45285878 -34449662 -34449662 -65431771 -65431771 -65431771 -45285878 -894030839 -45791859 -45...
result:
ok 99510 lines
Test #19:
score: 0
Accepted
time: 348ms
memory: 45928kb
input:
200000 200000 96932688 921219643 922005704 378036315 721247090 254515131 399300619 976051044 703508844 45976894 164223132 928515983 400225098 64682092 29691320 83197354 280506930 801331385 315678606 617806790 81667491 306329488 21558658 44535906 812438789 31317047 361002563 178035235 164150311 95955...
output:
462772940 462772940 462772940 403421166 1488678381 1488678381 1488678381 1488678381 2316208856 2581861386 2170118087 2767625029 2316208856 2767625029 2856398061 2477802326 2477802326 2884312767 2884312767 2959933696 1680416689 2959933696 2959933696 2579451777 2579451777 2678922734 2678922734 2137061...
result:
ok 100221 lines
Test #20:
score: 0
Accepted
time: 340ms
memory: 36932kb
input:
200000 200000 123916085 962998212 249098540 161224737 621682798 604255951 492988147 991092233 560342451 170581349 41264796 29394810 405180187 493790136 568059224 918936345 712569041 207142820 667789005 15262704 312274708 206860464 657399977 123995656 129106796 366638335 414778877 12341564 202820213 ...
output:
459685212 -76453917 -663952904 -76969839 -663952904 1574669325 2403459425 2403459425 2403459425 344446307 2518340925 1655444700 1655444700 1760305996 1655444700 1040672622 1040672622 1040672622 1040672622 190986759 -601900253 234612646 254106199 254106199 793509629 95675546 95675546 254106199 -38436...
result:
ok 100189 lines