답안 #774734

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
774734 2023-07-06T02:21:55 Z vjudge1 Addk (eJOI21_addk) C++17
92 / 100
40 ms 4976 KB
// #cheat_when_I_was_young
// #cheatkhitacontre #khionhatoicheat
// #thaycuckythatvong
#include "bits/stdc++.h"
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long
const int NM = 1e6 + 5;
int n, k, q, a[NM], p1[NM], p2[NM], p3[NM];
int get_sum1(int l, int r) {
    if (l > r) return 0;
    return p1[r] - p1[l-1];
}
int get_sum2(int l, int r) {
    if (l > r) return 0;
    return p2[r] - p2[l-1] - get_sum1(l, r) * (l-1);
}
int get_sum3(int l, int r) {
    if (l > r) return 0;
    return p3[l] - p3[r+1] - get_sum1(l, r) * (n-r);
}
signed main() {
	IOS;
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        p1[i] = p1[i-1] + a[i];
        p2[i] = p2[i-1] + a[i] * i;
	}
	for (int i = n; i >= 1; --i) p3[i] = p3[i+1] + a[i] * (n-i+1);
	cin >> q;
	while (q--) {
        int type;
        cin >> type;
        if (type == 1) {
            int x;
            for (int i = 1; i <= k; ++i) cin >> x;
            continue;
        }
        int l, r, m;
        cin >> l >> r >> m;
        if (r-l+1 < m) {
            cout << "0\n";
            continue;
        }
        int u, v, d = min(r-l+1-m, m-1);
        u = l+d;
        v = r-d;
        cout << get_sum2(l, u-1) + get_sum1(u, v) * (d+1) + get_sum3(v+1, r) << "\n";
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 528 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 3 ms 596 KB Output is correct
9 Correct 4 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1236 KB Output is correct
2 Correct 11 ms 1672 KB Output is correct
3 Correct 15 ms 2164 KB Output is correct
4 Correct 26 ms 3528 KB Output is correct
5 Correct 36 ms 4976 KB Output is correct
6 Correct 35 ms 4792 KB Output is correct
7 Correct 40 ms 4804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 2344 KB Output isn't correct
2 Halted 0 ms 0 KB -