Submission #848123

# Submission time Handle Problem Language Result Execution time Memory
848123 2023-09-11T11:50:11 Z JoksimKaktus Addk (eJOI21_addk) C++17
92 / 100
2000 ms 3996 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    int n,k;
    cin >> n >> k;
    vector <int> v(n+1);
    vector <long long> pre(n+1);
    pre[0] = 0;
    for(int i = 1;i <= n;i++){
        cin >> v[i];
        pre[i] = pre[i-1] + v[i];
    }
    int q;
    cin >> q;
    bool fix = false;
    vector <int> res(n+1,0);
    vector <int> res2(n+1,0);
    int mini = n;
    int maxi = 0;
    for(int i = 0;i < q;i++){
        int qu,l,r,m;
        cin >> qu;
        if(qu == 2){
            cin >> l >> r >> m;
            int rr = r;
            int ll = l-1;
            long long sum = 0;
            if(fix){
                for(int j = mini;j <= maxi;j++){
                    res2[j] += res[j-1] + res[j];
                    res[j] += res[j-1];
                    res[j-1] = 0;
                }
                res[maxi] = 0;
                fix = false;
                mini = n;
                maxi = 0;
            }
            for(int j = 0; j < min(m,(r-l)+2-m);j++){
                sum += pre[rr] + res2[rr] - (pre[ll] + res2[ll]);
                ll++;
                rr--;
            }
            cout << sum << "\n";
        }else{
            vector <int> ind(k);
            for(int ii = 0;ii < k;ii++){
                cin >> ind[ii];
            }
            for(int ii = 0;ii < k-1;ii++){
                int diff = v[ind[ii+1]] - v[ind[ii]];
                res[ind[ii]] += diff;
                res[ind[ii+1]] -= diff;
                int temp = v[ind[ii]];
                v[ind[ii]] = v[ind[ii+1]];
                v[ind[ii+1]] = temp;
            }
            fix = true;
            mini = min (mini,ind[0]);
            maxi = max(maxi, ind[k-1]);
        }
    }
    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 2 ms 348 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
6 Correct 6 ms 600 KB Output is correct
7 Correct 8 ms 604 KB Output is correct
8 Correct 10 ms 664 KB Output is correct
9 Correct 19 ms 720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 1108 KB Output is correct
2 Correct 146 ms 1636 KB Output is correct
3 Correct 256 ms 1616 KB Output is correct
4 Correct 846 ms 2816 KB Output is correct
5 Correct 1332 ms 3996 KB Output is correct
6 Correct 1311 ms 3720 KB Output is correct
7 Correct 1106 ms 3808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1462 ms 2144 KB Output is correct
2 Execution timed out 2058 ms 3108 KB Time limit exceeded
3 Halted 0 ms 0 KB -