Submission #770984

# Submission time Handle Problem Language Result Execution time Memory
770984 2023-07-02T09:20:36 Z GordonRemzi007 Addk (eJOI21_addk) C++17
0 / 100
104 ms 3144 KB
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int n, k, q, l, r, m, res = -1;
    cin >> n >> k;
    vector<int> a(n), b(n), c(n), u(k);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = a[i];
        c[i] = (i+1)*a[i];
        if(i != 0) b[i]+=b[i-1], c[i]+=c[i-1];
    }
    cin >> q;
    while(q--) {
        cin >> m;
        if(m == 1) {
            for(int i = 0; i < k; i++) cin >> u[i];
        } else {
            cin >> l >> r >> m;
            l--, r--;
            if(2*m <= r-l+1) cout << c[l+m-1]-(l-1 < 0 ? 0 : c[l-1])-l*(b[l+m-1]-(l-1 < 0 ? 0 : b[l-1])) + (b[r-m]-b[l+m-1])*m + (r+2)*(b[r]-(r-m < 0 ? 0 : b[r-m]))-(c[r]-c[r-m]) << "\n";
            else cout << c[r-m]-(l-1 < 0 ? 0 : c[l-1])-l*(b[r-m]-(l-1 < 0 ? 0 : b[l-1])) + (b[l+m-1]-b[r-m])*(r-l+2-m) + (r+2)*(b[r]-(l+m-1 < 0 ? 0 : b[l+m-1]))-(c[r]-c[l+m-1]) << "\n";
        }
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:6:27: warning: unused variable 'res' [-Wunused-variable]
    6 |     int n, k, q, l, r, m, res = -1;
      |                           ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Incorrect 4 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 1204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 104 ms 3144 KB Output isn't correct
2 Halted 0 ms 0 KB -