Submission #1035295

# Submission time Handle Problem Language Result Execution time Memory
1035295 2024-07-26T08:55:27 Z kebine Addk (eJOI21_addk) C++17
0 / 100
34 ms 1900 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long 

signed main(){
    int n,k;
    cin>>n>>k;
    if(k==1){
        int a[n+1];
        for(int q=1;q<=n;q++){
            cin>>a[q];
        }
        int pref[n+1],suf[n+2],sum[n+1],blk[n+1];
        pref[0]=0;
        suf[n+1]=0;
        sum[0]=0;
        blk[n+1]=0;

        for(int q=1;q<=n;q++){
            pref[q]=pref[q-1]+q*a[q];
            sum[q]=sum[q-1]+a[q];
        }
        for(int q=n;q>=1;q--){
            suf[q]=suf[q+1]+(n-q+1)*a[q];
            blk[q]=blk[q+1]+a[q];
        }

        int q;
        cin>>q;
        for(int w=1;w<=q;w++){
            int type;
            cin>>type;
            if(type==1){
                int r;
                cin>>r;
            }
            else{
                int l,r,m;
                cin>>l>>r>>m;
                int ans=0;

                if((r-l+1)%2==0){
                    int posl=l+m-1;
                    int posr=r-m+1;
                    if(posl>posr){
                        swap(posl,posr);
                    }
                    
                    ans+=pref[posl]-pref[l-1]-(l-1)*(sum[posl]-sum[l-1]);
                    ans+=suf[posr]-suf[r+1]-(n-r)*(blk[posr]-blk[r+1]);
                    posl++;
                    posr--;
                    if(posl<=posr){
                        ans+=m*(sum[posr]-sum[posl-1]);
                    }
                }
                else{
                    int posl=l+m-1;
                    int posr=r-m+1;
                    
                    if(posl>posr){
                        swap(posl,posr);
                    }
                    ans+=pref[posl]-pref[l-1]-(l-1)*(sum[posl]-sum[l-1]);
                    ans+=suf[posr]-suf[r+1]-(n-r)*(blk[posr]-blk[r+1]);

                    posl++;
                    posr--;
                    if(posl<=posr){
                        ans+=m*(sum[posr]-sum[posl-1]);
                    }
                }
                cout<<ans<<endl;
            }
        }
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 1900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -