답안 #593124

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
593124 2022-07-10T12:26:28 Z Dextar Addk (eJOI21_addk) C++14
0 / 100
30 ms 3020 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;
        } 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
*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 30 ms 1404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 3020 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -