Submission #613723

# Submission time Handle Problem Language Result Execution time Memory
613723 2022-07-30T09:48:30 Z KALARRY Addk (eJOI21_addk) C++14
92 / 100
63 ms 4980 KB
#include<bits/stdc++.h>
using namespace std;

long long N,K,Q,a[100005],preffix[100005],mullpreff[100005];

long long S1(long long l,long long r)
{
    return mullpreff[r]-mullpreff[l-1]-(l-1)*(preffix[r]-preffix[l-1]);
}

long long S2(long long l,long long r)
{
    return (r+1)*(preffix[r]-preffix[l-1])-mullpreff[r]+mullpreff[l-1];
}

int main()
{
    scanf("%lld%lld",&N,&K);
    for(long long i =1 ; i <= N ; i++)
    {
        scanf("%lld",&a[i]);
        preffix[i]=preffix[i-1]+a[i];
        mullpreff[i]=mullpreff[i-1]+i*a[i];
    }
    scanf("%lld",&Q);
    for(long long op,ans,l,r,m,i =1 ; i <= Q ; i++)
    {
        scanf("%lld",&op);
        if(op==1)
        {
            scanf("%*d");
            continue;
        }
        scanf("%lld%lld%lld",&l,&r,&m);
        if(2*m<=r-l+1)
        {
            ans= S1(l,l+m-1) +S2(r-m+1,r)+ (preffix[r-m]-preffix[l+m-1])*m;
            printf("%lld\n",ans);
        }
        else
        {
           long long d=r-l+2-m;
            ans = S1(l,r-m)+S2(l+m,r)+d*(preffix[l+m-1]-preffix[r-m]);
            printf("%lld\n",ans);
        }
    }
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     scanf("%lld%lld",&N,&K);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
Main.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%lld",&a[i]);
      |         ~~~~~^~~~~~~~~~~~~~
Main.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     scanf("%lld",&Q);
      |     ~~~~~^~~~~~~~~~~
Main.cpp:28:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         scanf("%lld",&op);
      |         ~~~~~^~~~~~~~~~~~
Main.cpp:31:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |             scanf("%*d");
      |             ~~~~~^~~~~~~
Main.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         scanf("%lld%lld%lld",&l,&r,&m);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 444 KB Output is correct
5 Correct 2 ms 452 KB Output is correct
6 Correct 3 ms 576 KB Output is correct
7 Correct 4 ms 596 KB Output is correct
8 Correct 4 ms 724 KB Output is correct
9 Correct 6 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 1520 KB Output is correct
2 Correct 19 ms 2076 KB Output is correct
3 Correct 23 ms 2492 KB Output is correct
4 Correct 42 ms 3680 KB Output is correct
5 Correct 63 ms 4980 KB Output is correct
6 Correct 55 ms 4760 KB Output is correct
7 Correct 52 ms 4732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 3204 KB Output isn't correct
2 Halted 0 ms 0 KB -