Submission #860170

# Submission time Handle Problem Language Result Execution time Memory
860170 2023-10-12T02:16:15 Z 8pete8 Progression (NOI20_progression) C++14
68 / 100
795 ms 90772 KB
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<algorithm>
#include<limits.h>
#include<cmath>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<pii,int>
#define pb push_back
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#define int long long
#define mod 1000000007
const int mxn=4*1e5,lg=20,inf=1e18;
int n,m;
struct node{
    int as=0,ms=1,ls=0,rs=0,lv=0,rv=0,sum=0;
    //all size, max size, left size,right size,left val,right val;
};
void print(node a){
    cout<<a.as<<" "<<a.ms<<" "<<a.ls<<" "<<a.rs<<" "<<a.lv<<" "<<a.rv<<'\n';
}
node seg[4*mxn+10];
int add[4*mxn+10],change[4*mxn+10],v[mxn+10];
bool yes[4*mxn+10];
int h;//height of tree
node comb(node a,node b){
    node tmp;
    if(a.rv==inf)return b;
    if(b.rv==inf)return a;
    tmp.ms=max(a.ms,b.ms);
    if(a.rv==b.lv)tmp.ms=max(tmp.ms,a.rs+b.ls);
    tmp.lv=a.lv;
    tmp.rv=b.rv;
    if(a.ls==a.as&&b.lv==a.lv)tmp.ls=a.ls+b.ls;
    if(b.rs==b.as&&a.rv==b.rv)tmp.rs=b.rs+a.rs;
    tmp.ls=max(tmp.ls,a.ls);
    tmp.rs=max(tmp.rs,b.rs);
    tmp.as=a.as+b.as;
    tmp.sum=a.sum+b.sum;
    return tmp;
}
void build(int pos,int l,int r){
   // cout<<pos<<" "<<l<<" "<<r<<'\n';
   if(r<l)return;
    if(l==r){
        seg[pos].as=seg[pos].ls=seg[pos].rs=seg[pos].ms=1;
        seg[pos].lv=seg[pos].rv=seg[pos].sum=v[l];
    }
    else{
        int mid=l+(r-l)/2;
        build(pos*2,l,mid);
        build(pos*2+1,mid+1,r);
        seg[pos]=comb(seg[pos<<1],seg[(pos<<1)|1]);
    }
}
void app(int pos){
    if(yes[pos]){
        seg[pos].ms=seg[pos].ls=seg[pos].rs=seg[pos].as;
        seg[pos].lv=seg[pos].rv=change[pos];
        seg[pos].sum=seg[pos].as*change[pos];
    }
    if(add[pos]){
        seg[pos].lv+=add[pos];
        seg[pos].rv+=add[pos];
        seg[pos].sum+=(seg[pos].as*add[pos]);
    }
}
void push(int pos,int l,int r){
    if(add[pos]){
        app(pos);
        if(l!=r){
            add[pos*2]+=add[pos];
            add[pos*2+1]+=add[pos];
        }
    }
    if(yes[pos]){
        app(pos);
        if(l!=r){
            add[pos*2]=0;
            add[pos*2+1]=0;
            yes[pos*2]=true;
            yes[pos*2+1]=true;
            change[pos*2]=change[pos];
            change[pos*2+1]=change[pos];
        }
    }
    add[pos]=0;
    yes[pos]=false;
    change[pos]=0;
}
void update(int pos,int l,int r,int ql,int qr,int val){
    if(r<l)return;
    push(pos,l,r);
    //cout<<pos<<' '<<l<<" "<<r<<' '<<ql<<" "<<qr<<'\n';
    if(r<ql||l>qr)return;
    if(ql<=l&&r<=qr){
        add[pos]+=val;
        push(pos,l,r);
        return;
    }
    int mid=l+(r-l)/2;
    update(pos*2,l,mid,ql,qr,val);
    update(pos*2+1,mid+1,r,ql,qr,val);
    seg[pos]=comb(seg[pos*2],seg[pos*2+1]);
}
void update2(int pos,int l,int r,int ql,int qr,int val){
    push(pos,l,r);
    if(r<l)return;
    if(r<ql||l>qr)return;
    //cout<<pos<<" "<<l<<" "<<r<<" "<<ql<<" "<<qr<<" "<<val<<'\n';
    if(ql<=l&&r<=qr){
        change[pos]=val;
        yes[pos]=true;
        push(pos,l,r);
        return;
    }
    push(pos,l,r);
    int mid=l+(r-l)/2;
    update2(pos*2,l,mid,ql,qr,val);
    update2(pos*2+1,mid+1,r,ql,qr,val);
    seg[pos]=comb(seg[pos<<1],seg[(pos<<1)|1]);
}
node query(int pos,int l,int r,int ql,int qr){
    node tmp;
    tmp.rv=inf;
  	push(pos,l,r);
    if(r<l)return tmp;
    if(r<ql||l>qr)return tmp;
    if(ql<=l&&r<=qr)return seg[pos];
    int mid=l+(r-l)/2;
    if(ql<=mid&&mid<qr)return comb(query(pos*2,l,mid,ql,qr),query(pos*2+1,mid+1,r,ql,qr));
    if(ql<=mid)return query(pos*2,l,mid,ql,qr);
    return query(pos*2+1,mid+1,r,ql,qr);
}
int32_t main(){
    fastio
    int n,m;cin>>n>>m;
    for(int i=0;i<n;i++)cin>>v[i];
    int val=v[0];
    for(int i=0;i<n;i++)v[i]=v[i+1]-v[i];
    build(1,0,n-1);
    int diff;
    while(m--){
        int type;cin>>type;
        if(type==1){
            int l,r,x,c;cin>>l>>r>>x>>c;
            l--,r--;
            if(l)update(1,0,n-1,l-1,l-1,x);
            else val+=x;
            update(1,0,n-1,r,r,-((x+((r-l)*c))));
            if(l!=r)update(1,0,n-1,l,r-1,c);
        }
        else if(type==2){
            int l,r,x,c;cin>>l>>r>>x>>c;
            l--,r--;
            int suml,sumr;
            sumr=query(1,0,n-1,0,r).sum+val;
            diff=sumr-(x+(r-l)*c);
            update2(1,0,n-1,r,r,diff);
            if(l){
                if(l>1)suml=query(1,0,n-1,0,l-2).sum+val;
                else suml=val;
                diff=x-suml;
                update2(1,0,n-1,l-1,l-1,diff);
            }
            else val=x;
            if(l!=r)update2(1,0,n-1,l,r-1,c);
        }
        else{
            int l,r;cin>>l>>r;
            l--;
            r--;
            cout<<((l==r)?0:query(1,0,n-1,l,r-1).ms)+1<<'\n';
        }
    }
 
}
# Verdict Execution time Memory Grader output
1 Correct 346 ms 74836 KB Output is correct
2 Correct 115 ms 7660 KB Output is correct
3 Correct 111 ms 7760 KB Output is correct
4 Correct 113 ms 7760 KB Output is correct
5 Correct 111 ms 7796 KB Output is correct
6 Correct 111 ms 7832 KB Output is correct
7 Correct 108 ms 7760 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 374 ms 74832 KB Output is correct
12 Correct 370 ms 74540 KB Output is correct
13 Correct 373 ms 74848 KB Output is correct
14 Correct 344 ms 75096 KB Output is correct
15 Correct 346 ms 74832 KB Output is correct
16 Correct 366 ms 74732 KB Output is correct
17 Correct 351 ms 74832 KB Output is correct
18 Correct 353 ms 74576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 248 ms 86416 KB Output is correct
2 Correct 67 ms 7256 KB Output is correct
3 Correct 64 ms 7256 KB Output is correct
4 Correct 72 ms 7240 KB Output is correct
5 Correct 68 ms 7248 KB Output is correct
6 Correct 68 ms 7248 KB Output is correct
7 Correct 65 ms 7248 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 268 ms 84720 KB Output is correct
12 Correct 252 ms 86164 KB Output is correct
13 Correct 294 ms 84816 KB Output is correct
14 Correct 289 ms 84808 KB Output is correct
15 Correct 237 ms 86264 KB Output is correct
16 Correct 261 ms 86608 KB Output is correct
17 Correct 268 ms 86608 KB Output is correct
18 Correct 270 ms 87120 KB Output is correct
19 Correct 232 ms 86076 KB Output is correct
20 Correct 267 ms 86096 KB Output is correct
21 Correct 265 ms 86136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 618 ms 89340 KB Output is correct
2 Correct 126 ms 7812 KB Output is correct
3 Correct 132 ms 7864 KB Output is correct
4 Correct 127 ms 7760 KB Output is correct
5 Correct 156 ms 7868 KB Output is correct
6 Correct 138 ms 7760 KB Output is correct
7 Correct 132 ms 7760 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 616 ms 85840 KB Output is correct
12 Correct 633 ms 88888 KB Output is correct
13 Correct 601 ms 85840 KB Output is correct
14 Correct 616 ms 85584 KB Output is correct
15 Correct 580 ms 88780 KB Output is correct
16 Correct 641 ms 88912 KB Output is correct
17 Correct 667 ms 88896 KB Output is correct
18 Correct 620 ms 89168 KB Output is correct
19 Correct 585 ms 88876 KB Output is correct
20 Correct 611 ms 88912 KB Output is correct
21 Correct 598 ms 88912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 248 ms 86416 KB Output is correct
2 Correct 67 ms 7256 KB Output is correct
3 Correct 64 ms 7256 KB Output is correct
4 Correct 72 ms 7240 KB Output is correct
5 Correct 68 ms 7248 KB Output is correct
6 Correct 68 ms 7248 KB Output is correct
7 Correct 65 ms 7248 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 268 ms 84720 KB Output is correct
12 Correct 252 ms 86164 KB Output is correct
13 Correct 294 ms 84816 KB Output is correct
14 Correct 289 ms 84808 KB Output is correct
15 Correct 237 ms 86264 KB Output is correct
16 Correct 261 ms 86608 KB Output is correct
17 Correct 268 ms 86608 KB Output is correct
18 Correct 270 ms 87120 KB Output is correct
19 Correct 232 ms 86076 KB Output is correct
20 Correct 267 ms 86096 KB Output is correct
21 Correct 265 ms 86136 KB Output is correct
22 Correct 731 ms 90336 KB Output is correct
23 Correct 137 ms 7760 KB Output is correct
24 Correct 131 ms 7780 KB Output is correct
25 Correct 131 ms 7804 KB Output is correct
26 Correct 136 ms 7760 KB Output is correct
27 Correct 136 ms 7836 KB Output is correct
28 Correct 148 ms 7760 KB Output is correct
29 Correct 1 ms 4456 KB Output is correct
30 Correct 1 ms 4456 KB Output is correct
31 Correct 1 ms 4440 KB Output is correct
32 Correct 746 ms 85688 KB Output is correct
33 Correct 723 ms 88400 KB Output is correct
34 Correct 791 ms 85600 KB Output is correct
35 Correct 752 ms 85584 KB Output is correct
36 Correct 561 ms 87632 KB Output is correct
37 Correct 571 ms 87376 KB Output is correct
38 Correct 559 ms 87448 KB Output is correct
39 Correct 706 ms 90456 KB Output is correct
40 Correct 772 ms 90452 KB Output is correct
41 Correct 743 ms 90772 KB Output is correct
42 Correct 795 ms 88424 KB Output is correct
43 Correct 730 ms 88524 KB Output is correct
44 Correct 704 ms 88496 KB Output is correct
45 Correct 706 ms 88396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 346 ms 74836 KB Output is correct
2 Correct 115 ms 7660 KB Output is correct
3 Correct 111 ms 7760 KB Output is correct
4 Correct 113 ms 7760 KB Output is correct
5 Correct 111 ms 7796 KB Output is correct
6 Correct 111 ms 7832 KB Output is correct
7 Correct 108 ms 7760 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4440 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 374 ms 74832 KB Output is correct
12 Correct 370 ms 74540 KB Output is correct
13 Correct 373 ms 74848 KB Output is correct
14 Correct 344 ms 75096 KB Output is correct
15 Correct 346 ms 74832 KB Output is correct
16 Correct 366 ms 74732 KB Output is correct
17 Correct 351 ms 74832 KB Output is correct
18 Correct 353 ms 74576 KB Output is correct
19 Incorrect 2 ms 4696 KB Output isn't correct
20 Halted 0 ms 0 KB -