Submission #1289982

#TimeUsernameProblemLanguageResultExecution timeMemory
1289982austinAddk (eJOI21_addk)C++20
36 / 100
2095 ms1456 KiB
// Source: https://usaco.guide/general/io
#include <bits/stdc++.h>
using namespace std;
int16_t type;
long long temp, sum, counter=0;
int n, k, q, l, r, m, i, j, s, z, temp2, treeT, debut, fin;
int main() {
  scanf("%d %d", &n, &k);
  treeT = 1<<(int)ceil(log2(n));
  vector<long long> tree(2*treeT);
  vector<int> op(k);
  for (i=1; i<=n; i++) {
    scanf("%lld", &tree[treeT+i]);
  }
  for (i=treeT-1; i>=1; i--) {
      tree[i] = tree[2*i]+tree[2*i+1];
  }
  scanf("%d", &q);
  for (i=0; i<q; i++) {
    scanf("%hd", &type);
    if (type == 1) {
      for (j=0; j<k; j++) {
        scanf("%d", &op[j]);
      }
      temp = tree[op[0]+treeT];
      for (j=1; j<k; j++) {
        tree[op[j-1]+treeT] = tree[op[j]+treeT];
        z = treeT+op[j-1];
        for (z>>=1; z>=1; z>>=1) {
          tree[z] = tree[z*2]+tree[z*2+1];
        }
      }
      tree[op[k-1]+treeT] = temp;
      z = treeT+op[k-1];
      for (z>>=1; z>=1; z>>=1) {
        tree[z] = tree[z*2]+tree[z*2+1];
      }
    } else {
      scanf("%d %d %d", &l, &r, &m);
      counter = 0;
      for (j = l; j <= r - m + 1; ++j) {
        debut = treeT + j;
        fin = treeT + j + m - 1;
        sum = 0;
        while (debut <= fin) {
          if (debut%2) sum += tree[debut++];
          if (!(fin%2)) sum += tree[fin--];
          debut >>= 1;
          fin >>= 1;
        }
        counter += sum;
      }
      printf("%lld\n", counter);
    }
  }
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:8:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |   scanf("%d %d", &n, &k);
      |   ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%lld", &tree[treeT+i]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   scanf("%d", &q);
      |   ~~~~~^~~~~~~~~~
Main.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     scanf("%hd", &type);
      |     ~~~~~^~~~~~~~~~~~~~
Main.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         scanf("%d", &op[j]);
      |         ~~~~~^~~~~~~~~~~~~~
Main.cpp:39:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |       scanf("%d %d %d", &l, &r, &m);
      |       ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...