题意
题目链接
单点修改,区间mod,区间和
sol
如果x > mod ,那么 x % mod < x / 2
证明:
即得易见平凡,
仿照上例显然,
留作习题答案略,
读者自证不难。
反之亦然同理,
推论自然成立,
略去过程q.e.d.,
由上可知证毕。
然后维护个最大值就做完了。。
复杂度不知道是一个log还是两个log,大概是两个吧(线段树一个+最多改log次。)
#include<bits/stdc++.h> #define pair pair<int, int> #define mp(x, y) make_pair(x, y) #define fi first #define se second //#define int long long #define ll long long #define fin(x) {freopen(#x".in","r",stdin);} #define fout(x) {freopen(#x".out","w",stdout);} using namespace std; const int maxn = 1e6 + 10, mod = 1e9 + 7, inf = 1e9 + 10; const double eps = 1e-9; template <typename a, typename b> inline bool chmin(a &a, b b){if(a > b) {a = b; return 1;} return 0;} template <typename a, typename b> inline bool chmax(a &a, b b){if(a < b) {a = b; return 1;} return 0;} template <typename a, typename b> inline ll add(a x, b y) {if(x + y < 0) return x + y + mod; return x + y >= mod ? x + y - mod : x + y;} template <typename a, typename b> inline void add2(a &x, b y) {if(x + y < 0) x = x + y + mod; else x = (x + y >= mod ? x + y - mod : x + y);} template <typename a, typename b> inline ll mul(a x, b y) {return 1ll * x * y % mod;} template <typename a, typename b> inline void mul2(a &x, b y) {x = (1ll * x * y % mod + mod) % mod;} template <typename a> inline void debug(a a){cout << a << 'n';} template <typename a> inline ll sqr(a x){return 1ll * x * x;} inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } int n, m, a[maxn]; #define ls k << 1 #define rs k << 1 | 1 ll sum[maxn]; int mx[maxn]; void update(int k) { sum[k] = sum[ls] + sum[rs]; mx[k] = max(mx[ls], mx[rs]); } void build(int k, int ll, int rr) { if(ll == rr) {sum[k] = mx[k] = read(); return ;} int mid = ll + rr >> 1; build(ls, ll, mid); build(rs, mid + 1, rr); update(k); } ll query(int k, int l, int r, int ql, int qr) { if(ql <= l && r <= qr) return sum[k]; int mid = l + r >> 1; if(ql > mid) return query(rs, mid + 1, r, ql, qr); else if(qr <= mid) return query(ls, l, mid, ql, qr); else return query(ls, l, mid, ql, qr) + query(rs, mid + 1, r, ql, qr); } void modify(int k, int l, int r, int p, int v) { if(l == r) {sum[k] = mx[k] = v; return ;} int mid = l + r >> 1; if(p <= mid) modify(ls, l, mid, p, v); else modify(rs, mid + 1, r, p, v); update(k); } void mod(int k, int l, int r, int ql, int qr, int x) { if(mx[k] < x) return ; if(l == r) {sum[k] = mx[k] % x; mx[k] %= x; return ;} int mid = l + r >> 1; if(ql <= mid) mod(ls, l, mid, ql, qr, x); if(qr > mid) mod(rs, mid + 1, r, ql, qr, x); update(k); } signed main() { n = read(); m = read(); build(1, 1, n); while(m--) { int opt = read(); if(opt == 1) { int l = read(), r = read(); cout << query(1, 1, n, l, r) << 'n'; } else if(opt == 2) { int l = read(), r = read(), x = read(); mod(1, 1, n, l, r, x); } else { int k = read(), x = read(); modify(1, 1, n, k, x); } } return 0; } /* */
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/605333.html