Submission #630035

# Submission time Handle Problem Language Result Execution time Memory
630035 2022-08-15T14:46:47 Z ZsofiaKeresztely Addk (eJOI21_addk) C++14
0 / 100
373 ms 1740 KB
#include <bits/stdc++.h>
using namespace std;
vector<int> lstairs, rstairs, pref;
int n;

void upd(vector<int> &a){
  pref.assign(n+1, 0);
  lstairs.assign(n+1, 0);
  rstairs.assign(n+1, 0);
  for (int i=1; i<n+1; i++){
    pref[i] = pref[i-1] + a[i];
    lstairs[i] = lstairs[i-1] + pref[i];
  }
  rstairs[n] = a[n];
  for (int i=n-1; i>0; i--){
    rstairs[i] = rstairs[i+1] + (pref[n] - pref[i-1]);
  }
  return;
}

int main(){
  int k;
  cin >> n >> k;
  vector<int> a(n+1);
  vector<int> orig;
  for (int i=1; i<n+1; i++){
    cin >> a[i];
  }
  orig = a;
  upd(a);
  int q, type, val, l, r, m, sum, lastl, lastr, x;
  vector<int> ind(k);
  set<int> toupd;
  cin >> q;
  for (int i=0; i<q; i++){
    cin >> type;
    if (type == 1){
      cin >> ind[0];
      toupd.insert(ind[0]);
      val = a[ind[0]];
      for (int j=1; j<k; j++){
        cin >> ind[j];
        toupd.insert(ind[j]);
        a[ind[j-1]] = a[ind[j]];
      }
      a[ind[k-1]] = val;
      val = toupd.size();
      if (val * val >= n * k){
        upd(a);
        orig = a;
        toupd.clear();
      }
    }
    else{
      cin >> l >> r >> m;
      lastl = min(l+m-1, r-m+1);
      lastr = max(l+m-1, r-m+1);
      if (lastl == lastr){
        lastr++;
      }
      sum = rstairs[l] - rstairs[lastl+1] - (lastl - l + 1) * (pref[n] - pref[lastl])
      + lstairs[r] - lstairs[lastr-1] - (r - lastr + 1) * pref[lastr - 1]
      + (lastl - 1 + 1) * (pref[lastr-1] - pref[lastl]);
      for (auto i : toupd){
        x = min(i - l + 1, r - i + 1);
        if (x > 0){
          sum += (a[i] - orig[i]) * x;
        }
      }
      cout << sum << "\n";
    }
  }
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 59 ms 844 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 373 ms 1740 KB Output isn't correct
2 Halted 0 ms 0 KB -