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
原文地址:https://www.cnblogs.com/qq965921539/p/9623617.html
时间: 2024-11-05 22:04:41