Submission #593442

# Submission time Handle Problem Language Result Execution time Memory
593442 2022-07-11T07:49:03 Z serkanrashid Addk (eJOI21_addk) C++14
0 / 100
23 ms 3988 KB
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

const int maxn=1e5+5;
int n,k,q;
long long a[maxn],pref[maxn],suff[maxn],dp[maxn];

void read()
{
    cin >> n >> k;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
        pref[i]=pref[i-1]+a[i]*i;
        dp[i]=dp[i-1]+a[i];
    }
    for(int i=1;i<=n;i++)
    {
        suff[i]=suff[i-1]+a[i]*(n-i+1);
    }
    cin >> q;
    int ch,l,r,m,idx,mid,len,obr;
    long long ans;
    for(int i=1;i<=q;i++)
    {
        cin >> ch;
        ans=0;
        if(ch==1) cin >> ch;
        else
        {
            cin >> l >> r >> m;
            len=r-l+1;
            idx=l+m-1;
            if(!(len%2)) len--;
            mid=(len/2)+l;
            if(mid>=idx) ///SUPEER
            {
                ans+=((pref[idx-1]-pref[l-1])-(dp[idx-1]-dp[l-1])*(l-1));
                obr=l+r-idx;
                ans+=((suff[r]-suff[obr]))-((dp[r]-dp[obr])*(n-r));
                ans+=((dp[obr]-dp[idx-1])*m);
            }
            else ///TUPICHKO
            {
                idx=mid;
                ans+=((pref[idx-1]-pref[l-1])-(dp[idx-1]-dp[l-1])*(l-1));
                obr=l+r-idx;
                ans+=((suff[r]-suff[obr]))-((dp[r]-dp[obr])*(n-r));
                ans+=((dp[obr]-dp[idx-1])*(idx-l+1));
            }
            cout << ans << endl;
        }
    }
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	read();
return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 1620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 3988 KB Output isn't correct
2 Halted 0 ms 0 KB -