Submission #707062

# Submission time Handle Problem Language Result Execution time Memory
707062 2023-03-08T11:15:02 Z lam Progression (NOI20_progression) C++14
100 / 100
1500 ms 119488 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int inf = (int)1e18;
const int maxn = 3e5 + 10;
int n,m;
int D[maxn];
struct node
{
    int pre,suf,val_l,val_r,sz,ans;
};
node hop(node x, node y)
{
    if (x.val_l==-1e18) return y;
    if (y.val_l==-1e18) return x;
    node cur;
    cur.sz=x.sz+y.sz;
    cur.ans=max(x.ans,y.ans);
    if (x.val_r==y.val_l) cur.ans=max(cur.ans,x.suf+y.pre);
    cur.val_l=x.val_l; cur.val_r=y.val_r;
    cur.pre = x.pre;
    if (x.sz==x.pre&&x.val_r==y.val_l) cur.pre=max(cur.pre,x.sz+y.pre);
    else cur.pre=x.pre;
    cur.suf = y.suf;
    if (y.sz==y.suf&&x.val_r==y.val_l) cur.suf=max(cur.suf,y.sz+x.suf);
    return cur;
}
node none = {0,0,-inf,-inf,0,0};
struct segtree
{
    node f[4*maxn]; int lazysum[4*maxn], lazyeq[4*maxn];
    void pushsum(int x, int lx, int rx, int val)
    {
        f[x].val_l+=val; f[x].val_r+=val;
        lazysum[x]+=val;
    }
    void pusheq(int x, int lx, int rx, int val)
    {
        f[x].val_l=f[x].val_r=lazyeq[x]=val;
        f[x].ans=f[x].pre=f[x].suf=f[x].sz=rx-lx+1;
        lazysum[x]=0;
    }
    void down(int x, int lx, int rx)
    {
        if (lx==rx) return;
        int mid=(lx+rx)/2;
        if (lazyeq[x]!=-1e18)
        {
            pusheq(2*x,lx,mid,lazyeq[x]);
            pusheq(2*x+1,mid+1,rx,lazyeq[x]);
            lazyeq[x]=-1e18;
        }
        if (lazysum[x]!=0)
        {
            pushsum(2*x,lx,mid,lazysum[x]);
            pushsum(2*x+1,mid+1,rx,lazysum[x]);
            lazysum[x]=0;
        }
    }

    void build(int x, int lx, int rx)
    {
        lazysum[x]=0;
        lazyeq[x]=-1e18;
        if (lx==rx)
        {
            pusheq(x,lx,rx,D[lx]-D[lx-1]);
            return;
        }
        int mid=(lx+rx)/2;
        build(2*x,lx,mid); build(2*x+1,mid+1,rx);
        f[x]=hop(f[2*x],f[2*x+1]);
    }

