You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
1.9 KiB
92 lines
1.9 KiB
#include <cstdio>
|
|
#include <cstring>
|
|
#include <algorithm>
|
|
#include <iostream>
|
|
#include <cmath>
|
|
using namespace std;
|
|
|
|
#define ls u << 1
|
|
#define rs u << 1 | 1
|
|
|
|
int n, m;
|
|
typedef long long LL;
|
|
const int N = 1e5 + 10;
|
|
int a[N];
|
|
|
|
struct Node {
|
|
int l, r;
|
|
LL sum, max;
|
|
} tr[N << 2];
|
|
|
|
void pushup(int u) {
|
|
tr[u].sum = tr[ls].sum + tr[rs].sum;
|
|
tr[u].max = max(tr[ls].max, tr[rs].max);
|
|
}
|
|
|
|
void build(int u, int l, int r) {
|
|
tr[u] = {l, r, 0, 0};
|
|
if (l == r) {
|
|
tr[u].max = tr[u].sum = a[l];
|
|
return;
|
|
}
|
|
int mid = (l + r) >> 1;
|
|
build(ls, l, mid), build(rs, mid + 1, r);
|
|
|
|
pushup(u);
|
|
}
|
|
|
|
void modify(int u, int x, int c) {
|
|
if (tr[u].l > x || tr[u].r < x) return;
|
|
if (tr[u].l == tr[u].r) {
|
|
tr[u].sum = tr[u].max = c;
|
|
return;
|
|
}
|
|
modify(ls, x, c), modify(rs, x, c);
|
|
pushup(u);
|
|
}
|
|
|
|
void modify(int u, int l, int r, int x) {
|
|
if (tr[u].l > r || tr[u].r < l) return;
|
|
if (tr[u].max < x) return; //剪枝
|
|
|
|
if (tr[u].l == tr[u].r) {
|
|
tr[u].sum %= x;
|
|
tr[u].max = tr[u].sum;
|
|
return;
|
|
}
|
|
modify(ls, l, r, x), modify(rs, l, r, x);
|
|
pushup(u);
|
|
}
|
|
|
|
LL query(int u, int l, int r) {
|
|
if (tr[u].l > r || tr[u].r < l) return 0;
|
|
if (tr[u].l >= l && tr[u].r <= r) return tr[u].sum;
|
|
return query(ls, l, r) + query(rs, l, r);
|
|
}
|
|
|
|
int main() {
|
|
ios::sync_with_stdio(false), cin.tie(0);
|
|
cin >> n >> m;
|
|
for (int i = 1; i <= n; i++) cin >> a[i];
|
|
|
|
build(1, 1, n);
|
|
|
|
int l, r, k, x;
|
|
while (m--) {
|
|
int op;
|
|
cin >> op;
|
|
if (op == 1) {
|
|
cin >> l >> r;
|
|
printf("%lld\n", query(1, l, r));
|
|
}
|
|
if (op == 2) {
|
|
cin >> l >> r >> x;
|
|
modify(1, l, r, x);
|
|
}
|
|
if (op == 3) {
|
|
cin >> k >> x;
|
|
modify(1, k, x);
|
|
}
|
|
}
|
|
return 0;
|
|
} |