Submission #1217536

#TimeUsernameProblemLanguageResultExecution timeMemory
1217536badge881Addk (eJOI21_addk)C++20
100 / 100
1358 ms4760 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int inf = 1e16; const int N = 2e5 + 10; const int mod = 1e9 + 7; int t[N * 4], a[N]; void update(int v, int tl, int tr, int pos) { if (tl == tr) { t[v] = a[tl]; return; } int m = (tl + tr) / 2; if (pos <= m) update(v * 2, tl, m, pos); else update(v * 2 + 1, m + 1, tr, pos); t[v] = t[v * 2] + t[v * 2 + 1]; } int get(int v, int tl, int tr, int l, int r) { if (tl >= l && tr <= r) return t[v]; if (l > tr || r < tl) return 0; int m = (tl + tr) / 2; return get(v * 2, tl, m, l, r) + get(v * 2 + 1, m + 1, tr, l, r); } signed main() { int n, k; scanf("%lld %lld", &n, &k); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); update(1, 1, n, i); } int q; scanf("%lld", &q); while (q--) { int type; scanf("%lld\n", &type); if (type == 1) { int pos[k + 1], val[k + 1]; for (int i = 1; i <= k; i++) { int x; scanf("%lld", &x); pos[i] = x; val[i] = a[x]; } for (int i = 1; i <= k; i++) { if (i == k) a[pos[i]] = val[1]; else a[pos[i]] = val[i + 1]; update(1, 1, n, pos[i]); } } else { int l, r, m; scanf("%lld %lld %lld", &l, &r, &m); int ans = get(1, 1, n, l, r) * m; for (int i = l, x = m - 1; x > 0; i++, x--) ans -= a[i] * x; for (int i = r, x = m - 1; x > 0; i--, x--) ans -= a[i] * x; printf("%lld\n", ans); } } }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     scanf("%lld %lld", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~
Main.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |         scanf("%lld", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
Main.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |     scanf("%lld", &q);
      |     ~~~~~^~~~~~~~~~~~
Main.cpp:49:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         scanf("%lld\n", &type);
      |         ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:56:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |                 scanf("%lld", &x);
      |                 ~~~~~^~~~~~~~~~~~
Main.cpp:72:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |             scanf("%lld %lld %lld", &l, &r, &m);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...