Submission #793207

#TimeUsernameProblemLanguageResultExecution timeMemory
793207rainboyAddk (eJOI21_addk)C11
100 / 100
83 ms7508 KiB
#include <stdio.h> #define N 100000 #define K 10 void update(long long *ft, int i, int n, long long x) { while (i < n) { ft[i] += x; i |= i + 1; } } long long query(long long *ft, int i) { long long x = 0; while (i >= 0) { x += ft[i]; i &= i + 1, i--; } return x; } int main() { static int aa[N]; static long long ft1[N], ft2[N]; int n, k, q, h, i, j; scanf("%d%d", &n, &k); for (i = 0; i < n; i++) scanf("%d", &aa[i]); for (i = 0; i < n; i++) update(ft1, i, n, aa[i]), update(ft2, i, n, (long long) aa[i] * i); scanf("%d", &q); while (q--) { static int ii[K]; int t, l, r, m, tmp; scanf("%d", &t); if (t == 1) { for (h = 0; h < k; h++) scanf("%d", &ii[h]), ii[h]--; for (h = 0; h < k; h++) { i = ii[h], j = ii[(h + 1) % k]; update(ft1, i, n, aa[j] - aa[i]), update(ft2, i, n, (long long) (aa[j] - aa[i]) * i); } for (h = 0; h + 1 < k; h++) { i = ii[h], j = ii[h + 1]; tmp = aa[i], aa[i] = aa[j], aa[j] = tmp; } } else { scanf("%d%d%d", &l, &r, &m), l--, r--; printf("%lld\n", query(ft2, r) - query(ft2, l - 1) - (query(ft1, r) - query(ft1, l - 1)) * (l - 1) - (query(ft2, r) - query(ft2, l + m - 1)) + (query(ft1, r) - query(ft1, l + m - 1)) * (l + m - 1) - (query(ft2, r) - query(ft2, r - m + 1)) + (query(ft1, r) - query(ft1, r - m + 1)) * (r - m + 1)); } } return 0; }

Compilation message (stderr)

Main.c: In function 'main':
Main.c:28:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |  scanf("%d%d", &n, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~
Main.c:30:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
Main.c:33:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |  scanf("%d", &q);
      |  ^~~~~~~~~~~~~~~
Main.c:38:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf("%d", &t);
      |   ^~~~~~~~~~~~~~~
Main.c:41:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     scanf("%d", &ii[h]), ii[h]--;
      |     ^~~~~~~~~~~~~~~~~~~
Main.c:51:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |    scanf("%d%d%d", &l, &r, &m), l--, r--;
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...