Submission #476156

# Submission time Handle Problem Language Result Execution time Memory
476156 2021-09-25T06:55:09 Z gvancak Addk (eJOI21_addk) C++11
0 / 100
465 ms 1520 KB
#include <iostream>
 
using namespace std;
long long n,k,q,a[100001],p[100001],t,x,ans,l,r,m,y;
int main()
{
    cin >> n >> k;
    for (int i=1; i<=n; i++){
    cin >> a[i];
    p[i]=p[i-1]+a[i];
    }
    cin >> q;
    for (int o=1; o<=q; o++){
    cin >> t;
    ans=0;
    if (t==1){
        for (int i=1; i<=k; i++){
            cin >> x;
        }
    }
    else{
        cin >> l >> r >> m;
        if (r-l+1<m*2-1){
            x=r-(l+m-1)+1;
            for (int i=l; i<=l+m-1-1; i++){
            	if (x<=i-l+1){ y=i; break; }
                ans+=min(i-l+1,x)*a[i];
            }
            ans+=(p[l+m-2]-p[y-1])*x;
            for (int i=l+m-1-1+1; i<=r; i++){
                ans+=min(r-i+1,x)*a[i];
            }
            cout<<ans<<endl;
        }
        else{
            x=m;
            /*
            for (int i=l; i<=l+m-1-1; i++){
                ans+=min(i-l+1,x)*a[i];
            }
            ans+=(p[r-m]-p[l+m-1-1])*m;
            for (int i=r-m+1; i<=r; i++){
                ans+=min(r-i+1,x)*a[i];
            }*/
            ans=(p[r]-p[l-1])*m;
            for (int i=l; i<=l+m-2; i++){
            	ans-=a[i]*(l-(i-l+1));
            	ans-=a[r-(i-l)]*(l-(i-l+1));
			}
            cout<<ans<<endl;
        }
    }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 174 ms 752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 465 ms 1520 KB Output isn't correct
2 Halted 0 ms 0 KB -