Submission #1050717

# Submission time Handle Problem Language Result Execution time Memory
1050717 2024-08-09T13:16:00 Z mar Addk (eJOI21_addk) C++14
100 / 100
1652 ms 7616 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
int main() {
    int n,k;
    cin >> n >> k;
    vector<int>v(n+1);
    vector<ll>ps(n+1);
    ps[0] = 0;
    for(int i = 1;i <= n;i++){
        cin >> v[i];
        ps[i] = ps[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 += ps[rr] + res2[rr] - (ps[ll] + res2[ll]);
                ll++;
                rr--;
            }
            cout << sum << "\n";
        }else{
            vector<int> ind(k);
            for(int j= 0;j < k;j++){
                cin >> ind[j];
            }
            for(int j = 0;j < k-1;j++){
                int diff = v[ind[j+1]] - v[ind[j]];
                res[ind[j]] += diff;
                res[ind[j+1]] -= diff;
                int temp = v[ind[j]];
                v[ind[j]] = v[ind[j+1]];
                v[ind[j+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 1 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
5 Correct 8 ms 648 KB Output is correct
6 Correct 11 ms 604 KB Output is correct
7 Correct 13 ms 520 KB Output is correct
8 Correct 17 ms 604 KB Output is correct
9 Correct 28 ms 916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 1364 KB Output is correct
2 Correct 161 ms 2128 KB Output is correct
3 Correct 312 ms 2556 KB Output is correct
4 Correct 882 ms 4436 KB Output is correct
5 Correct 1354 ms 6224 KB Output is correct
6 Correct 1256 ms 5904 KB Output is correct
7 Correct 1122 ms 6108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 744 ms 3684 KB Output is correct
2 Correct 1336 ms 5444 KB Output is correct
3 Correct 1652 ms 7616 KB Output is correct
4 Correct 1623 ms 6608 KB Output is correct