Submission #1290028

#TimeUsernameProblemLanguageResultExecution timeMemory
1290028austinAddk (eJOI21_addk)C++20
36 / 100
2096 ms2912 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
using namespace std;
int16_t type;
long long counter = 0, window;
int n, k, q, l, r, m, i, j, temp;
static inline long long read() {
  long long x = 0;
  int c = getchar_unlocked();
  while ( c<'0' && c>'9') {
    c = getchar_unlocked();
  }
  while (c>='0' && c<='9') {
    x = x*10+(c-'0');
    c = getchar_unlocked();
  }
  return x;
}
static inline void write(long long val) {
  if (val == 0) {
    putchar_unlocked('0');
    putchar_unlocked('\n');
    return;
  }
  char buf[21];
  i=0;
  while (val>0) {
    buf[i++] = val%10+'0';
    val/=10;
  }
  while (i--) {
    putchar_unlocked(buf[i]);
  }
  putchar_unlocked('\n');
}
int main() {
  n = read();
  k = read();
  vector<long long> v(n+1), prefix(n+1, 0);
  vector<int> operations(k);
  for (i=1; i<=n; i++) {
    v[i] = read();
    prefix[i] = prefix[i-1] + v[i];
  }
  q = (int)read();
  for (i=0; i<q; i++) {
    type = (int16_t)read();
    if (type == 1) {
      for (j=0; j<k; j++) {
        operations[j] = (int)read();
      }
      temp = v[operations[0]];
      for (j=1; j<k; j++) {
        v[operations[j-1]] = v[operations[j]];
      }
      v[operations[k-1]] = temp;
      temp = *min_element(operations.begin(), operations.end());
      prefix[temp] = prefix[temp - 1] + v[temp];
      for (j=temp+1; j<=n; ++j) {
        prefix[j] = prefix[j - 1] + v[j];
      }
    } else if (type == 2) {
      l = read();
      r = read();
      m = read();
      counter = 0;
      for (j=l; j<=r-m+1; j++) {
        counter += prefix[j+m-1] - prefix[j-1];
      }
      write(counter);
    }
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...