Submission #964725

# Submission time Handle Problem Language Result Execution time Memory
964725 2024-04-17T12:07:26 Z zxcigan Addk (eJOI21_addk) C++17
0 / 100
2000 ms 1376 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);
    for (int i = 1; i <= n; ++i) cin >> a[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;
            vector<ll> pref (n + 1);
//            for (int i = l; i <= r; ++i) pref[i] = pref[i - 1] + a[i];
            for (int i = l; i <= r; ++i) {
//                if (i <= r - x + 1) ans += pref[i + x - 1] - pref[i - 1];
                int cnt = 0;
                int R = min (r, i + x - 1);
                int L = max (l, i - x + 1);

                ans += min (i - L + 1, R - i + 1) * 1LL * a[i];
            }
            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;
        }
    }
}

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;
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:37:21: warning: unused variable 'cnt' [-Wunused-variable]
   37 |                 int cnt = 0;
      |                     ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 620 ms 788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2032 ms 1376 KB Time limit exceeded
2 Halted 0 ms 0 KB -