Submission #774896

# Submission time Handle Problem Language Result Execution time Memory
774896 2023-07-06T05:08:20 Z CDuong Addk (eJOI21_addk) C++17
92 / 100
133 ms 11284 KB
/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/

#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
#define ll long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define isz(x) (int)x.size()
using namespace std;

const int mxN = 1e5 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;

struct node {
    int val, lazy;
    node() {val = lazy = 0;}
    node operator + (const node &o) {
        node res;
        res.val = val + o.val;
        return res;
    }
} segtree[4 * mxN];

int n, k, q, a[mxN];

void down(int idx, int l, int r) {
    if(segtree[idx].lazy == 0)
        return;
    int val = segtree[idx].lazy, mid = (l + r) >> 1;

    segtree[idx << 1].val += val * (mid - l + 1);
    segtree[idx << 1].lazy += val;

    segtree[idx << 1 | 1].val += val * (r - mid);
    segtree[idx << 1 | 1].lazy += val;

    segtree[idx].lazy = 0;
}

void update(int l, int r, int idx, int u, int v, int val) {
    if(r < u || v < l) return;
    if(u <= l && r <= v) {
        segtree[idx].val += (r - l + 1) * val;
        segtree[idx].lazy += val;
        return;
    }

    down(idx, l, r);

    int mid = (l + r) >> 1;
    update(l, mid, idx << 1, u, v, val);
    update(mid + 1, r, idx << 1 | 1, u, v, val);

    segtree[idx] = segtree[idx << 1] + segtree[idx << 1 | 1];
}

int get(int l, int r, int idx, int u, int v) {
    if(r < u || v < l) return 0;
    if(u <= l && r <= v)
        return segtree[idx].val;

    down(idx, l, r);

    int mid = (l + r) >> 1;
    return get(l, mid, idx << 1, u, v) + get(mid + 1, r, idx << 1 | 1, u, v);
}

void solve() {
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        update(0, n, 1, i, n, a[i]);
    }

    cin >> q;
    while(q--) {
        int type; cin >> type;
        if(type == 1) {
            vi pos(k);
            for(int &val : pos) cin >> val;
            for(int i = 0; i < k; ++i) {
                int diff = a[pos[(i + 1) % k]] - a[pos[i]];
                update(0, n, 1, pos[i], n, diff);
            }
        }
        else {
            int l, r, m; cin >> l >> r >> m;
            cout << get(0, n, 1, l + m - 1, r) - get(0, n, 1, l - 1, r - m) << "\n";
        }
    }
}

signed main() {

#ifndef CDuongg
    if(fopen(taskname".inp", "r"))
        assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
    freopen("bai3.inp", "r", stdin);
    freopen("bai3.out", "w", stdout);
    auto start = chrono::high_resolution_clock::now();
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1; //cin >> t;
    while(t--) solve();

#ifdef CDuongg
    auto end = chrono::high_resolution_clock::now();
    cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
    cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif

}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6484 KB Output is correct
2 Correct 4 ms 6612 KB Output is correct
3 Correct 6 ms 6612 KB Output is correct
4 Correct 7 ms 6600 KB Output is correct
5 Correct 8 ms 6724 KB Output is correct
6 Correct 7 ms 6736 KB Output is correct
7 Correct 8 ms 6740 KB Output is correct
8 Correct 11 ms 6860 KB Output is correct
9 Correct 12 ms 6996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 7416 KB Output is correct
2 Correct 32 ms 7880 KB Output is correct
3 Correct 48 ms 8380 KB Output is correct
4 Correct 83 ms 9868 KB Output is correct
5 Correct 132 ms 11284 KB Output is correct
6 Correct 133 ms 11032 KB Output is correct
7 Correct 114 ms 11000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 96 ms 9416 KB Output isn't correct
2 Halted 0 ms 0 KB -