Submission #838495

#TimeUsernameProblemLanguageResultExecution timeMemory
838495BlockOGAddk (eJOI21_addk)C++14
36 / 100
2033 ms1396 KiB
#include <iostream> using namespace std; int a[100000]; long long b[100001]; long long bsum(int n, int i) { long long res = 0; i = min(++i, n); while (i > 0) { res += b[i]; i -= i & -i; } return res; } void bchg(int n, int i, int c) { i++; while (i <= n) { b[i] += c; i += i & -i; } } int main() { int n, k; cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; bchg(n, i, a[i]); } int q; cin >> q; for (int it = 0; it < q; it++) { int code; cin >> code; if (code == 1) { if (k > 1) { int i, j; cin >> i; i--; j = i; int tmp = a[j]; for (int l = 1; l < k; l++) { int m; cin >> m; m--; bchg(n, i, a[m] - a[i]); a[i] = a[m]; i = m; } bchg(n, i, tmp - a[i]); a[i] = tmp; } else cin >> code; } else { int l, r, m; cin >> l >> r >> m; long long res = 0; for (int i = l - 2; i < r - m; i++) res += bsum(n, i + m) - bsum(n, i); cout << res << endl; } } }

Compilation message (stderr)

Main.cpp: In function 'long long int bsum(int, int)':
Main.cpp:10:7: warning: operation on 'i' may be undefined [-Wsequence-point]
   10 |     i = min(++i, n); while (i > 0) {
      |     ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...