답안 #583748

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
583748 2022-06-26T07:27:28 Z Ivkosqn Addk (eJOI21_addk) C++14
0 / 100
34 ms 2952 KB
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

const int maxn = 1e5 + 1;
long long n, k, a[maxn], p[maxn], pref[maxn];
long long t[4 * maxn];

void make_tree(int i, int l, int r){
    if(l == r){
        t[i] = a[r];
        return;
    }
    int mid = (l + r) / 2;
    make_tree(2 * i, l, mid);
    make_tree(2 * i + 1, mid + 1, r);
    t[i] = t[2 * i] + t[2 * i + 1];
}

long long query(int i, int l, int r, int ql, int qr){
    if(l == ql && r == qr){
        return t[i];
    }
    int mid = (l + r) / 2;
    if(qr <= mid) return query(2 * i, l, mid, ql ,qr);
    if(ql > mid) return query(2 * i + 1, mid + 1, r, ql, qr);
    return query(2 * i, l, mid, ql, mid) + query(2 * i + 1, mid + 1, r, mid + 1, qr);
}

void solve(){
    int q;
    cin >> q;
    while(q--){
        int type;
        cin >> type;
        if(type == 1){
            for(int i = 0;i < k;i++){
                int a;
                cin >> a;
            }
            continue;
        }
        int l, r, m;
        cin >> l >> r >> m;
        long long ans = 0;
        ans = pref[r] - pref[l + m - 2];
        ans = ans - (pref[r - m] - pref[l - 1]);
        cout << ans << endl;
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
        p[i] = p[i - 1] + a[i];
    }
    for(int i = 1;i <= n;i++){
        pref[i] = pref[i - 1] + p[i];
    }
    make_tree(1, 1, n);
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 1620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 34 ms 2952 KB Output isn't correct
2 Halted 0 ms 0 KB -