Submission #839680

# Submission time Handle Problem Language Result Execution time Memory
839680 2023-08-30T12:44:05 Z konber Addk (eJOI21_addk) C++14
36 / 100
2000 ms 3064 KB
#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);
        ll ans=0;
        for(int i=l; i <= r-m+1; i++){
            ans += prefix_sum1(i, i+m-1);
        }
        printf("%lld\n", ans);
        /*if(m==1){
            printf("%lld\n", prefix_sum1(l, r));
            continue;
        }
        int ind1=l+m-1, ind2=r-m+1;
        if(ind1 <= ind2){
            ll ans = m*prefix_sum1(ind1, ind2);
            ans += prefix_sum2(l, ind1-1);
            ans += m*prefix_sum1(ind2+1, r) - prefix_sum2(ind2+1, r);
            printf("%lld\n", ans);
        }
        else{
            m = ind2-l+1;
            swap(ind1, ind2);
            ll ans;
            if(m==1) ans=prefix_sum1(ind1, ind2);
            else{
                ans = m*prefix_sum1(ind1, ind2);
                ans += prefix_sum2(l, ind1-1);
                ans += m*prefix_sum1(ind2+1, r) - prefix_sum2(ind2+1, r);
            }
            printf("%lld\n", ans);
        }*/
    }
}

Compilation message

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 time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 4 ms 340 KB Output is correct
5 Correct 5 ms 416 KB Output is correct
6 Correct 8 ms 340 KB Output is correct
7 Correct 11 ms 468 KB Output is correct
8 Correct 14 ms 468 KB Output is correct
9 Correct 27 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 852 KB Output is correct
2 Correct 211 ms 1224 KB Output is correct
3 Correct 380 ms 1772 KB Output is correct
4 Correct 1526 ms 2816 KB Output is correct
5 Execution timed out 2059 ms 3064 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -