当前位置:网站首页>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;
}
边栏推荐
- LLVM之父Chris Lattner:为什么我们要重建AI基础设施软件
- Infix expression evaluation
- One dimensional vector transpose point multiplication np dot
- Reasons for the insecurity of C language standard function scanf
- Warning: retrying occurs during PIP installation
- Ros- learn basic knowledge of 0 ROS - nodes, running ROS nodes, topics, services, etc
- TF coordinate transformation of common components of ros-9 ROS
- Adaboost使用
- Basic number theory - factors
- How many checks does kubedm series-01-preflight have
猜你喜欢
Shift operation of complement
[牛客网刷题 Day4] JZ35 复杂链表的复制
Guess riddles (5)
Business modeling of software model | overview
Use and programming method of ros-8 parameters
Halcon snap, get the area and position of coins
资源变现小程序添加折扣充值和折扣影票插件
Guess riddles (6)
How to manage the performance of R & D team?
Programming implementation of ROS learning 5-client node
随机推荐
Codeworks round 638 (Div. 2) cute new problem solution
轮子1:QCustomPlot初始化模板
287. Looking for repeats - fast and slow pointer
Pytorch entry record
golang 基础 ——map、数组、切片 存放不同类型的数据
Shift operation of complement
Program error record 1:valueerror: invalid literal for int() with base 10: '2.3‘
c#比较两张图像的差异
C#图像差异对比:图像相减(指针法、高速)
Ros- learn basic knowledge of 0 ROS - nodes, running ROS nodes, topics, services, etc
Golang foundation -- map, array and slice store different types of data
Kubedm series-00-overview
猜谜语啦(6)
My experience from technology to product manager
[牛客网刷题 Day4] JZ32 从上往下打印二叉树
C#绘制带控制点的Bezier曲线,用于点阵图像及矢量图形
猜谜语啦(142)
皮尔森相关系数
IT冷知识(更新ing~)
Digital analog 2: integer programming