    void add(int x, int lx, int rx, int l, int r, int val)
    {
        if (lx>r||rx<l) return;
        if (lx>=l&&rx<=r)
        {
            pushsum(x,lx,rx,val);
            return;
        }
        int mid=(lx+rx)/2;
        down(x,lx,rx);
        add(2*x,lx,mid,l,r,val);
        add(2*x+1,mid+1,rx,l,r,val);
        f[x]=hop(f[2*x],f[2*x+1]);
    }
    void update_eq(int x, int lx, int rx, int l, int r, int val)
    {
        if (lx>r||rx<l) return;
        if (lx>=l&&rx<=r)
        {
            pusheq(x,lx,rx,val);
            return;
        }
        int mid=(lx+rx)/2;
        down(x,lx,rx);
        update_eq(2*x,lx,mid,l,r,val);
        update_eq(2*x+1,mid+1,rx,l,r,val);
        f[x]=hop(f[2*x],f[2*x+1]);
    }
    void update(int x, int lx, int rx, int idx, int val)
    {
        if (lx==rx)
        {
            pusheq(x,lx,rx,val);
            return;
        }
        int mid=(lx+rx)/2;
        down(x,lx,rx);
        if (idx<=mid) update(2*x,lx,mid,idx,val);
        else update(2*x+1,mid+1,rx,idx,val);
        f[x]=hop(f[2*x],f[2*x+1]);
    }
    node get(int x, int lx, int rx, int l, int r)
    {
        if (lx>r||rx<l) return {0,0,-inf,-inf,0,0};
        if (lx>=l&&rx<=r) return f[x];
        int mid=(lx+rx)/2;
        down(x,lx,rx);
        return hop(get(2*x,lx,mid,l,r),get(2*x+1,mid+1,rx,l,r));
    }
    void dbg(int x, int lx, int rx)
    {
        cout<<x<<' '<<lx<<' '<<rx<<" = "<<f[x].val_l<<' '<<f[x].val_r<<" , "<<f[x].pre<<' '<<f[x].suf<<" , "<<f[x].sz<<' '<<f[x].ans<<'\n';
        if (lx==rx) return;
        int mid=(lx+rx)/2;
        dbg(2*x,lx,mid); dbg(2*x+1,mid+1,rx);
    }
};
segtree tree;
struct line
{
    int a,b;
};
int calc(line x, int idx)
{
    return x.a*idx + x.b;
}
struct lichao_tree
{
    line f[4*maxn],lazysum[4*maxn],lazyeq[4*maxn];
    void pushsum(int x, int lx, int rx, line val)
    {
        f[x].a+=val.a; f[x].b+=val.b;
        lazysum[x].a+=val.a; lazysum[x].b+=val.b;
    }
    void pusheq(int x, int lx, int rx, line val)
    {
        f[x]=lazyeq[x]=val; lazysum[x]={0,0};
    }
    void down(int x, int lx, int rx)
    {
        if (lx==rx) return;
        int mid=(lx+rx)/2;
        if (lazyeq[x].a!=-inf||lazyeq[x].b!=-inf)
        {
            pusheq(2*x,lx,mid,lazyeq[x]);
            pusheq(2*x+1,mid+1,rx,lazyeq[x]);
            lazyeq[x]={-inf,-inf};
        }
        if (lazysum[x].a!=0||lazysum[x].b!=0)
        {
            pushsum(2*x,lx,mid,lazysum[x]);
            pushsum(2*x+1,mid+1,rx,lazysum[x]);
            lazysum[x]={0,0};
        }
    }
    void build(int x, int lx, int rx)
    {
        lazysum[x]={0,0};
        lazyeq[x]={-inf,-inf};
        if (lx==rx)
        {
            pusheq(x,lx,rx,{0,D[lx]});
            return;
        }
        int mid=(lx+rx)/2;
        build(2*x,lx,mid); build(2*x+1,mid+1,rx);
    }
    void add(int x, int lx, int rx, int l, int r, line val)
    {
        if (lx>r||rx<l) return;
        if (lx>=l&&rx<=r)
        {
            pushsum(x,lx,rx,val);
            return;
        }
        int mid=(lx+rx)/2;
        down(x,lx,rx);
        add(2*x,lx,mid,l,r,val);
        add(2*x+1,mid+1,rx,l,r,val);
    }
    void update_eq(int x, int lx, int rx, int l, int r, line val)
    {
        if (lx>r||rx<l) return;
        if (lx>=l&&rx<=r)
        {
            pusheq(x,lx,rx,val);
            return;
        }
        int mid=(lx+rx)/2;
        down(x,lx,rx);
        update_eq(2*x,lx,mid,l,r,val);
        update_eq(2*x+1,mid+1,rx,l,r,val);
    }
    line get(int x, int lx, int rx, int idx)
    {
        if (lx==rx) return f[x];
        int mid=(lx+rx)/2;
        down(x,lx,rx);
        if (idx<=mid) return get(2*x,lx,mid,idx);
        else return get(2*x+1,mid+1,rx,idx);
    }
};
lichao_tree lichao;

