Submission #901411

# Submission time Handle Problem Language Result Execution time Memory
901411 2024-01-09T12:01:18 Z 12345678 Progression (NOI20_progression) C++17
100 / 100
1049 ms 154652 KB
#include <bits/stdc++.h>

using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

const int nx=3e5+5;
#define ll long long

ll n, q, v[nx], t, l, r, ss, c;

struct gap
{
    ll type, g;
    gap(ll type=0, ll g=0): type(type), g(g){}
    friend bool operator==(const gap &lhs, const gap &rhs) {return lhs.type||rhs.type||lhs.g==rhs.g;}
    friend bool operator!=(const gap &lhs, const gap &rhs) {return !(lhs==rhs);}
};
gap opposite(gap o) { return gap(o.type, -o.g);}

struct segtree
{
    struct node
    {
        gap gapl, gapr;
        ll type, mx, mxl, mxr, vl, vr, sz, lzs, lzc, lzss, lzsc, isset;
        node(ll x=0, ll type=0): type(type), mx(1), mxl(1), mxr(1), vl(x), vr(x), gapl(gap(1)), gapr(gap(1)), sz(1), lzs(0), lzc(0), lzss(0), lzsc(0), isset(0){}
        friend node operator+(const node &lhs, const node &rhs)
        {
            if (lhs.type) return rhs;
            if (rhs.type) return lhs;
            node res=node();
            gap gapl=gap(0, rhs.vl-lhs.vr), gapr=gap(0, lhs.vr-rhs.vl);
            res.vl=lhs.vl;
            res.vr=rhs.vr;
            res.sz=lhs.sz+rhs.sz;
            res.gapl=lhs.gapl.type?gapl:lhs.gapl;
            res.gapr=rhs.gapr.type?gapr:rhs.gapr;
            if (lhs.mxl!=lhs.sz||lhs.gapl!=gapl) res.mxl=lhs.mxl;
            else res.mxl=(gapl==rhs.gapl)?lhs.mxl+rhs.mxl:lhs.mxl+1;
            if (rhs.mxr!=rhs.sz||rhs.gapr!=gapr) res.mxr=rhs.mxr;
            else res.mxr=(gapr==lhs.gapr)?lhs.mxr+rhs.mxr:rhs.mxr+1;
            res.mx=max(lhs.mx, rhs.mx);
            if (opposite(lhs.gapr)==gapl) res.mx=max(res.mx, lhs.mxr+1);
            if (rhs.gapl==gapl) res.mx=max(res.mx, rhs.mxl+1);
            if (opposite(lhs.gapr)==gapl&&gapl==rhs.gapl) res.mx=max(res.mx, lhs.mxr+rhs.mxl);
            return res;
        }
        void set()
        {
            vl=lzss;
            vr=lzss+(sz-1)*lzsc;
            gapl=(sz!=1)?gap(0, lzsc):gap(1);
            gapr=(sz!=1)?gap(0, -lzsc):gap(1);
            mx=mxl=mxr=sz;
        }
        void push()
        {
            vl+=lzs;
            vr+=lzs+lzc*(sz-1);
            gapl.g+=lzc;
            gapr.g-=lzc;
        }
    } d[4*nx];
    void pushlz(int l, int r, int i)
    {
        if (d[i].isset) d[i].set();
        d[i].push();
        if (l==r) return d[i].lzs=d[i].lzc=d[i].lzss=d[i].lzsc=d[i].isset=0, void();
        if (d[i].isset) 
        {
            d[2*i].lzs=d[2*i].lzc=d[2*i+1].lzs=d[2*i+1].lzc=0;
            d[2*i].lzss=d[i].lzss;
            d[2*i+1].lzss=d[i].lzss+d[2*i].sz*d[i].lzsc;
            d[2*i].lzsc=d[2*i+1].lzsc=d[i].lzsc;
            d[2*i].isset=d[2*i+1].isset=1;
        }
        d[2*i].lzs+=d[i].lzs;
        d[2*i].lzc+=d[i].lzc;
        d[2*i+1].lzs+=d[i].lzs+d[2*i].sz*d[i].lzc;
        d[2*i+1].lzc+=d[i].lzc;
        d[i].lzs=d[i].lzc=d[i].lzss=d[i].lzsc=d[i].isset=0;
    }
    void build(int l, int r, int i)
    {
        if (l==r) return void(d[i]=node(v[l], 0));
        int md=(l+r)/2;
        build(l, md, 2*i);
        build(md+1, r, 2*i+1);
        d[i]=d[2*i]+d[2*i+1];
    }
    void update(int l, int r, int i, int ql, int qr, ll s, ll c, bool type)
    {
        pushlz(l, r, i);
        if (qr<l||r<ql) return;
        if (ql<=l&&r<=qr&&!type) return d[i].lzs=s, d[i].lzc=c, pushlz(l, r, i), void();
        if (ql<=l&&r<=qr&&type) return d[i].lzss=s, d[i].lzsc=c, d[i].isset=1, pushlz(l, r, i), void();
        int md=(l+r)/2;
        update(l, md, 2*i, ql, qr, s, c, type);
        update(md+1, r, 2*i+1, ql, qr, s+(md-l+1)*c, c, type);
        d[i]=d[2*i]+d[2*i+1];
    }
    node query(int l, int r, int i, int ql, int qr)
    {
        pushlz(l, r, i);
        if (qr<l||r<ql) return node(0, 1);
        if (ql<=l&&r<=qr) return d[i];
        int md=(l+r)/2;
        return query(l, md, 2*i, ql, qr)+query(md+1, r, 2*i+1, ql, qr);
    }
} s;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>q;
    for (int i=1; i<=n; i++) cin>>v[i];
    s.build(1, n, 1);
    while (q--)
    {
        cin>>t;
        if (t==1) cin>>l>>r>>ss>>c, s.update(1, n, 1, l, r, ss-c*(l-1), c, 0);
        if (t==2) cin>>l>>r>>ss>>c, s.update(1, n, 1, l, r, ss-c*(l-1), c, 1);
        if (t==3) cin>>l>>r, cout<<s.query(1, n, 1, l, r).mx<<'\n';
    }
}

