当前位置:网站首页>Codeforces round 684 (Div. 2) e - green shopping (line segment tree)
Codeforces round 684 (Div. 2) e - green shopping (line segment tree)
2022-07-05 08:52:00 【Qizi K】
I have time to fill in my thoughts or something qwq
#include <bits/stdc++.h>
#define rep(n) for(int i = 1; i <= (n); ++i)
#define ll long long
using namespace std;
const int N = 400010;
int n,m;
ll w[N];
struct node{
int l, r;
ll maxx, minn, sum, lazy;
}tr[4 * N];
void pushup(int u){
tr[u].sum = tr[u << 1].sum + tr[u << 1 | 1].sum;
tr[u].maxx = max(tr[u << 1].maxx, tr[u << 1 | 1].maxx);
tr[u].minn = min(tr[u << 1].minn, tr[u << 1 | 1].minn);
}
void pushdown(int u){
if(tr[u].lazy){
tr[u << 1].sum = tr[u].lazy * (tr[u << 1].r - tr[u << 1].l + 1);
tr[u << 1 | 1].sum = tr[u].lazy * (tr[u << 1 | 1].r - tr[u << 1 | 1].l + 1);
tr[u << 1].lazy = tr[u << 1].minn = tr[u << 1].maxx = tr[u].lazy;
tr[u << 1 | 1].lazy = tr[u << 1 | 1].minn = tr[u << 1 | 1].maxx = tr[u].lazy;
tr[u].lazy = 0;
}
}
void build(int u, int l, int r){
if(l == r) tr[u] = {
l,r,w[l],w[l],w[l],0};
else{
tr[u].l = l, tr[u].r = r;
int mid = l + r >> 1;
build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
pushup(u);
}
}
void modify(int u, int l, int r, ll val){
if(tr[u].minn >= val) return ;
if(tr[u].l >= l && tr[u].r <= r && tr[u].maxx <= val){
tr[u].sum = val * (tr[u].r - tr[u].l + 1);
tr[u].maxx = tr[u].minn = tr[u].lazy = val;
}else{
pushdown(u);
int mid = tr[u].l + tr[u].r >> 1;
if(l <= mid) modify(u << 1, l, r, val);
if(r > mid) modify(u << 1 | 1, l, r, val);
pushup(u);
}
}
ll query(int u, int l, int r, ll& val){
if(tr[u].minn > val) return 0;
if(tr[u].l >= l && tr[u].r <= r && tr[u].sum <= val){
val -= tr[u].sum;
return tr[u].r - tr[u].l + 1;
}else{
pushdown(u);
ll res = 0;
int mid = tr[u].l + tr[u].r >> 1;
if(l <= mid) res += query(u << 1, l, r, val);
if(r > mid) res += query(u << 1 | 1, l, r, val);
return res;
}
}
int main(){
cin >> n >> m;
rep(n) scanf("%lld", &w[i]);
build(1,1,n);
rep(m){
int op, x;
ll y;
scanf("%d%d%lld",&op,&x,&y);
if(op == 1) modify(1,1,x,y);
else printf("%lld\n", query(1,x,n,y));
}
return 0;
}
边栏推荐
- Guess riddles (8)
- Add discount recharge and discount shadow ticket plug-ins to the resource realization applet
- Guess riddles (4)
- MPSoC QSPI flash upgrade method
- My university
- Run menu analysis
- 微信H5公众号获取openid爬坑记
- How apaas is applied in different organizational structures
- Typescript hands-on tutorial, easy to understand
- RT thread kernel quick start, kernel implementation and application development learning with notes
猜你喜欢
猜谜语啦(4)
RT thread kernel quick start, kernel implementation and application development learning with notes
Guess riddles (6)
Solution to the problems of the 17th Zhejiang University City College Program Design Competition (synchronized competition)
Run menu analysis
Programming implementation of ROS learning 2 publisher node
猜谜语啦(142)
Guess riddles (4)
深度学习模型与湿实验的结合,有望用于代谢通量分析
Solutions of ordinary differential equations (2) examples
随机推荐
Halcon affine transformations to regions
使用arm Neon操作,提高内存拷贝速度
Halcon shape_ trans
Ecmascript6 introduction and environment construction
某公司文件服务器迁移方案
golang 基础 —— golang 向 mysql 插入的时间数据和本地时间不一致
Latex improve
2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition
AdaBoost use
Business modeling of software model | overview
图解八道经典指针笔试题
Typescript hands-on tutorial, easy to understand
Codeforces Round #648 (Div. 2) E.Maximum Subsequence Value
【日常训练】1200. 最小绝对差
520 diamond Championship 7-4 7-7 solution
Redis实现高性能的全文搜索引擎---RediSearch
ROS learning 1- create workspaces and function packs
js异步错误处理
golang 基础 ——map、数组、切片 存放不同类型的数据
Infix expression evaluation