QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#422598#6227. 区间和james1BadCreeper25 163ms130704kbC++174.1kb2024-05-27 17:10:452024-05-27 17:10:45

Judging History

你现在查看的是最新测评结果

  • [2024-05-27 17:10:45]
  • 评测
  • 测评结果:25
  • 用时:163ms
  • 内存:130704kb
  • [2024-05-27 17:10:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std; 
typedef long long i64; 
const int N = 4e5 + 5; 
const i64 INF = 2e18; 

struct Func {
    int k; i64 b; 
    Func(int k = 0, i64 b = 0) : k(k), b(b) {}
    friend Func operator+ (const Func a, const Func b) {
        return Func(a.k + b.k, a.b + b.b); 
    }
    inline void add(i64 v) { b += k * v; }
    inline void set(void) { k = 0; }
}; 
inline pair<Func, i64> max(Func a, Func b) {
    if (a.k < b.k || a.k == b.k && a.b < b.b) swap(a, b); 
    if (a.b >= b.b) return make_pair(a, INF); 
    return make_pair(b, (b.b - a.b) / (a.k - b.k)); 
}
struct Node {
    Func sum, lmax, rmax, ans; 
    i64 x; 
    Node(Func sum = Func(), Func lmax = Func(), Func rmax = Func(), Func ans = Func(), i64 x = 0) : sum(sum), lmax(lmax), rmax(rmax), ans(ans), x(x) {}
    friend Node operator+ (const Node &a, const Node &b) {
        Node t; t.sum = a.sum + b.sum; 
        t.x = min(a.x, b.x); 
        auto tmp = max(a.lmax, a.sum + b.lmax); 
        t.lmax = tmp.first, t.x = min(t.x, tmp.second); 
        tmp = max(b.rmax, b.sum + a.rmax); 
        t.rmax = tmp.first, t.x = min(t.x, tmp.second); 
        tmp = max(a.ans, b.ans); 
        t.ans = tmp.first, t.x = min(t.x, tmp.second); 
        tmp = max(tmp.first, a.rmax + b.lmax); 
        t.ans = tmp.first, t.x = min(t.x, tmp.second); 
        return t; 
    }
    inline Node set(void) {
        Node a = *this; 
        a.sum.set(); a.lmax.set(); a.rmax.set(); a.ans.set(); 
        return a; 
    }
} T[N * 4]; 

int n, q; 
int a[N]; 
i64 tag[N * 4], mn[N * 4], se[N * 4]; 

inline void pushup(int o) {
    if (mn[o << 1] == mn[o << 1 | 1]) {
        mn[o] = mn[o << 1], se[o] = min(se[o << 1], se[o << 1 | 1]); 
        T[o] = T[o << 1] + T[o << 1 | 1]; 
    } else if (mn[o << 1] < mn[o << 1 | 1]) {
        mn[o] = mn[o << 1], se[o] = min(se[o << 1], mn[o << 1 | 1]); 
        T[o] = T[o << 1] + T[o << 1 | 1].set(); 
    } else {
        mn[o] = mn[o << 1 | 1], se[o] = min(mn[o << 1], se[o << 1 | 1]); 
        T[o] = T[o << 1].set() + T[o << 1 | 1]; 
    }
}
void build(int o, int l, int r) {
    tag[o] = -INF; 
    if (l == r) {
        auto it = Func(1, a[l]); 
        T[o] = Node(it, it, it, it, INF); 
        mn[o] = a[l]; se[o] = INF; 
        return;
    }
    int mid = l + r >> 1; 
    build(o << 1, l, mid); build(o << 1 | 1, mid + 1, r); 
    pushup(o); 
}
inline void maketag(int o, i64 k) {
    if (mn[o] >= k) return; 
    i64 v = k - mn[o]; mn[o] = k; tag[o] = k; T[o].x -= v; 
    T[o].sum.add(v); T[o].lmax.add(v); T[o].rmax.add(v); T[o].ans.add(v); 
}
inline void pushdown(int o) {
    if (tag[o] == -INF) return; 
    maketag(o << 1, tag[o]); maketag(o << 1 | 1, tag[o]); 
    tag[o] = -INF; 
}
void rebuild(int o, int l, int r, i64 k) {
    tag[o] = max(tag[o], k); 
    if (k - mn[o] > T[o].x) {
        int mid = l + r >> 1; 
        rebuild(o << 1, l, mid, tag[o]); 
        rebuild(o << 1 | 1, mid + 1, r, tag[o]); 
        pushup(o); 
        return; 
    }
    maketag(o, k); 
}
void update(int o, int l, int r, int x, int y, i64 k) {
    if (mn[o] >= k) return; 
    if (x <= l && r <= y && k < se[o]) return rebuild(o, l, r, k), void(); 
    pushdown(o); int mid = l + r >> 1; 
    if (x <= mid) update(o << 1, l, mid, x, y, k); 
    if (mid < y) update(o << 1 | 1, mid + 1, r, x, y, k); 
    T[o] = T[o << 1] + T[o << 1 | 1]; 
}
Node query(int o, int l, int r, int x, int y) {
    if (x <= l && r <= y) return T[o]; 
    pushdown(o); int mid = l + r >> 1; 
    if (y <= mid) return query(o << 1, l, mid, x, y); 
    if (mid < x) return query(o << 1 | 1, mid + 1, r, x, y); 
    return query(o << 1, l, mid, x, y) + query(o << 1 | 1, mid + 1, r, x, y); 
}

int main(void) {
    ios::sync_with_stdio(0); cin.tie(0); 
    cin >> n >> q; 
    for (int i = 1; i <= n; ++i) cin >> a[i]; 
    build(1, 1, n); 
    while (q--) {
        int op, l, r, v; cin >> op >> l >> r; 
        if (op == 0) cin >> v, update(1, 1, n, l, r, v); 
        else cout << max(0ll, query(1, 1, n, l, r).ans.b) << "\n"; 
    }
    return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 123024kb

input:

182 187
20634704 -703314946 -948946252 144678123 5498424 341678302 -583114991 -196836433 43951489 -525692929 12701289 476729334 473931783 221423816 187493596 355488624 -39527016 -914505949 161713515 -227399136 -318205061 226437730 -601354045 -755181154 -241221294 256834551 44488096 -422708891 -79709...

output:

270081855
539758298
1110244863
539758298
933165833
933165833
415646256
1727768442
933165833
539758298
1727768442
1110244863
1110244863
1016111427
1121569481
1727768442
1110244863
1110244863
547193953
1110244863
1110244863
9387367327
7187231999
51650758
1727768442
4425642397
1727768442
6717339964
117...

result:

wrong answer 14th lines differ - expected: '933165833', found: '1016111427'

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 3ms
memory: 123644kb

input:

195 195
248663111 -522337032 -47794804 -955243356 418601542 493840666 478655582 -269027492 -801169819 -410940079 -766532109 -547019833 -158802702 -193483181 -125250985 35351136 -47755604 -781346033 -613952400 -155863697 5685369 -620132917 222562003 -563874770 65617262 356362550 -311762774 86801383 -...

output:

1190435898
1190435898
639530621
639530621
639530621
639530621
1391097790
1190435898
639530621
1067434241
630930122
718933383
1067434241
350877205
518835809
718933383
1067434241
972496248
718933383
1067434241
1190435898
1067434241
1190435898
518835809
518835809
1067434241
929409019
330633442
39062849...

result:

wrong answer 10th lines differ - expected: '579188534', found: '1067434241'

Subtask #3:

score: 0
Wrong Answer

Test #4:

score: 0
Wrong Answer
time: 16ms
memory: 121952kb

input:

1834 1935
-32669453 -670047955 -534537788 80759807 -678610903 -5993655 476471070 90341342 -187206225 -710992660 -837284426 -844649722 -846473433 123470247 177108533 -821700607 97488160 171075677 -146656769 -775261735 -464781034 -518041912 -668027329 -286982559 -108624782 483720318 -632815034 -881243...

output:

1137782164
774147943
1279874032
1267995234
1689668080
1279874032
893115370
1689668080
1279874032
1294914714
697506760
998636635
712660432
1689668080
1137805811
786895412
1137805811
1294914714
1137805811
1294914714
1137782164
1279874032
1137782164
10445269872
10445269872
10445269872
10445269872
10445...

result:

wrong answer 37th lines differ - expected: '344174555328', found: '344379059447'

Subtask #4:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 7ms
memory: 123636kb

input:

1893 1857
-575490410 -790871182 -488011488 -321041425 238235943 262471772 -469848975 -105728328 62479104 19449896 54374656 91107269 125781673 251316981 -264727698 -933332817 315892884 -117300817 -826569250 -156322407 -109499160 202312868 264008468 -814436982 -431822419 -791224962 -67966257 407973223...

output:

936342527
1833261811
1833261811
1833261811
1073428714
1833261811
1073428714
1833261811
1833261811
1833261811
1833261811
1833261811
1762929123
1073428714
1833261811
1833261811
12232324898
61547147263
45295265069
61547147263
444826397143
58754678356
622444335
84858166293
177385934237
403965408013
5827...

result:

wrong answer 24th lines differ - expected: '84132616330', found: '84858166293'

Subtask #5:

score: 5
Accepted

Test #7:

score: 5
Accepted
time: 82ms
memory: 130704kb

input:

97140 97922
75593863 -269004770 -675918045 472330615 -528175962 -580254086 -951270301 -544120385 -525052964 83784128 -226029062 -845875377 34756691 -952920941 -135400084 -20027657 -106558944 -855126948 46245866 -27672459 57802322 -834704313 -625678818 477028623 -9764793 -562713509 477554293 -7238437...

output:

1901808402
2589864136
2615472062
1901808402
2703782432
2703782432
2615472062
2615472062
2615472062
2067055974
2703782432
2615472062
2615472062
2615472062
2615472062
421081808
2615472062
1883490541
1883490541
2441176212
2067055974
2020462870
2615472062
2703782432
2441176212
2703782432
2299923583
2441...

result:

ok 48670 lines

Subtask #6:

score: 5
Accepted

Test #8:

score: 5
Accepted
time: 149ms
memory: 130564kb

input:

97981 186115
-226252189 -571234361 62844820 434180550 269963453 329910638 -847454849 112774660 -178914951 71306715 -859266500 -339120598 -962299988 -157196500 125308122 -668295657 -761232762 165342869 134196398 -767235541 -384052757 -305824813 199376354 226477587 -678798649 -885355596 -979742822 -84...

output:

1819183608
2495542993
2495542993
2084102650
2495542993
2220231814
2495542993
2220231814
2293866611
1927092471
1739879062
2495542993
2495542993
1923181637
2220231814
1494640322
2220231814
2495542993
1927092471
2495542993
1881136236
2495542993
2495542993
2495542993
2112346048
2495542993
2495542993
222...

result:

ok 92966 lines

Subtask #7:

score: 5
Accepted

Test #9:

score: 5
Accepted
time: 159ms
memory: 130632kb

input:

100000 200000
-372870627 -42874740 -537215664 -906588913 -835034566 -406645490 -54474616 -38917607 467210345 -993351739 450345098 12085867 -344729277 -480989044 388326288 -297525580 -259462382 -224591683 -948514660 -494880819 -13589765 -249884145 -387021275 471618602 291976233 358261225 -268906305 1...

output:

1841236083
2463913756
3170394596
3170394596
2463913756
2747069068
3170394596
3170394596
2747069068
3170394596
3170394596
3170394596
1875295477
2747069068
3170394596
3170394596
1868323991
2514664161
3170394596
2514664161
3170394596
3170394596
3170394596
3170394596
3170394596
1914135908
2747069068
317...

result:

ok 99715 lines

Subtask #8:

score: 5
Accepted

Test #10:

score: 5
Accepted
time: 159ms
memory: 128508kb

input:

100000 200000
144608435 -87274600 -974677350 -100352489 -649030362 -39453096 289447879 -537852584 -94574777 337360089 -199669378 -850160928 -298263608 -591161493 231532575 -573617469 -439297426 260642811 425094445 300764130 -476717856 -965323290 102381102 113958066 -683059518 -390842776 -444568945 -...

output:

1949383025
2089788051
2217473154
2317971860
2217473154
2217473154
2109029972
1313420784
2317971860
2217473154
2317971860
2109029972
2317971860
2317971860
2080688479
2317971860
1572475396
2317971860
2109029972
2217473154
2089788051
2317971860
2109029972
1947887794
2109029972
1969937655
2317971860
210...

result:

ok 100024 lines

Subtask #9:

score: 5
Accepted

Test #11:

score: 5
Accepted
time: 152ms
memory: 130576kb

input:

100000 200000
21871390 -860420857 -462213415 -669025807 -260713612 225198084 387180573 31901468 -79466646 -251439643 -593680453 -56298015 -436840232 -277416623 -606833369 311445607 -468196483 -819533304 417838981 -448959219 -517533939 -295117724 -255342449 -218817100 264166786 258541865 7382813 -268...

output:

1689797409
2687069651
2019825451
1806609143
2019825451
3385030765
3385030765
2687069651
3385030765
2758502704
3385030765
3385030765
3385030765
2019825451
2758502704
3385030765
3385030765
2758502704
3385030765
2185444656
2758502704
3385030765
2687069651
3385030765
3385030765
3385030765
3385030765
338...

result:

ok 100081 lines

Test #12:

score: 0
Accepted
time: 163ms
memory: 130580kb

input:

100000 200000
-401401250 -885857116 410723463 -244305377 -25591488 407803305 219938653 -783240987 -225715768 218449074 -899907600 -151354935 -308711466 -10853978 -65937459 86760080 -451157162 -268769676 -510520098 -776019619 -571358783 -152612168 56347434 -532914379 -128957552 -514831396 282407029 4...

output:

2186441814
2362563927
1717698691
2362563927
2362563927
2187267852
2464889211
2325212535
2187267852
2362563927
1561958126
2362563927
1830826681
2362563927
2362563927
2186441814
1999929173
2325212535
1904167572
2325212535
2464889211
2325212535
2362563927
1906990190
2362563927
2362563927
2378323268
236...

result:

ok 100332 lines

Subtask #10:

score: 0
Time Limit Exceeded

Test #13:

score: 0
Time Limit Exceeded

input:

95517 191795
-725239261 -299498656 71286270 -594521669 192006852 271302895 182213759 -447983665 496646313 364428830 141890698 -582020559 102214817 -223415363 -502837969 -762043847 -607694704 -229708001 6321315 240383244 -776743439 193648400 -974528015 44096904 -785689867 -185689539 -492379003 289140...

output:

2554548427
2554548427
2554548427
2554548427
2571377320
2571377320
2571377320
2571377320
2571377320
2571377320
2571377320
2571377320
2571377320
2571377320
2571377320
70139131164484
70139131164484
70139131164484
70139131164484
70139131164484
74002136382027
74266295950255
74856316077338
74953471508064
...

result:


Subtask #11:

score: 0
Time Limit Exceeded

Test #14:

score: 0
Time Limit Exceeded

input:

100000 200000
135797954 -138947496 -406182714 438477901 -267057521 -232444211 130630377 -317348655 37833748 -981372450 246923545 -803068401 216077120 233292050 -267523089 -630927369 -922280156 302142108 -175654796 -464364140 -534375053 -118878135 445980692 -371294038 -797139239 -631637350 418273018 ...

output:

3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
3220264508
322...

result:


Subtask #12:

score: 0
Time Limit Exceeded

Test #15:

score: 0
Time Limit Exceeded

input:

100000 200000
-924767382 -769781514 144232383 -995460305 274241911 -591199999 -462371403 -736028436 -723144279 204535592 -76117810 136712480 197266266 301370706 -157194236 -533948187 439155758 458743159 -856515801 -189489725 -57278555 -20198384 445455871 272093273 -231072195 212372946 245905921 7066...

output:

2749251676
2749251676
2749251676
2749251676
2749251676
2749251676
2749251676
2749251676
5480532221038
5480532221038
5480532221038
5480532221038
5480532221038
5480532221038
5480532221038
5480532221038
5587789693912
5613148834437
5613148834437
5613148834437
5613148834437
5613148834437
5613148834437
56...

result:


Subtask #13:

score: 0
Time Limit Exceeded

Test #16:

score: 0
Time Limit Exceeded

input:

100000 200000
388142692 -345061796 393830628 210472351 75607734 -959422668 -800026188 -960077632 -668437004 -754515329 -307441856 192254236 -451503349 -536240240 376753194 131296191 -966349165 -144012934 -795609529 -4772916 -149566306 -97856138 -913369907 -924695033 20622624 -474639442 283572561 -95...

output:

3110564098
3110564098
3110564098
3110564098
3110564098
3110564098
3110564098
3110564098
3110564098
3110564098
3110564098
19251662950608
19258512649019
19318341830966
19318341830966
19329949813319
19296570165080
19334688832578
19334688832578
19334688832578
19334688832578
19315255625364
19330138493132...

result:


Subtask #14:

score: 0
Time Limit Exceeded

Test #18:

score: 0
Time Limit Exceeded

input:

93028 91818
-295735337 -564744068 -902605531 62391852 -365321307 -603557247 -717081598 162329592 -971363607 247538774 -216804827 -289183462 -770010287 -248152826 -606594806 -23136252 -879560984 -602010879 93750090 -229236489 -647166389 -320819399 -527809250 -999279828 -143001985 -227646820 -49727247...

output:

1903996022
2730626954
2730626954
2730626954
2730626954
2730626954
2730626954
2514281855
2435627856
1675159444
2730626954
2136750003
2488717432
2730626954
2514281855
283119864
2730626954
2730626954
1903996022
2435627856
2488717432
2488717432
6681582669844
2043020481
2488717432
2221716936
584796621430...

result:


Subtask #15:

score: 0
Time Limit Exceeded

Test #19:

score: 0
Time Limit Exceeded

input:

91507 95839
-23664684 -962845837 -26368215 326675641 -724479 499137961 -879329828 -484112881 -891925211 -24962093 291998659 -444033146 -469035647 215328625 78544430 235825511 -873452291 367590693 -588338012 -64562533 243308218 -90161552 107801329 -540773420 -957858728 -963156371 456254393 -455576987...

output:

1784552270
3394268345
2175108698
3394268345
2087565982
2020894702
2087565982
2175108698
2175108698
2175108698
2020894702
2175108698
2044820932
2087565982
2012110730
2175108698
2175108698
2175108698
3394268345
2175108698
2175108698
2175108698
1941396248
2175108698
2044820932
2087936317
1650947749
206...

result:


Subtask #16:

score: 0
Time Limit Exceeded

Test #20:

score: 0
Time Limit Exceeded

input:

94402 181505
-575507596 154582735 -580773807 -76942222 -218416229 -420520457 -603882856 -579269638 -968806749 -330938819 -594039411 -853624581 12356239 -335972976 -715519332 -115758740 -139424484 145442017 -586731895 -524655417 62044280 447562515 112543550 286412994 -755863775 -964258126 258612618 -...

output:

2156322198
1515475393
1897346487
1515475393
2277939806
1515475393
2717536602
2717536602
2717536602
27702659791206
2717536602
18946697813541
9080369490069
1595703981
9245673329882
21852861673102
25985908221269
7391725521971
28116958829831
27980635668641
6280442455318
691039452507
4420631357351
111374...

result:


Subtask #17:

score: 0
Time Limit Exceeded

Test #21:

score: 0
Time Limit Exceeded

input:

97097 197748
-39532660 72924140 -860212972 266724148 -102927196 -536320064 -542895316 -6951259 -451165977 -563012023 -878017150 234956088 -821084308 70082632 103670556 -550194976 5890742 -374521897 -291211030 -189582599 -532780350 153646292 481408375 -522692696 4914802 144236997 -554911116 209552098...

output:

2374171709
2152295655
2773590811
2773590811
2509505436
2509505436
2509505436
1539073381
2152295655
2255388437
2807998903
2807998903
2807998903
2807998903
2807998903
2807998903
2807998903
2136488417
2110104123
2152295655
2255388437
1182776031462
394379349507
2145508281
2255388437
1849117227563
307380...

result:


Subtask #18:

score: 0
Time Limit Exceeded

Test #22:

score: 0
Time Limit Exceeded

input:

100000 200000
124057764 -95019391 -978000572 221124832 352671144 -189215640 -621389420 -576096799 -860592121 282165011 443560050 4236897 -184072665 -157472860 451941374 -94913773 -40873747 6340470 -178064909 7793037 -811205774 260938388 129013318 -867099913 -258095930 110791678 139837296 -88254587 -...

output:

2850239691
1721346319
2152894836
2850239691
2679459632
2679459632
1721346319
2850239691
2679459632
2275028400
2679459632
2275028400
2679459632
2850239691
2399788064
1119450722729
2213972902552
859358493471
1494241517868
2213972902552
952766881738
1155367648364
43066851828
2333695273031
377998921966
...

result:


Subtask #19:

score: 0
Time Limit Exceeded

Test #23:

score: 0
Time Limit Exceeded

input:

100000 200000
-613945542 -776631594 -426750433 204865476 -956716144 289199620 -415317595 -88687071 -31304858 341801980 -657704863 -153593964 -334118199 -544077510 -801376065 -371865322 -829707245 -144589260 -231246860 -393207796 -260603663 195684150 118550317 -165300622 -770784867 -315971863 -518967...

output:

3010106070
1721382511
2080111992
1915159490632
265779822185
3010106070
3010106070
136039857737
854998796399
724672088
1570397857955
336882061494
3010106070
1707688700595
3010106070
3010106070
255020258132
1210678790305
1480137041162
2080111992
1410020760176
1919654476
729008748011
1941807890088
8463...

result:


Subtask #20:

score: 0
Time Limit Exceeded

Test #24:

score: 0
Time Limit Exceeded

input:

100000 200000
-839752687 193465364 -320699181 364320507 491503148 58174453 -204127703 -818328812 -374166865 -186497314 -99589760 355057503 107437758 101726988 341975032 -881462802 272573187 -493611511 27393952 60635930 94215380 64708383 -472618291 -712265364 -520878214 -426679966 347269993 52124326 ...

output:

1982457074
2200495086
2149209979
2290312575
2290312575
2678047382
142526198308
1969960056
364171120161
385255607693
729277108237
1247489149
2678047382
2380156438
9197565576
194976451212
771728964874
2237836949
354068259392
156383839127
2097250739450
192202511046
4879746832666
4359945481530
291477005...

result: