Submission #593496

# Submission time Handle Problem Language Result Execution time Memory
593496 2022-07-11T09:25:03 Z serkanrashid Addk (eJOI21_addk) C++14
92 / 100
54 ms 7380 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];
        suff[i]=suff[i-1]+a[i]*(n-i+1);
    }
    cin >> q;
    int ch,l,r,m,idx,mid,obr;
    long long ans=0;
    for(int i=1;i<=q;i++)
    {
        cin >> ch;
        ans=0;
        if(ch==1)
        {
            cin >> ch;
        }
        else
        {
            cin >> l >> r >> m;
            //cout << "++++++++++++++++++++++++++" << endl;
            m=min(m,r-l+2-m);
            idx=l+m-1;
            mid=(l+r)/2;
            idx=min(idx,mid);
            m=idx-l+1;
            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;
}

/*
8 1
7 2 5 1 9 3 4 6
6
2 3 8 4
2 5 6 2
2 6 8 1
2 1 8 4
2 1 8 6
2 3 7 2
*/

# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 3 ms 580 KB Output is correct
7 Correct 3 ms 748 KB Output is correct
8 Correct 4 ms 744 KB Output is correct
9 Correct 5 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1492 KB Output is correct
2 Correct 14 ms 2396 KB Output is correct
3 Correct 20 ms 3024 KB Output is correct
4 Correct 32 ms 5200 KB Output is correct
5 Correct 54 ms 7380 KB Output is correct
6 Correct 51 ms 7160 KB Output is correct
7 Correct 47 ms 7168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 2908 KB Output isn't correct
2 Halted 0 ms 0 KB -