Compilation message

Progression.cpp: In constructor 'segtree::node::node(long long int, long long int)':
Progression.cpp:26:36: warning: 'segtree::node::vr' will be initialized after [-Wreorder]
   26 |         ll type, mx, mxl, mxr, vl, vr, sz, lzs, lzc, lzss, lzsc, isset;
      |                                    ^~
Progression.cpp:25:13: warning:   'gap segtree::node::gapl' [-Wreorder]
   25 |         gap gapl, gapr;
      |             ^~~~
Progression.cpp:27:9: warning:   when initialized here [-Wreorder]
   27 |         node(ll x=0, ll type=0): type(type), mx(1), mxl(1), mxr(1), vl(x), vr(x), gapl(gap(1)), gapr(gap(1)), sz(1), lzs(0), lzc(0), lzss(0), lzsc(0), isset(0){}
      |         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 122 ms 153664 KB Output is correct
2 Correct 81 ms 152712 KB Output is correct
3 Correct 82 ms 152524 KB Output is correct
4 Correct 81 ms 152628 KB Output is correct
5 Correct 82 ms 152628 KB Output is correct
6 Correct 81 ms 152656 KB Output is correct
7 Correct 85 ms 152656 KB Output is correct
8 Correct 19 ms 152412 KB Output is correct
9 Correct 19 ms 152236 KB Output is correct
10 Correct 21 ms 152400 KB Output is correct
11 Correct 133 ms 153592 KB Output is correct
12 Correct 129 ms 153472 KB Output is correct
13 Correct 123 ms 153720 KB Output is correct
14 Correct 124 ms 153776 KB Output is correct
15 Correct 124 ms 153964 KB Output is correct
16 Correct 126 ms 153484 KB Output is correct
17 Correct 125 ms 153484 KB Output is correct
18 Correct 127 ms 153476 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 152412 KB Output is correct
2 Correct 20 ms 152668 KB Output is correct
3 Correct 19 ms 152412 KB Output is correct
4 Correct 21 ms 152332 KB Output is correct
5 Correct 19 ms 152412 KB Output is correct
6 Correct 20 ms 152300 KB Output is correct
7 Correct 20 ms 152308 KB Output is correct
8 Correct 20 ms 152408 KB Output is correct
9 Correct 21 ms 152412 KB Output is correct
10 Correct 21 ms 152412 KB Output is correct
11 Correct 20 ms 152372 KB Output is correct
12 Correct 21 ms 152412 KB Output is correct
13 Correct 20 ms 152412 KB Output is correct
14 Correct 20 ms 152412 KB Output is correct
15 Correct 20 ms 152408 KB Output is correct
16 Correct 21 ms 152412 KB Output is correct
17 Correct 20 ms 152272 KB Output is correct
18 Correct 20 ms 152412 KB Output is correct
19 Correct 20 ms 152412 KB Output is correct
20 Correct 20 ms 152412 KB Output is correct
21 Correct 20 ms 152412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 374 ms 154196 KB Output is correct
2 Correct 112 ms 152916 KB Output is correct
3 Correct 116 ms 153036 KB Output is correct
4 Correct 117 ms 152928 KB Output is correct
5 Correct 111 ms 152916 KB Output is correct
6 Correct 111 ms 152920 KB Output is correct
7 Correct 118 ms 153172 KB Output is correct
8 Correct 20 ms 152408 KB Output is correct
9 Correct 19 ms 152412 KB Output is correct
10 Correct 19 ms 152352 KB Output is correct
11 Correct 450 ms 153764 KB Output is correct
12 Correct 370 ms 154104 KB Output is correct
13 Correct 441 ms 153684 KB Output is correct
14 Correct 443 ms 153736 KB Output is correct
15 Correct 395 ms 153912 KB Output is correct
16 Correct 442 ms 154452 KB Output is correct
17 Correct 475 ms 154432 KB Output is correct
18 Correct 486 ms 154452 KB Output is correct
19 Correct 387 ms 153684 KB Output is correct
20 Correct 407 ms 153872 KB Output is correct
21 Correct 402 ms 153684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 596 ms 153540 KB Output is correct
2 Correct 139 ms 152576 KB Output is correct
3 Correct 151 ms 152608 KB Output is correct
4 Correct 136 ms 152408 KB Output is correct
5 Correct 148 ms 152452 KB Output is correct
6 Correct 141 ms 152524 KB Output is correct
7 Correct 143 ms 152492 KB Output is correct
8 Correct 19 ms 152412 KB Output is correct
9 Correct 20 ms 152412 KB Output is correct
10 Correct 19 ms 152276 KB Output is correct
11 Correct 551 ms 153340 KB Output is correct
12 Correct 541 ms 153328 KB Output is correct
13 Correct 552 ms 153428 KB Output is correct
14 Correct 582 ms 153168 KB Output is correct
15 Correct 524 ms 153228 KB Output is correct
16 Correct 563 ms 153396 KB Output is correct
17 Correct 580 ms 153760 KB Output is correct
18 Correct 582 ms 153364 KB Output is correct
19 Correct 533 ms 153220 KB Output is correct
20 Correct 584 ms 153392 KB Output is correct
21 Correct 541 ms 153428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 374 ms 154196 KB Output is correct
2 Correct 112 ms 152916 KB Output is correct
3 Correct 116 ms 153036 KB Output is correct
4 Correct 117 ms 152928 KB Output is correct
5 Correct 111 ms 152916 KB Output is correct
6 Correct 111 ms 152920 KB Output is correct
7 Correct 118 ms 153172 KB Output is correct
8 Correct 20 ms 152408 KB Output is correct
9 Correct 19 ms 152412 KB Output is correct
10 Correct 19 ms 152352 KB Output is correct
11 Correct 450 ms 153764 KB Output is correct
12 Correct 370 ms 154104 KB Output is correct
13 Correct 441 ms 153684 KB Output is correct
14 Correct 443 ms 153736 KB Output is correct
15 Correct 395 ms 153912 KB Output is correct
16 Correct 442 ms 154452 KB Output is correct
17 Correct 475 ms 154432 KB Output is correct
18 Correct 486 ms 154452 KB Output is correct
19 Correct 387 ms 153684 KB Output is correct
20 Correct 407 ms 153872 KB Output is correct
21 Correct 402 ms 153684 KB Output is correct
22 Correct 717 ms 153492 KB Output is correct
23 Correct 143 ms 152564 KB Output is correct
24 Correct 153 ms 152656 KB Output is correct
25 Correct 152 ms 152660 KB Output is correct
26 Correct 146 ms 152656 KB Output is correct
27 Correct 144 ms 152656 KB Output is correct
28 Correct 143 ms 152636 KB Output is correct
29 Correct 19 ms 152412 KB Output is correct
30 Correct 20 ms 152412 KB Output is correct
31 Correct 22 ms 152412 KB Output is correct
32 Correct 746 ms 153376 KB Output is correct
33 Correct 681 ms 153364 KB Output is correct
34 Correct 727 ms 153704 KB Output is correct
35 Correct 766 ms 153696 KB Output is correct
36 Correct 665 ms 153796 KB Output is correct
37 Correct 648 ms 153732 KB Output is correct
38 Correct 648 ms 153936 KB Output is correct
39 Correct 736 ms 153336 KB Output is correct
40 Correct 742 ms 153492 KB Output is correct
41 Correct 720 ms 153536 KB Output is correct
42 Correct 743 ms 153428 KB Output is correct
43 Correct 702 ms 153428 KB Output is correct
44 Correct 715 ms 153456 KB Output is correct
45 Correct 697 ms 153632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 153664 KB Output is correct
2 Correct 81 ms 152712 KB Output is correct
3 Correct 82 ms 152524 KB Output is correct
4 Correct 81 ms 152628 KB Output is correct
5 Correct 82 ms 152628 KB Output is correct
6 Correct 81 ms 152656 KB Output is correct
7 Correct 85 ms 152656 KB Output is correct
8 Correct 19 ms 152412 KB Output is correct
9 Correct 19 ms 152236 KB Output is correct
10 Correct 21 ms 152400 KB Output is correct
11 Correct 133 ms 153592 KB Output is correct
12 Correct 129 ms 153472 KB Output is correct
13 Correct 123 ms 153720 KB Output is correct
14 Correct 124 ms 153776 KB Output is correct
15 Correct 124 ms 153964 KB Output is correct
16 Correct 126 ms 153484 KB Output is correct
17 Correct 125 ms 153484 KB Output is correct
18 Correct 127 ms 153476 KB Output is correct
19 Correct 21 ms 152412 KB Output is correct
20 Correct 20 ms 152668 KB Output is correct
21 Correct 19 ms 152412 KB Output is correct
22 Correct 21 ms 152332 KB Output is correct
23 Correct 19 ms 152412 KB Output is correct
24 Correct 20 ms 152300 KB Output is correct
25 Correct 20 ms 152308 KB Output is correct
26 Correct 20 ms 152408 KB Output is correct
27 Correct 21 ms 152412 KB Output is correct
28 Correct 21 ms 152412 KB Output is correct
29 Correct 20 ms 152372 KB Output is correct
30 Correct 21 ms 152412 KB Output is correct
31 Correct 20 ms 152412 KB Output is correct
32 Correct 20 ms 152412 KB Output is correct
33 Correct 20 ms 152408 KB Output is correct
34 Correct 21 ms 152412 KB Output is correct
35 Correct 20 ms 152272 KB Output is correct
36 Correct 20 ms 152412 KB Output is correct
37 Correct 20 ms 152412 KB Output is correct
38 Correct 20 ms 152412 KB Output is correct
39 Correct 20 ms 152412 KB Output is correct
40 Correct 374 ms 154196 KB Output is correct
41 Correct 112 ms 152916 KB Output is correct
42 Correct 116 ms 153036 KB Output is correct
43 Correct 117 ms 152928 KB Output is correct
44 Correct 111 ms 152916 KB Output is correct
45 Correct 111 ms 152920 KB Output is correct
46 Correct 118 ms 153172 KB Output is correct
47 Correct 20 ms 152408 KB Output is correct
48 Correct 19 ms 152412 KB Output is correct
49 Correct 19 ms 152352 KB Output is correct
50 Correct 450 ms 153764 KB Output is correct
51 Correct 370 ms 154104 KB Output is correct
52 Correct 441 ms 153684 KB Output is correct
53 Correct 443 ms 153736 KB Output is correct
54 Correct 395 ms 153912 KB Output is correct
55 Correct 442 ms 154452 KB Output is correct
56 Correct 475 ms 154432 KB Output is correct
57 Correct 486 ms 154452 KB Output is correct
58 Correct 387 ms 153684 KB Output is correct
59 Correct 407 ms 153872 KB Output is correct
60 Correct 402 ms 153684 KB Output is correct
61 Correct 596 ms 153540 KB Output is correct
62 Correct 139 ms 152576 KB Output is correct
63 Correct 151 ms 152608 KB Output is correct
64 Correct 136 ms 152408 KB Output is correct
65 Correct 148 ms 152452 KB Output is correct
66 Correct 141 ms 152524 KB Output is correct
67 Correct 143 ms 152492 KB Output is correct
68 Correct 19 ms 152412 KB Output is correct
69 Correct 20 ms 152412 KB Output is correct
70 Correct 19 ms 152276 KB Output is correct
71 Correct 551 ms 153340 KB Output is correct
72 Correct 541 ms 153328 KB Output is correct
73 Correct 552 ms 153428 KB Output is correct
74 Correct 582 ms 153168 KB Output is correct
75 Correct 524 ms 153228 KB Output is correct
76 Correct 563 ms 153396 KB Output is correct
77 Correct 580 ms 153760 KB Output is correct
78 Correct 582 ms 153364 KB Output is correct
79 Correct 533 ms 153220 KB Output is correct
80 Correct 584 ms 153392 KB Output is correct
81 Correct 541 ms 153428 KB Output is correct
82 Correct 717 ms 153492 KB Output is correct
83 Correct 143 ms 152564 KB Output is correct
84 Correct 153 ms 152656 KB Output is correct
85 Correct 152 ms 152660 KB Output is correct
86 Correct 146 ms 152656 KB Output is correct
87 Correct 144 ms 152656 KB Output is correct
88 Correct 143 ms 152636 KB Output is correct
89 Correct 19 ms 152412 KB Output is correct
90 Correct 20 ms 152412 KB Output is correct
91 Correct 22 ms 152412 KB Output is correct
92 Correct 746 ms 153376 KB Output is correct
93 Correct 681 ms 153364 KB Output is correct
94 Correct 727 ms 153704 KB Output is correct
95 Correct 766 ms 153696 KB Output is correct
96 Correct 665 ms 153796 KB Output is correct
97 Correct 648 ms 153732 KB Output is correct
98 Correct 648 ms 153936 KB Output is correct
99 Correct 736 ms 153336 KB Output is correct
100 Correct 742 ms 153492 KB Output is correct
101 Correct 720 ms 153536 KB Output is correct
102 Correct 743 ms 153428 KB Output is correct
103 Correct 702 ms 153428 KB Output is correct
104 Correct 715 ms 153456 KB Output is correct
105 Correct 697 ms 153632 KB Output is correct
106 Correct 907 ms 153828 KB Output is correct
107 Correct 178 ms 152464 KB Output is correct
108 Correct 174 ms 152460 KB Output is correct
109 Correct 175 ms 152720 KB Output is correct
110 Correct 20 ms 152408 KB Output is correct
111 Correct 20 ms 152412 KB Output is correct
112 Correct 19 ms 152280 KB Output is correct
113 Correct 729 ms 153428 KB Output is correct
114 Correct 747 ms 153608 KB Output is correct
115 Correct 739 ms 153940 KB Output is correct
116 Correct 713 ms 153352 KB Output is correct
117 Correct 874 ms 153596 KB Output is correct
118 Correct 727 ms 153428 KB Output is correct
119 Correct 694 ms 153204 KB Output is correct
120 Correct 462 ms 154472 KB Output is correct
121 Correct 455 ms 154448 KB Output is correct
122 Correct 453 ms 154336 KB Output is correct
123 Correct 407 ms 153680 KB Output is correct
124 Correct 390 ms 153684 KB Output is correct
125 Correct 394 ms 154168 KB Output is correct
126 Correct 872 ms 153680 KB Output is correct
127 Correct 891 ms 153680 KB Output is correct
128 Correct 902 ms 153616 KB Output is correct
129 Correct 886 ms 153744 KB Output is correct
130 Correct 765 ms 154340 KB Output is correct
131 Correct 769 ms 154196 KB Output is correct
132 Correct 779 ms 154408 KB Output is correct
133 Correct 887 ms 153684 KB Output is correct
134 Correct 931 ms 153732 KB Output is correct
135 Correct 1049 ms 154400 KB Output is correct
136 Correct 186 ms 154652 KB Output is correct
137 Correct 175 ms 154196 KB Output is correct
138 Correct 177 ms 154300 KB Output is correct