当前位置:网站首页>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;
}
边栏推荐
- IT冷知识(更新ing~)
- 多元线性回归(梯度下降法)
- Programming implementation of ROS learning 6 -service node
- [formation quotidienne - Tencent Selection 50] 557. Inverser le mot III dans la chaîne
- [daiy4] copy of JZ35 complex linked list
- Meta tag details
- 某公司文件服务器迁移方案
- [牛客网刷题 Day4] JZ55 二叉树的深度
- Guess riddles (10)
- Numpy 小坑:维度 (n, 1) 和 维度 (n, ) 数组相加运算后维度变为 (n, n)
猜你喜欢
ROS learning 4 custom message
Halcon clolor_ pieces. Hedv: classifier_ Color recognition
图解八道经典指针笔试题
Halcon blob analysis (ball.hdev)
Ros- learn basic knowledge of 0 ROS - nodes, running ROS nodes, topics, services, etc
Classification of plastic surgery: short in long long long
Illustration of eight classic pointer written test questions
[matlab] matlab reads and writes Excel
TypeScript手把手教程,简单易懂
Guess riddles (142)
随机推荐
皮尔森相关系数
Business modeling of software model | overview
Use arm neon operation to improve memory copy speed
ABC#237 C
Run菜单解析
Shift operation of complement
js异步错误处理
JS asynchronous error handling
golang 基础 ——map、数组、切片 存放不同类型的数据
[matlab] matlab reads and writes Excel
Digital analog 1: linear programming
Configuration and startup of kubedm series-02-kubelet
asp. Net (c)
File server migration scheme of a company
MPSoC QSPI flash upgrade method
Guess riddles (6)
Guess riddles (9)
Typescript hands-on tutorial, easy to understand
轮子1:QCustomPlot初始化模板
Add discount recharge and discount shadow ticket plug-ins to the resource realization applet