답안 #593146

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
593146 2022-07-10T13:00:33 Z Dextar Addk (eJOI21_addk) C++14
92 / 100
149 ms 6180 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
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 464 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 5 ms 468 KB Output is correct
5 Correct 6 ms 488 KB Output is correct
6 Correct 8 ms 468 KB Output is correct
7 Correct 9 ms 644 KB Output is correct
8 Correct 11 ms 692 KB Output is correct
9 Correct 15 ms 852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 1016 KB Output is correct
2 Correct 48 ms 1936 KB Output is correct
3 Correct 58 ms 2636 KB Output is correct
4 Correct 102 ms 4464 KB Output is correct
5 Correct 149 ms 6180 KB Output is correct
6 Correct 135 ms 5932 KB Output is correct
7 Correct 141 ms 5932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 2388 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -