Submission #964727

# Submission time Handle Problem Language Result Execution time Memory
964727 2024-04-17T12:13:45 Z zxcigan Addk (eJOI21_addk) C++17
36 / 100
2000 ms 2488 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e6 + 1;
const int mod = 1e9 + 7;

template <typename T>
bool umx(T& a, T b) {
    return (a < b ? a = b, 1 : 0);
}
template <typename T>
bool umn(T& a, T b) {
    return (a > b ? a = b, 1 : 0);
}

void solve () {
    int n, k;
    cin  >> n >> k;
    vector<int> a(n + 1);
    vector<ll> pref (n + 1);
    vector<ll> ppref (n + 1);
    for (int i = 1; i <= n; ++i) cin >> a[i], pref[i] = pref[i - 1] + a[i];
    for (int i = 1; i <= n; ++i) ppref[i] = ppref[i - 1] + pref[i];
    int q;
    cin >> q;
    while (q--) {
        int type;
        cin >> type;
        if (type == 2) {
            int l, r, x;
            cin >> l >> r >> x;
            ll ans = 0;
            if (l == 1) {
                ans -= ppref[r - x];
            }
            else {
                ans -= ppref[r - x] - ppref[l - 2];
            }
            for (int i = l; i <= r; ++i) {
                if (i <= r - x + 1) ans += pref[i + x - 1] ;
            }
            cout << ans << "\n";
        }
        else {
            vector<int> ve(k);
            for (int i = 0; i < k; ++i) cin >> ve[i];
            int last = a[ve[0]];
            for (int i = 0; i < k - 1; ++i) a[ve[ i]] = a[ve[i + 1]];
            a[ve.back()] = last;
            for (int i = 1; i <= n; ++i) pref[i] = pref[i - 1] + a[i];
            for (int i = 1; i <= n; ++i) ppref[i] = ppref[i - 1] + pref[i];
        }
    }
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    //    freopen ("input.txt", "r", stdin);
//    freopen ("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    while (T--) solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 4 ms 348 KB Output is correct
4 Correct 8 ms 520 KB Output is correct
5 Correct 18 ms 544 KB Output is correct
6 Correct 24 ms 568 KB Output is correct
7 Correct 29 ms 604 KB Output is correct
8 Correct 43 ms 604 KB Output is correct
9 Correct 81 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 307 ms 1144 KB Output is correct
2 Correct 721 ms 1320 KB Output is correct
3 Correct 1235 ms 1844 KB Output is correct
4 Execution timed out 2029 ms 2488 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2023 ms 1692 KB Time limit exceeded
2 Halted 0 ms 0 KB -