Submission #593130

# Submission time Handle Problem Language Result Execution time Memory
593130 2022-07-10T12:32:32 Z Dextar Addk (eJOI21_addk) C++14
0 / 100
6 ms 2432 KB
#include <bits/stdc++.h>
#define first x
#define second y
#define ll long long

using namespace std;

const int INF = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, k;
    cin >> n >> k;
    int a[n];
    for(int i=0; i<n; i++) {
        cin >> a[i];
    }
    ll pref[n+1];
    pref[0] = 0;
    for(int i=0; i<n; i++) {
        pref[i+1] = pref[i] + a[i];
    }
    ll sumPref[n+1];
    sumPref[0] = 0;
    for(int i=1; i<=n; i++) {
        sumPref[i] = sumPref[i-1] + pref[i];
    }
    int q;
    cin >> q;
    while(q--) {
        int type;
        cin >> type;
        if(type==1) {
            int x;
            cin >> x;  cout<<1/0<<endl;
        } else
        {
            int l, r, m;
            cin >> l >> r >> m;
            int sz = r - l + 1;
            m = min(m , sz - m + 1);
            int left = l + m - 2, right = r - m ;  //cout<<left<<' '<<right<<endl;
            ll sumMid = 1LL * m * (pref[right + 1] - pref[left]);
            ll sumL = 1LL * m * pref[left] - sumPref[left];
            if(l>=2) {
                sumL -= sumPref[l-2];
            }
            ll sumR = 0LL + (sumPref[r] - sumPref[right]) - m * pref[right+1];
            ll sum = sumMid + sumL + sumR;
            //cout<<sumMid<<' '<<sumL<<' '<<sumR<<endl;
            cout << sum << endl;
        }
    }
    return 0;
}
/*
3
3 1 1
*/

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:37:31: warning: division by zero [-Wdiv-by-zero]
   37 |             cin >> x;  cout<<1/0<<endl;
      |                              ~^~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 4
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 1236 KB Execution killed with signal 4
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 2432 KB Execution killed with signal 4
2 Halted 0 ms 0 KB -