Submission #1088556

# Submission time Handle Problem Language Result Execution time Memory
1088556 2024-09-14T15:25:04 Z vjudge1 Progression (NOI20_progression) C++17
100 / 100
1098 ms 122196 KB
#include<bits/stdc++.h>
#define taskname ""
#define el '\n'
#define fi first
#define sc second
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define int ll
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
#define Faster ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int maxn=3e5+3;
const int INF=LLONG_MAX;
int n,q,a[maxn],b[maxn];
struct segtree
{
    int sett[4*maxn],add[4*maxn],mul[4*maxn];
    void cons(int id,int cl,int cr)
    {
        if(cl==cr)
        {
            sett[id]=a[cl];
            add[id]=0;
            mul[id]=0;
            return;
        }
        int mid=(cl+cr)/2;
        cons(2*id,cl,mid);
        cons(2*id+1,mid+1,cr);
        add[id]=mul[id]=0;
        sett[id]=INF;
    }
    void down(int id)
    {
        if(sett[id]!=INF)
        {
            sett[2*id]=sett[id*2+1]=sett[id];
            add[2*id]=add[id*2+1]=0;
            mul[2*id]=mul[id*2+1]=0;
            sett[id]=INF;
        }
        add[id*2]+=add[id];
        add[id*2+1]+=add[id];
        add[id]=0;
        mul[id*2]+=mul[id];
        mul[id*2+1]+=mul[id];
        mul[id]=0;
    }
    void updateset(int id,int cl,int cr,int l,int r,int val)
    {
        if(cl>r||cr<l) return;
        if(cl>=l&&cr<=r)
        {
            sett[id]=val;
            add[id]=0;
            mul[id]=0;
            return;
        }
        int mid=(cl+cr)/2;
        down(id);
        updateset(2*id,cl,mid,l,r,val);
        updateset(2*id+1,mid+1,cr,l,r,val);
    }
    void updateadd(int id,int cl,int cr,int l,int r,int val)
    {
        if(cl>r||cr<l) return;
        if(cl>=l&&cr<=r)
        {
            add[id]+=val;
            return;
        }
        int mid=(cl+cr)/2;
        down(id);
        updateadd(2*id,cl,mid,l,r,val);
        updateadd(2*id+1,mid+1,cr,l,r,val);
    }
    void updatemul(int id,int cl,int cr,int l,int r,int val)
    {
        if(cl>r||cr<l) return;
        if(cl>=l&&cr<=r)
        {
            mul[id]+=val;
            return;
        }
        int mid=(cl+cr)/2;
        down(id);
        updatemul(2*id,cl,mid,l,r,val);
        updatemul(2*id+1,mid+1,cr,l,r,val);
    }
    int get(int id,int cl,int cr,int pos)
    {
        if(cl==cr)
        {
//            if(sett[id]==INF) return add[id]+pos*mul[id];
            return sett[id]+add[id]+pos*mul[id];
        }
        int mid=(cl+cr)/2;
        down(id);
        if(pos<=mid) return get(2*id,cl,mid,pos);
        else return get(2*id+1,mid+1,cr,pos);
    }
}f;
struct node
{
    pii pre,suf,opt;
    int l;
};
node operator +(node a,node b)
{
    node res;
    res.l=a.l+b.l;
    if(a.l==0) return b;
    if(b.l==0) return a;
    if(a.pre.sc==a.l&&(a.pre.fi==b.pre.fi))
    {
        res.pre={a.pre.fi,a.l+b.pre.sc};
    }
    else res.pre=a.pre;
    if(b.suf.sc==b.l&&(b.suf.fi==a.suf.fi))
    {
        res.suf={b.suf.fi,b.l+a.suf.sc};
    }
    else res.suf=b.suf;
    res.opt=a.opt;
    if(res.opt.sc<b.opt.sc) res.opt=b.opt;
    if(a.suf.fi==b.pre.fi)
    {
        if(a.suf.sc+b.pre.sc>res.opt.sc)
        {
            res.opt={a.suf.fi,a.suf.sc+b.pre.sc};
        }
    }
    return res;
}
struct seggtree
{
    node ST[4*maxn];
    int laz[4*maxn],add[maxn*4];
    void down(int id)
    {
        if(laz[id]!=INF)
        {
            laz[id*2]=laz[id];
            laz[id*2+1]=laz[id];
            ST[id*2]={{laz[id],ST[id*2].l},{laz[id],ST[id*2].l},{laz[id],ST[id*2].l},ST[id*2].l};
            ST[id*2+1]={{laz[id],ST[id*2+1].l},{laz[id],ST[id*2+1].l},{laz[id],ST[id*2+1].l},ST[id*2+1].l};
            add[id*2]=add[2*id+1]=0;
            laz[id]=INF;
        }
        {
            ST[id*2].pre.fi+=add[id];
            ST[id*2].opt.fi+=add[id];
            ST[id*2].suf.fi+=add[id];
            ST[id*2+1].pre.fi+=add[id];
            ST[id*2+1].opt.fi+=add[id];
            ST[id*2+1].suf.fi+=add[id];
            add[2*id]+=add[id];
            add[2*id+1]+=add[id];
            add[id]=0;
        }
    }
    void cons(int id,int cl,int cr)
    {
        if(cl==cr)
        {
            ST[id]={{b[cl],1},{b[cl],1},{b[cl],1},1};
            laz[id]=b[cl];
            return;
        }
        int mid=(cl+cr)/2;
        cons(2*id,cl,mid);
        cons(2*id+1,mid+1,cr);
        ST[id]=ST[id*2]+ST[id*2+1];
        laz[id]=INF;
    }
    void update(int id,int cl,int cr,int l,int r,int val)
    {
        if(cl>r||cr<l) return;
        if(cl>=l&&cr<=r)
        {
            ST[id].opt.fi+=val;
            ST[id].pre.fi+=val;
            ST[id].suf.fi+=val;
            add[id]+=val;
            return;
        }
        int mid=(cl+cr)/2;
        down(id);
        update(2*id,cl,mid,l,r,val);
        update(2*id+1,mid+1,cr,l,r,val);
        ST[id]=ST[id*2]+ST[id*2+1];
    }
    void rupdate(int id,int cl,int cr,int l,int r,int val)
    {
        if(cl>r||cr<l) return;
        if(cl>=l&&cr<=r)
        {
            laz[id]=val;
            add[id]=0;
            ST[id]={{laz[id],ST[id].l},{laz[id],ST[id].l},{laz[id],ST[id].l},ST[id].l};
            return;
        }
        int mid=(cl+cr)/2;
        down(id);
        rupdate(2*id,cl,mid,l,r,val);
        rupdate(2*id+1,mid+1,cr,l,r,val);
        ST[id]=ST[id*2]+ST[id*2+1];
    }
    node get(int id,int cl,int cr,int l,int r)
    {
        if(cl>r||cr<l) return {{0,0},{0,0},{0,0},0};
        if(cl>=l&&cr<=r) return ST[id];
        int mid=(cl+cr)/2;
        down(id);
        node siu=get(2*id,cl,mid,l,r)+get(2*id+1,mid+1,cr,l,r);
        return siu;
    }
}g;
signed main()
{
    if (fopen(taskname".INP","r"))
    {
        freopen(taskname".INP","r",stdin);
        freopen(taskname".OUT","w",stdout);
    }
    Faster
    cin>>n>>q;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        b[i]=a[i]-a[i-1];
    }
    f.cons(1,1,n);
    g.cons(1,1,n);
    for(int i=1;i<=q;i++)
    {
        int t,l,r,s,c;
        cin>>t;
        if(t==1)
        {
            cin>>l>>r>>s>>c;
            g.update(1,1,n,l,l,s);
            if(r<n) g.update(1,1,n,r+1,r+1,-(s+c*(r-l)));
            g.update(1,1,n,l+1,r,c);
            f.updateadd(1,1,n,l,r,s-l*c);
            f.updatemul(1,1,n,l,r,c);
            if(n<=1000)
            {
                for(int j=l;j<=r;j++)
                {
                    a[j]+=s+(j-l)*c;
                }
            }
        }
        else if(t==2)
        {
            cin>>l>>r>>s>>c;
            int xx;
            if(l>1)
            {
                xx=f.get(1,1,n,l-1);
                if(n<=1000) xx=a[l-1];
                g.rupdate(1,1,n,l,l,s-xx);
            }
            if(r<n)
            {
                xx=f.get(1,1,n,r+1);
                if(n<=1000) xx=a[r+1];
                g.rupdate(1,1,n,r+1,r+1,xx-(s+(r-l)*c));
            }
            g.rupdate(1,1,n,l+1,r,c);
            f.updateset(1,1,n,l,r,s-l*c);
            f.updatemul(1,1,n,l,r,c);
            if(n<=1000)
            {
                for(int j=l;j<=r;j++)
                {
                    a[j]=s+(j-l)*c;
                }
            }
        }
        else
        {
            cin>>l>>r;
            if(l==r) cout<<1<<"\n";
            else
            {
                node siu=g.get(1,1,n,l+1,r);
                cout<<siu.opt.sc+1<<"\n";
            }

        }
    }

}

Compilation message

Progression.cpp: In function 'int main()':
Progression.cpp:226:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  226 |         freopen(taskname".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Progression.cpp:227:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  227 |         freopen(taskname".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 339 ms 112208 KB Output is correct
2 Correct 142 ms 69460 KB Output is correct
3 Correct 154 ms 69588 KB Output is correct
4 Correct 140 ms 69456 KB Output is correct
5 Correct 145 ms 69460 KB Output is correct
6 Correct 151 ms 69456 KB Output is correct
7 Correct 143 ms 69404 KB Output is correct
8 Correct 25 ms 66132 KB Output is correct
9 Correct 24 ms 66136 KB Output is correct
10 Correct 25 ms 66140 KB Output is correct
11 Correct 361 ms 112180 KB Output is correct
12 Correct 341 ms 112300 KB Output is correct
13 Correct 358 ms 112536 KB Output is correct
14 Correct 352 ms 112724 KB Output is correct
15 Correct 343 ms 112460 KB Output is correct
16 Correct 341 ms 112212 KB Output is correct
17 Correct 332 ms 112212 KB Output is correct
18 Correct 330 ms 112212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 66140 KB Output is correct
2 Correct 22 ms 66092 KB Output is correct
3 Correct 23 ms 66140 KB Output is correct
4 Correct 23 ms 66072 KB Output is correct
5 Correct 22 ms 66136 KB Output is correct
6 Correct 22 ms 66140 KB Output is correct
7 Correct 22 ms 66392 KB Output is correct
8 Correct 23 ms 66140 KB Output is correct
9 Correct 23 ms 66208 KB Output is correct
10 Correct 23 ms 66140 KB Output is correct
11 Correct 23 ms 66136 KB Output is correct
12 Correct 23 ms 66140 KB Output is correct
13 Correct 22 ms 66140 KB Output is correct
14 Correct 22 ms 66128 KB Output is correct
15 Correct 23 ms 66220 KB Output is correct
16 Correct 23 ms 66132 KB Output is correct
17 Correct 23 ms 66136 KB Output is correct
18 Correct 23 ms 66216 KB Output is correct
19 Correct 22 ms 66084 KB Output is correct
20 Correct 22 ms 66132 KB Output is correct
21 Correct 24 ms 66140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 318 ms 118868 KB Output is correct
2 Correct 104 ms 68944 KB Output is correct
3 Correct 108 ms 68692 KB Output is correct
4 Correct 92 ms 68688 KB Output is correct
5 Correct 103 ms 68948 KB Output is correct
6 Correct 104 ms 69016 KB Output is correct
7 Correct 103 ms 68944 KB Output is correct
8 Correct 24 ms 66140 KB Output is correct
9 Correct 22 ms 66196 KB Output is correct
10 Correct 25 ms 66136 KB Output is correct
11 Correct 347 ms 117588 KB Output is correct
12 Correct 305 ms 118864 KB Output is correct
13 Correct 333 ms 117588 KB Output is correct
14 Correct 346 ms 117516 KB Output is correct
15 Correct 298 ms 118868 KB Output is correct
16 Correct 327 ms 119376 KB Output is correct
17 Correct 332 ms 119380 KB Output is correct
18 Correct 368 ms 119636 KB Output is correct
19 Correct 327 ms 118868 KB Output is correct
20 Correct 322 ms 118952 KB Output is correct
21 Correct 340 ms 119120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 796 ms 121680 KB Output is correct
2 Correct 166 ms 69336 KB Output is correct
3 Correct 166 ms 69580 KB Output is correct
4 Correct 176 ms 69528 KB Output is correct
5 Correct 171 ms 69456 KB Output is correct
6 Correct 176 ms 69456 KB Output is correct
7 Correct 180 ms 69616 KB Output is correct
8 Correct 24 ms 66140 KB Output is correct
9 Correct 22 ms 66052 KB Output is correct
10 Correct 25 ms 66208 KB Output is correct
11 Correct 702 ms 118612 KB Output is correct
12 Correct 692 ms 121680 KB Output is correct
13 Correct 745 ms 118380 KB Output is correct
14 Correct 747 ms 118404 KB Output is correct
15 Correct 727 ms 121552 KB Output is correct
16 Correct 776 ms 121648 KB Output is correct
17 Correct 809 ms 121680 KB Output is correct
18 Correct 767 ms 121608 KB Output is correct
19 Correct 730 ms 121480 KB Output is correct
20 Correct 707 ms 121424 KB Output is correct
21 Correct 681 ms 121516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 318 ms 118868 KB Output is correct
2 Correct 104 ms 68944 KB Output is correct
3 Correct 108 ms 68692 KB Output is correct
4 Correct 92 ms 68688 KB Output is correct
5 Correct 103 ms 68948 KB Output is correct
6 Correct 104 ms 69016 KB Output is correct
7 Correct 103 ms 68944 KB Output is correct
8 Correct 24 ms 66140 KB Output is correct
9 Correct 22 ms 66196 KB Output is correct
10 Correct 25 ms 66136 KB Output is correct
11 Correct 347 ms 117588 KB Output is correct
12 Correct 305 ms 118864 KB Output is correct
13 Correct 333 ms 117588 KB Output is correct
14 Correct 346 ms 117516 KB Output is correct
15 Correct 298 ms 118868 KB Output is correct
16 Correct 327 ms 119376 KB Output is correct
17 Correct 332 ms 119380 KB Output is correct
18 Correct 368 ms 119636 KB Output is correct
19 Correct 327 ms 118868 KB Output is correct
20 Correct 322 ms 118952 KB Output is correct
21 Correct 340 ms 119120 KB Output is correct
22 Correct 866 ms 120996 KB Output is correct
23 Correct 162 ms 69460 KB Output is correct
24 Correct 159 ms 69460 KB Output is correct
25 Correct 159 ms 69456 KB Output is correct
26 Correct 167 ms 69460 KB Output is correct
27 Correct 184 ms 69460 KB Output is correct
28 Correct 166 ms 69460 KB Output is correct
29 Correct 27 ms 66128 KB Output is correct
30 Correct 23 ms 66164 KB Output is correct
31 Correct 23 ms 66140 KB Output is correct
32 Correct 881 ms 118452 KB Output is correct
33 Correct 830 ms 120844 KB Output is correct
34 Correct 877 ms 118452 KB Output is correct
35 Correct 855 ms 118352 KB Output is correct
36 Correct 657 ms 118264 KB Output is correct
37 Correct 641 ms 118260 KB Output is correct
38 Correct 676 ms 118184 KB Output is correct
39 Correct 781 ms 120940 KB Output is correct
40 Correct 797 ms 121168 KB Output is correct
41 Correct 784 ms 121172 KB Output is correct
42 Correct 804 ms 120912 KB Output is correct
43 Correct 821 ms 120912 KB Output is correct
44 Correct 785 ms 120912 KB Output is correct
45 Correct 825 ms 120912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 339 ms 112208 KB Output is correct
2 Correct 142 ms 69460 KB Output is correct
3 Correct 154 ms 69588 KB Output is correct
4 Correct 140 ms 69456 KB Output is correct
5 Correct 145 ms 69460 KB Output is correct
6 Correct 151 ms 69456 KB Output is correct
7 Correct 143 ms 69404 KB Output is correct
8 Correct 25 ms 66132 KB Output is correct
9 Correct 24 ms 66136 KB Output is correct
10 Correct 25 ms 66140 KB Output is correct
11 Correct 361 ms 112180 KB Output is correct
12 Correct 341 ms 112300 KB Output is correct
13 Correct 358 ms 112536 KB Output is correct
14 Correct 352 ms 112724 KB Output is correct
15 Correct 343 ms 112460 KB Output is correct
16 Correct 341 ms 112212 KB Output is correct
17 Correct 332 ms 112212 KB Output is correct
18 Correct 330 ms 112212 KB Output is correct
19 Correct 22 ms 66140 KB Output is correct
20 Correct 22 ms 66092 KB Output is correct
21 Correct 23 ms 66140 KB Output is correct
22 Correct 23 ms 66072 KB Output is correct
23 Correct 22 ms 66136 KB Output is correct
24 Correct 22 ms 66140 KB Output is correct
25 Correct 22 ms 66392 KB Output is correct
26 Correct 23 ms 66140 KB Output is correct
27 Correct 23 ms 66208 KB Output is correct
28 Correct 23 ms 66140 KB Output is correct
29 Correct 23 ms 66136 KB Output is correct
30 Correct 23 ms 66140 KB Output is correct
31 Correct 22 ms 66140 KB Output is correct
32 Correct 22 ms 66128 KB Output is correct
33 Correct 23 ms 66220 KB Output is correct
34 Correct 23 ms 66132 KB Output is correct
35 Correct 23 ms 66136 KB Output is correct
36 Correct 23 ms 66216 KB Output is correct
37 Correct 22 ms 66084 KB Output is correct
38 Correct 22 ms 66132 KB Output is correct
39 Correct 24 ms 66140 KB Output is correct
40 Correct 318 ms 118868 KB Output is correct
41 Correct 104 ms 68944 KB Output is correct
42 Correct 108 ms 68692 KB Output is correct
43 Correct 92 ms 68688 KB Output is correct
44 Correct 103 ms 68948 KB Output is correct
45 Correct 104 ms 69016 KB Output is correct
46 Correct 103 ms 68944 KB Output is correct
47 Correct 24 ms 66140 KB Output is correct
48 Correct 22 ms 66196 KB Output is correct
49 Correct 25 ms 66136 KB Output is correct
50 Correct 347 ms 117588 KB Output is correct
51 Correct 305 ms 118864 KB Output is correct
52 Correct 333 ms 117588 KB Output is correct
53 Correct 346 ms 117516 KB Output is correct
54 Correct 298 ms 118868 KB Output is correct
55 Correct 327 ms 119376 KB Output is correct
56 Correct 332 ms 119380 KB Output is correct
57 Correct 368 ms 119636 KB Output is correct
58 Correct 327 ms 118868 KB Output is correct
59 Correct 322 ms 118952 KB Output is correct
60 Correct 340 ms 119120 KB Output is correct
61 Correct 796 ms 121680 KB Output is correct
62 Correct 166 ms 69336 KB Output is correct
63 Correct 166 ms 69580 KB Output is correct
64 Correct 176 ms 69528 KB Output is correct
65 Correct 171 ms 69456 KB Output is correct
66 Correct 176 ms 69456 KB Output is correct
67 Correct 180 ms 69616 KB Output is correct
68 Correct 24 ms 66140 KB Output is correct
69 Correct 22 ms 66052 KB Output is correct
70 Correct 25 ms 66208 KB Output is correct
71 Correct 702 ms 118612 KB Output is correct
72 Correct 692 ms 121680 KB Output is correct
73 Correct 745 ms 118380 KB Output is correct
74 Correct 747 ms 118404 KB Output is correct
75 Correct 727 ms 121552 KB Output is correct
76 Correct 776 ms 121648 KB Output is correct
77 Correct 809 ms 121680 KB Output is correct
78 Correct 767 ms 121608 KB Output is correct
79 Correct 730 ms 121480 KB Output is correct
80 Correct 707 ms 121424 KB Output is correct
81 Correct 681 ms 121516 KB Output is correct
82 Correct 866 ms 120996 KB Output is correct
83 Correct 162 ms 69460 KB Output is correct
84 Correct 159 ms 69460 KB Output is correct
85 Correct 159 ms 69456 KB Output is correct
86 Correct 167 ms 69460 KB Output is correct
87 Correct 184 ms 69460 KB Output is correct
88 Correct 166 ms 69460 KB Output is correct
89 Correct 27 ms 66128 KB Output is correct
90 Correct 23 ms 66164 KB Output is correct
91 Correct 23 ms 66140 KB Output is correct
92 Correct 881 ms 118452 KB Output is correct
93 Correct 830 ms 120844 KB Output is correct
94 Correct 877 ms 118452 KB Output is correct
95 Correct 855 ms 118352 KB Output is correct
96 Correct 657 ms 118264 KB Output is correct
97 Correct 641 ms 118260 KB Output is correct
98 Correct 676 ms 118184 KB Output is correct
99 Correct 781 ms 120940 KB Output is correct
100 Correct 797 ms 121168 KB Output is correct
101 Correct 784 ms 121172 KB Output is correct
102 Correct 804 ms 120912 KB Output is correct
103 Correct 821 ms 120912 KB Output is correct
104 Correct 785 ms 120912 KB Output is correct
105 Correct 825 ms 120912 KB Output is correct
106 Correct 1031 ms 122160 KB Output is correct
107 Correct 208 ms 69648 KB Output is correct
108 Correct 218 ms 69592 KB Output is correct
109 Correct 203 ms 69460 KB Output is correct
110 Correct 20 ms 66140 KB Output is correct
111 Correct 20 ms 66184 KB Output is correct
112 Correct 20 ms 66140 KB Output is correct
113 Correct 780 ms 121124 KB Output is correct
114 Correct 858 ms 121116 KB Output is correct
115 Correct 877 ms 121060 KB Output is correct
116 Correct 861 ms 121168 KB Output is correct
117 Correct 1098 ms 121984 KB Output is correct
118 Correct 769 ms 121172 KB Output is correct
119 Correct 765 ms 121192 KB Output is correct
120 Correct 335 ms 119736 KB Output is correct
121 Correct 333 ms 119676 KB Output is correct
122 Correct 331 ms 119724 KB Output is correct
123 Correct 329 ms 118868 KB Output is correct
124 Correct 346 ms 118988 KB Output is correct
125 Correct 312 ms 118816 KB Output is correct
126 Correct 1038 ms 118868 KB Output is correct
127 Correct 1073 ms 118800 KB Output is correct
128 Correct 1028 ms 122196 KB Output is correct
129 Correct 1034 ms 118868 KB Output is correct
130 Correct 656 ms 118920 KB Output is correct
131 Correct 734 ms 118760 KB Output is correct
132 Correct 688 ms 118904 KB Output is correct
133 Correct 1058 ms 122192 KB Output is correct
134 Correct 1028 ms 122192 KB Output is correct
135 Correct 1000 ms 122144 KB Output is correct
136 Correct 212 ms 69460 KB Output is correct
137 Correct 213 ms 69456 KB Output is correct
138 Correct 209 ms 69460 KB Output is correct