ACM-ICPC 2018徐州网络赛-H题 Ryuji doesn't want to study
Posted qq965921539
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ACM-ICPC 2018徐州网络赛-H题 Ryuji doesn't want to study相关的知识,希望对你有一定的参考价值。
C*M....死于update的一个long long写成int了
心累 不想写过程了 ********
树状数组,一个平的一个斜着的,怎么斜都行
题库链接:https://nanti.jisuanke.com/t/31460
#include <iostream> #include <cstring> #define ll long long #define lowbit(x) (x & -x) using namespace std; const int maxn = 1e5 + 20; int n, m; ll t[maxn]; ll t1[maxn]; ll ans[maxn]; ll search(int pos, int r) { ll sum = 0; r = n - r; while (pos) { sum += t[pos]; sum -= r * t1[pos]; pos -= lowbit(pos); } return sum; } void update(int pos, int val) { int x = pos; while (pos <= n) { t[pos] += (n - x + 1) * val; t1[pos] += val; pos += lowbit(pos); } } void update1(int pos, ll val) { val = val - search(pos, pos) + search(pos - 1,pos); int x = pos; while (pos <= n) { t[pos] += (n - x + 1) * val; t1[pos] += val; pos += lowbit(pos); } } void init() { memset(t, 0, sizeof(t)); memset(t1, 0, sizeof(t1)); for (int i = 1; i <= n; i++) update(i, ans[i]); } int main() { ios::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> ans[i]; init(); while (m--) { int op; ll a, b; cin >> op >> a >> b; if (op == 1) cout << search(b, b) - search(a - 1, b) << endl; else update1(a, b); } return 0; }
以上是关于ACM-ICPC 2018徐州网络赛-H题 Ryuji doesn't want to study的主要内容,如果未能解决你的问题,请参考以下文章