답안 #989963

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
989963 2024-05-29T08:45:38 Z LOLOLO Addk (eJOI21_addk) C++17
92 / 100
109 ms 15816 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (ll)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())
 
const int N = 4e5 + 1000;
ll sz[N], seg[N], laz[N];

void push(int id) {
    ll t = laz[id];
    laz[id * 2] += t;
    laz[id * 2 + 1] += t;
    seg[id * 2] += sz[id * 2] * t;
    seg[id * 2 + 1] += sz[id * 2 + 1] * t;
    laz[id] = 0;
}


void build(int id, int l, int r) {
    sz[id] = r - l + 1;
    if (l == r)
        return;

    int m = (l + r) / 2;
    build(id * 2, l, m);
    build(id * 2 + 1, m + 1, r);
}

void upd(int id, int l, int r, int u, int v, ll c) {
    if (l > v || r < u)
        return;

    if (l >= u && r <= v) {
        seg[id] += sz[id] * c;
        laz[id] += c;
        return;
    }

    push(id);
    int m = (l + r) / 2;
    upd(id * 2, l, m, u, v, c);
    upd(id * 2 + 1, m + 1, r, u, v, c);
    seg[id] = seg[id * 2] + seg[id * 2 + 1];    
}

ll range(int id, int l, int r, int u, int v) {
    if (l > v || r < u || u > v)
        return 0;

    if (l >= u && r <= v) {
        return seg[id];
    } 

    push(id);
    int m = (l + r) / 2;
    return range(id * 2, l, m, u, v) + range(id * 2 + 1, m + 1, r, u, v);
}

ll a[N];
void solve() {
    int n, k;
    cin >> n >> k;

    build(1, 0, n);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        upd(1, 0, n, i, n, a[i]);
    }

    int q;
    cin >> q;

    for (int i = 1; i <= q; i++) {
        int t;
        cin >> t;

        if (t == 1) {
            vector <int> val, pos;
            int fs = -1;
            for (int j = 0; j < k; j++) {
                int x;
                cin >> x;
                if (fs == -1) {
                    fs = a[x];
                } else {
                    val.pb(a[x]);
                }
                pos.pb(x);
            }

            val.pb(fs);
            for (int j = 0; j < k; j++) {
                upd(1, 1, n, pos[j], n, val[j] - a[pos[j]]);
                a[pos[j]] = val[j];
            }
        } else {
            int l, r, m;
            cin >> l >> r >> m;
            cout << range(1, 0, n, l + m - 1, r) - range(1, 0, n, l - 1, r - m) << '\n';
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t = 1;
    //cin >> t;

    while (t--) {
        solve();
    }

    return 0;
} 

/*
8 3
 7 2 5 1 9 3 4 6
 3
 2 2 7 5
 1 2 5 8
 2 2 7 3
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 3 ms 6748 KB Output is correct
5 Correct 4 ms 6748 KB Output is correct
6 Correct 5 ms 6748 KB Output is correct
7 Correct 6 ms 6948 KB Output is correct
8 Correct 7 ms 7004 KB Output is correct
9 Correct 10 ms 7260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 7956 KB Output is correct
2 Correct 31 ms 10472 KB Output is correct
3 Correct 41 ms 13404 KB Output is correct
4 Correct 81 ms 14676 KB Output is correct
5 Correct 109 ms 15816 KB Output is correct
6 Correct 106 ms 15700 KB Output is correct
7 Correct 104 ms 15712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 82 ms 14248 KB Output isn't correct
2 Halted 0 ms 0 KB -