Submission #832383

#TimeUsernameProblemLanguageResultExecution timeMemory
832383konberAddk (eJOI21_addk)C++14
0 / 100
28 ms876 KiB
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

vector<ll> pref1, pref2;

ll prefix_sum1(int a, int b){
    return pref1[b] - pref1[a-1];
}

ll prefix_sum2(int a, int b){
    return pref2[b] - pref2[a-1] - (a-1)*prefix_sum1(a, b);
}

int main()
{
    int N, K;
    scanf("%d%d", &N, &K);
    if(K!=1)
        return 0;
    vector<int> a(N+1);
    pref1.resize(N+1, 0);
    pref2.resize(N+1, 0);
    for(int i=1; i <= N; i++){
        scanf("%d", &a[i]);
    }

    for(int i=1; i <= N; i++){
        pref1[i] = pref1[i-1] + a[i];
        pref2[i] = pref2[i-1] + i*a[i];
    }

    int Q;
    scanf("%d", &Q);
    while(Q--){
        int q;
        scanf("%d", &q);
        if(q==1){
            int ig;
            scanf("%d", &ig);
            continue;
        }
        int l, r, m;
        scanf("%d%d%d", &l, &r, &m);
        /*if(m==1){
            printf("%lld", prefix_sum1(l, r));
            continue;
        }*/
        int ind1, ind2;
        ind1 = l+m-1;
        ind2 = r-m+1;
        if(ind1 > ind2){
            m = (r-l+1)-m+1;
            swap(ind1, ind2);
        }
        ll ans = m*prefix_sum1(ind1, ind2) + prefix_sum2(l, ind1-1) + m*prefix_sum1(ind2+1, r) - prefix_sum2(ind2+1, r);
        cout << ans << endl;
    }
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     scanf("%d%d", &N, &K);
      |     ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
Main.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     scanf("%d", &Q);
      |     ~~~~~^~~~~~~~~~
Main.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         scanf("%d", &q);
      |         ~~~~~^~~~~~~~~~
Main.cpp:42:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |             scanf("%d", &ig);
      |             ~~~~~^~~~~~~~~~~
Main.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         scanf("%d%d%d", &l, &r, &m);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...