void sub1()
{
    for (int i=1; i<=m; i++)
    {
        int t; cin>>t;
        if (t==1||t==2)
        {
            int l,r,x,y; cin>>l>>r>>x>>y;
        }
        else
        {
            int l,r; cin>>l>>r;
            cout<<"1\n";
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin>>n>>m;
    for (int i=1; i<=n; i++) cin>>D[i];
    if (n==1)
    {
        sub1();
        return 0;
    }
    tree.build(1,2,n);
    lichao.build(1,1,n);
    for (int i=1; i<=m; i++)
    {
        int t; cin>>t;
        if (t==1)
        {
            int l,r,S,C; cin>>l>>r>>S>>C;
            line temp = {C,S-l*C};
            tree.add(1,2,n,l+1,r,C);
            lichao.add(1,1,n,l,r,temp);
            if (l>1) tree.update(1,2,n,l,calc(lichao.get(1,1,n,l),l) - calc(lichao.get(1,1,n,l-1),l-1));
            if (r<n) tree.update(1,2,n,r+1,calc(lichao.get(1,1,n,r+1),r+1) - calc(lichao.get(1,1,n,r),r));
        }
        else if (t==2)
        {
            int l,r,S,C; cin>>l>>r>>S>>C;
            line temp = {C,S-l*C};
            tree.update_eq(1,2,n,l+1,r,C);
            lichao.update_eq(1,1,n,l,r,temp);
            if (l>1) tree.update(1,2,n,l,calc(lichao.get(1,1,n,l),l) - calc(lichao.get(1,1,n,l-1),l-1));
            if (r<n) tree.update(1,2,n,r+1,calc(lichao.get(1,1,n,r+1),r+1) - calc(lichao.get(1,1,n,r),r));
        }
        else
        {
            int l,r; cin>>l>>r;
            node ans = tree.get(1,2,n,l+1,r);
            cout<<ans.ans+1<<'\n';
        }
//        tree.dbg(1,2,n);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 155 ms 114496 KB Output is correct
2 Correct 69 ms 976 KB Output is correct
3 Correct 72 ms 976 KB Output is correct
4 Correct 68 ms 892 KB Output is correct
5 Correct 70 ms 976 KB Output is correct
6 Correct 74 ms 2252 KB Output is correct
7 Correct 86 ms 2168 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 162 ms 117228 KB Output is correct
12 Correct 161 ms 117192 KB Output is correct
13 Correct 162 ms 117492 KB Output is correct
14 Correct 158 ms 117552 KB Output is correct
15 Correct 169 ms 117416 KB Output is correct
16 Correct 160 ms 117068 KB Output is correct
17 Correct 163 ms 117064 KB Output is correct
18 Correct 175 ms 117128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 3 ms 596 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 3 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 3 ms 580 KB Output is correct
16 Correct 3 ms 596 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 2 ms 596 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 333 ms 114768 KB Output is correct
2 Correct 97 ms 2344 KB Output is correct
3 Correct 91 ms 2344 KB Output is correct
4 Correct 82 ms 2272 KB Output is correct
5 Correct 94 ms 2392 KB Output is correct
6 Correct 90 ms 2324 KB Output is correct
7 Correct 91 ms 2380 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 354 ms 117056 KB Output is correct
12 Correct 325 ms 117324 KB Output is correct
13 Correct 350 ms 117112 KB Output is correct
14 Correct 327 ms 116964 KB Output is correct
15 Correct 334 ms 117272 KB Output is correct
16 Correct 338 ms 117904 KB Output is correct
17 Correct 339 ms 117680 KB Output is correct
18 Correct 347 ms 117904 KB Output is correct
19 Correct 317 ms 116940 KB Output is correct
20 Correct 311 ms 116808 KB Output is correct
21 Correct 302 ms 116680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 894 ms 114292 KB Output is correct
2 Correct 193 ms 1796 KB Output is correct
3 Correct 193 ms 1636 KB Output is correct
4 Correct 182 ms 1612 KB Output is correct
5 Correct 194 ms 1668 KB Output is correct
6 Correct 187 ms 1636 KB Output is correct
7 Correct 186 ms 1668 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 902 ms 115216 KB Output is correct
12 Correct 897 ms 114956 KB Output is correct
13 Correct 885 ms 114936 KB Output is correct
14 Correct 899 ms 114916 KB Output is correct
15 Correct 885 ms 114584 KB Output is correct
16 Correct 901 ms 114768 KB Output is correct
17 Correct 898 ms 114772 KB Output is correct
18 Correct 897 ms 114752 KB Output is correct
19 Correct 972 ms 114520 KB Output is correct
20 Correct 884 ms 114444 KB Output is correct
21 Correct 893 ms 114460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 333 ms 114768 KB Output is correct
2 Correct 97 ms 2344 KB Output is correct
3 Correct 91 ms 2344 KB Output is correct
4 Correct 82 ms 2272 KB Output is correct
5 Correct 94 ms 2392 KB Output is correct
6 Correct 90 ms 2324 KB Output is correct
7 Correct 91 ms 2380 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 354 ms 117056 KB Output is correct
12 Correct 325 ms 117324 KB Output is correct
13 Correct 350 ms 117112 KB Output is correct
14 Correct 327 ms 116964 KB Output is correct
15 Correct 334 ms 117272 KB Output is correct
16 Correct 338 ms 117904 KB Output is correct
17 Correct 339 ms 117680 KB Output is correct
18 Correct 347 ms 117904 KB Output is correct
19 Correct 317 ms 116940 KB Output is correct
20 Correct 311 ms 116808 KB Output is correct
21 Correct 302 ms 116680 KB Output is correct
22 Correct 1052 ms 119192 KB Output is correct
23 Correct 181 ms 1356 KB Output is correct
24 Correct 174 ms 1396 KB Output is correct
25 Correct 183 ms 1368 KB Output is correct
26 Correct 178 ms 1432 KB Output is correct
27 Correct 177 ms 1356 KB Output is correct
28 Correct 178 ms 1444 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1077 ms 118680 KB Output is correct
33 Correct 1074 ms 118792 KB Output is correct
34 Correct 1173 ms 118736 KB Output is correct
35 Correct 1334 ms 118624 KB Output is correct
36 Correct 929 ms 118952 KB Output is correct
37 Correct 906 ms 118984 KB Output is correct
38 Correct 1092 ms 119084 KB Output is correct
39 Correct 1074 ms 118716 KB Output is correct
40 Correct 1078 ms 118796 KB Output is correct
41 Correct 1064 ms 118760 KB Output is correct
42 Correct 1067 ms 118952 KB Output is correct
43 Correct 1113 ms 118732 KB Output is correct
44 Correct 1130 ms 118552 KB Output is correct
45 Correct 1119 ms 118652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 114496 KB Output is correct
2 Correct 69 ms 976 KB Output is correct
3 Correct 72 ms 976 KB Output is correct
4 Correct 68 ms 892 KB Output is correct
5 Correct 70 ms 976 KB Output is correct
6 Correct 74 ms 2252 KB Output is correct
7 Correct 86 ms 2168 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 162 ms 117228 KB Output is correct
12 Correct 161 ms 117192 KB Output is correct
13 Correct 162 ms 117492 KB Output is correct
14 Correct 158 ms 117552 KB Output is correct
15 Correct 169 ms 117416 KB Output is correct
16 Correct 160 ms 117068 KB Output is correct
17 Correct 163 ms 117064 KB Output is correct
18 Correct 175 ms 117128 KB Output is correct
19 Correct 3 ms 596 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 3 ms 596 KB Output is correct
28 Correct 2 ms 588 KB Output is correct
29 Correct 2 ms 596 KB Output is correct
30 Correct 3 ms 596 KB Output is correct
31 Correct 2 ms 596 KB Output is correct
32 Correct 2 ms 596 KB Output is correct
33 Correct 3 ms 580 KB Output is correct
34 Correct 3 ms 596 KB Output is correct
35 Correct 3 ms 596 KB Output is correct
36 Correct 2 ms 596 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 333 ms 114768 KB Output is correct
41 Correct 97 ms 2344 KB Output is correct
42 Correct 91 ms 2344 KB Output is correct
43 Correct 82 ms 2272 KB Output is correct
44 Correct 94 ms 2392 KB Output is correct
45 Correct 90 ms 2324 KB Output is correct
46 Correct 91 ms 2380 KB Output is correct
47 Correct 1 ms 340 KB Output is correct
48 Correct 1 ms 336 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 354 ms 117056 KB Output is correct
51 Correct 325 ms 117324 KB Output is correct
52 Correct 350 ms 117112 KB Output is correct
53 Correct 327 ms 116964 KB Output is correct
54 Correct 334 ms 117272 KB Output is correct
55 Correct 338 ms 117904 KB Output is correct
56 Correct 339 ms 117680 KB Output is correct
57 Correct 347 ms 117904 KB Output is correct
58 Correct 317 ms 116940 KB Output is correct
59 Correct 311 ms 116808 KB Output is correct
60 Correct 302 ms 116680 KB Output is correct
61 Correct 894 ms 114292 KB Output is correct
62 Correct 193 ms 1796 KB Output is correct
63 Correct 193 ms 1636 KB Output is correct
64 Correct 182 ms 1612 KB Output is correct
65 Correct 194 ms 1668 KB Output is correct
66 Correct 187 ms 1636 KB Output is correct
67 Correct 186 ms 1668 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 902 ms 115216 KB Output is correct
72 Correct 897 ms 114956 KB Output is correct
73 Correct 885 ms 114936 KB Output is correct
74 Correct 899 ms 114916 KB Output is correct
75 Correct 885 ms 114584 KB Output is correct
76 Correct 901 ms 114768 KB Output is correct
77 Correct 898 ms 114772 KB Output is correct
78 Correct 897 ms 114752 KB Output is correct
79 Correct 972 ms 114520 KB Output is correct
80 Correct 884 ms 114444 KB Output is correct
81 Correct 893 ms 114460 KB Output is correct
82 Correct 1052 ms 119192 KB Output is correct
83 Correct 181 ms 1356 KB Output is correct
84 Correct 174 ms 1396 KB Output is correct
85 Correct 183 ms 1368 KB Output is correct
86 Correct 178 ms 1432 KB Output is correct
87 Correct 177 ms 1356 KB Output is correct
88 Correct 178 ms 1444 KB Output is correct
89 Correct 1 ms 340 KB Output is correct
90 Correct 1 ms 340 KB Output is correct
91 Correct 1 ms 344 KB Output is correct
92 Correct 1077 ms 118680 KB Output is correct
93 Correct 1074 ms 118792 KB Output is correct
94 Correct 1173 ms 118736 KB Output is correct
95 Correct 1334 ms 118624 KB Output is correct
96 Correct 929 ms 118952 KB Output is correct
97 Correct 906 ms 118984 KB Output is correct
98 Correct 1092 ms 119084 KB Output is correct
99 Correct 1074 ms 118716 KB Output is correct
100 Correct 1078 ms 118796 KB Output is correct
101 Correct 1064 ms 118760 KB Output is correct
102 Correct 1067 ms 118952 KB Output is correct
103 Correct 1113 ms 118732 KB Output is correct
104 Correct 1130 ms 118552 KB Output is correct
105 Correct 1119 ms 118652 KB Output is correct
106 Correct 1500 ms 118884 KB Output is correct
107 Correct 235 ms 1344 KB Output is correct
108 Correct 229 ms 1304 KB Output is correct
109 Correct 227 ms 1356 KB Output is correct
110 Correct 1 ms 340 KB Output is correct
111 Correct 1 ms 340 KB Output is correct
112 Correct 1 ms 348 KB Output is correct
113 Correct 1087 ms 118716 KB Output is correct
114 Correct 1090 ms 118820 KB Output is correct
115 Correct 1094 ms 118756 KB Output is correct
116 Correct 1043 ms 118804 KB Output is correct
117 Correct 1439 ms 118904 KB Output is correct
118 Correct 1048 ms 118572 KB Output is correct
119 Correct 1036 ms 118640 KB Output is correct
120 Correct 336 ms 115592 KB Output is correct
121 Correct 356 ms 115616 KB Output is correct
122 Correct 327 ms 115548 KB Output is correct
123 Correct 303 ms 115048 KB Output is correct
124 Correct 288 ms 114832 KB Output is correct
125 Correct 308 ms 115092 KB Output is correct
126 Correct 1410 ms 119036 KB Output is correct
127 Correct 1390 ms 119112 KB Output is correct
128 Correct 1383 ms 118800 KB Output is correct
129 Correct 1387 ms 118744 KB Output is correct
130 Correct 861 ms 119272 KB Output is correct
131 Correct 911 ms 119292 KB Output is correct
132 Correct 855 ms 119488 KB Output is correct
133 Correct 1402 ms 118616 KB Output is correct
134 Correct 1383 ms 118564 KB Output is correct
135 Correct 1396 ms 118748 KB Output is correct
136 Correct 222 ms 880 KB Output is correct
137 Correct 220 ms 896 KB Output is correct
138 Correct 227 ms 1004 KB Output is correct