比赛 |
4043级2023省选练习赛5 |
评测结果 |
AAAAAATTTT |
题目名称 |
市场 |
最终得分 |
60 |
用户昵称 |
zxhhh |
运行时间 |
12.641 s |
代码语言 |
C++ |
内存使用 |
17.37 MiB |
提交时间 |
2023-03-13 20:57:02 |
显示代码纯文本
//#include <bits/stdc++.h>
//
//using namespace std;
//
//const int N = 1e5 + 5;
//typedef long long ll;
//
//int n, q;
//ll a[N];
//
//int main () {
// freopen("2017market.in", "r", stdin);
// freopen("2017market.out", "w", stdout);
// scanf("%d%d", &n, &q);
// for (int i = 1;i <= n;i++) scanf("%lld", &a[i]);
// while (q--) {
// int op, l, r; ll k;
// scanf("%d%d%d", &op, &l, &r); l++; r++;
// if (op == 1) {
// scanf("%lld", &k);
// for (int i = l;i <= r;i++) a[i] += k;
// }
// else if (op == 2) {
// scanf("%lld", &k);
// for (int i = l;i <= r;i++) {
// if (a[i] >= 0) a[i] = a[i] / k;
// else a[i] = (a[i]-k+1) / k;
// }
// }
// else if (op == 3) {
// ll minn = 0x3f3f3f3f3f3f3f3f;
// for (int i = l;i <= r;i++) minn = min(minn, a[i]);
// cout << minn << endl;
// }
// else {
// ll sum = 0;
// for (int i = l;i <= r;i++) sum += a[i];
// cout << sum << endl;
// }
// }
// return 0;
//}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
int n, q;
ll a[N];
inline ll read () {
ll num = 0; int f = 1; char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') num = (num<<1)+(num<<3)+(ch^48), ch = getchar();
return num*f;
}
ll get_chu (ll x, ll k) {
if (x >= 0) return x/k;
return (x-k+1)/k;
}
struct node {
int flag;
ll s, add, setv, maxn, minn;
}nodes[N << 2];
inline void upd (int p, int l, int r, ll k) {
nodes[p].s += k*(r-l+1);
nodes[p].maxn += k; nodes[p].minn += k; nodes[p].add += k;
}
inline void setupd (int p, int l, int r, ll k) {
nodes[p].maxn = nodes[p].minn = k;
nodes[p].s = k*(r-l+1);
nodes[p].flag = 1; nodes[p].setv = k; nodes[p].add = 0;
}
inline void push_up (int p) {
nodes[p].s = nodes[p<<1].s+nodes[p<<1|1].s;
nodes[p].minn = min(nodes[p<<1].minn, nodes[p<<1|1].minn);
nodes[p].maxn = max(nodes[p<<1].maxn, nodes[p<<1|1].maxn);
}
inline void push_down (int p, int l, int r) {
int mid = (l+r)>>1;
if (nodes[p].flag) {
setupd(p<<1, l, mid, nodes[p].setv); setupd(p<<1|1, mid+1, r, nodes[p].setv);
nodes[p].flag = 0;
}
upd(p<<1, l, mid, nodes[p].add); upd(p<<1|1, mid+1, r, nodes[p].add);
nodes[p].add = 0;
}
void build (int p, int l, int r) {
if (l == r) {
nodes[p].s = nodes[p].maxn = nodes[p].minn = a[l];
return;
}
int mid = (l+r)>>1;
build (p<<1, l, mid); build (p<<1|1, mid+1, r);
push_up(p);
}
void add (int p, int l, int r, int tl, int tr, ll k) {
if (l >= tl && r <= tr) {
upd(p, l, r, k);
return;
}
push_down(p, l, r);
int mid = (l+r)>>1;
if (tl <= mid) add(p<<1, l, mid, tl, tr, k);
if (tr > mid) add(p<<1|1, mid+1, r, tl, tr, k);
push_up(p);
}
void chu (int p, int l, int r, int tl, int tr, ll k) {
if (l >= tl && r <= tr && get_chu(nodes[p].maxn, k) == get_chu(nodes[p].minn, k)) {
setupd(p, l, r, get_chu(nodes[p].maxn, k));
// upd(p, l, r, get_chu(nodes[p].minn, k) - nodes[p].minn);
return;
// nodes[p].maxn = nodes[p].minn = get_chu(nodes[p].maxn, k);
// nodes[p].s = get_chu(nodes[p].maxn, k)*(r-l+1);
}
int mid = (l+r)>>1;
push_down(p, l, r);
if (tl <= mid) chu(p<<1, l, mid, tl, tr, k); if (tr > mid) chu(p<<1|1, mid+1, r, tl, tr, k);
push_up(p);
}
ll minn (int p, int l, int r, int tl, int tr) {
if (l >= tl && r <= tr) return nodes[p].minn;
int mid = (l+r)>>1; ll res = 0x3f3f3f3f3f3f3f3f;
push_down(p, l, r);
if (tl <= mid) res = minn(p<<1, l, mid, tl, tr);
if (tr > mid) res = min(res, minn(p<<1|1, mid+1, r, tl, tr));
return res;
}
ll sum (int p, int l, int r, int tl, int tr) {
if (l >= tl && r <= tr) return nodes[p].s;
int mid = (l+r)>>1; ll res = 0;
push_down(p, l, r);
if (tl <= mid) res += sum(p<<1, l, mid, tl, tr); if (tr > mid) res += sum(p<<1|1, mid+1, r, tl, tr);
return res;
}
int main () {
freopen("2017market.in", "r", stdin);
freopen("2017market.out", "w", stdout);
n = read(); q= read();
for (int i = 1;i <= n;i++) a[i] = read();
build (1, 1, n);
while (q--) {
int op = read(), l =read(), r = read(); ll k;
l++; r++;
if (op == 1) {
k = read();
add(1, 1, n, l, r, k);
}
else if (op == 2) {
k = read();
chu(1, 1, n, l, r, k);
}
else if (op == 3) printf("%lld\n", minn(1, 1, n, l, r));
else printf("%lld\n", sum(1, 1, n, l, r));
// cout << sum(1, 1, n, 1, n) << endl;
}
return 0;
}