답안 #770765

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
770765 2023-07-01T22:11:59 Z GordonRemzi007 Addk (eJOI21_addk) C++17
0 / 100
107 ms 3072 KB
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int n, k, q, l, r, m, res = -1;
    cin >> n >> k;
    vector<int> a(n), b(n), c(n), u(k);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = a[i];
        c[i] = (i+1)*a[i];
        if(i != 0) b[i]+=b[i-1], c[i]+=c[i-1];
    }
    cin >> q;
    while(q--) {
        cin >> m;
        if(m == 1) {
            for(int i = 0; i < k; i++) cin >> u[i];
        } else {
            cin >> l >> r >> m;
            l--, r--;
            if(2*m <= r-l+1) cout << c[l+m-1]-(l-1 < 0 ? 0 : c[l-1])-l*(b[l+m-1]-(l-1 < 0 ? 0 : b[l-1])) + (b[r-m]-b[l+m-1])*m + (r+2)*(b[r]-(r-m < 0 ? 0 : b[r-m]))-(c[r]-c[r-m]) << "\n";
            else cout << c[r-m+1]-(l-1 < 0 ? 0 : c[l-1])-l*(b[r-m+1]-(l-1 < 0 ? 0 : b[l-1])) + (b[l+m-2]-b[r-m+1])*(r-l+2-m) + (r+2)*(b[r]-(l+m-2 < 0 ? 0 : b[l+m-2]))-(c[r]-c[l+m-2]) << "\n";
        }
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:6:27: warning: unused variable 'res' [-Wunused-variable]
    6 |     int n, k, q, l, r, m, res = -1;
      |                           ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Incorrect 4 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 1108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 107 ms 3072 KB Output isn't correct
2 Halted 0 ms 0 KB -