当前位置:网站首页>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;
}
边栏推荐
- [牛客网刷题 Day4] JZ55 二叉树的深度
- [Niuke brush questions day4] jz55 depth of binary tree
- Pearson correlation coefficient
- Multiple linear regression (sklearn method)
- Business modeling of software model | stakeholders
- [daily training -- Tencent selected 50] 557 Reverse word III in string
- C#图像差异对比:图像相减(指针法、高速)
- Guess riddles (2)
- [牛客网刷题 Day4] JZ35 复杂链表的复制
- 2020 "Lenovo Cup" National College programming online Invitational Competition and the third Shanghai University of technology programming competition
猜你喜欢

Business modeling of software model | stakeholders
![[牛客网刷题 Day4] JZ35 复杂链表的复制](/img/bc/ce90bb3cb6f52605255f1d6d6894b0.png)
[牛客网刷题 Day4] JZ35 复杂链表的复制

Install the CPU version of tensorflow+cuda+cudnn (ultra detailed)

Numpy pit: after the addition of dimension (n, 1) and dimension (n,) array, the dimension becomes (n, n)

猜谜语啦(3)

Guess riddles (4)

Guess riddles (10)

资源变现小程序添加折扣充值和折扣影票插件

Halcon affine transformations to regions

Numpy 小坑:维度 (n, 1) 和 维度 (n, ) 数组相加运算后维度变为 (n, n)
随机推荐
Use arm neon operation to improve memory copy speed
OpenFeign
Tips 1: Web video playback code
TypeScript手把手教程,简单易懂
Add discount recharge and discount shadow ticket plug-ins to the resource realization applet
kubeadm系列-00-overview
[Niuke brush questions day4] jz55 depth of binary tree
资源变现小程序添加折扣充值和折扣影票插件
asp. Net (c)
Halcon wood texture recognition
520 diamond Championship 7-4 7-7 solution
Pearson correlation coefficient
[daiy4] copy of JZ35 complex linked list
Halcon clolor_ pieces. Hedv: classifier_ Color recognition
C#【必备技能篇】ConfigurationManager 类的使用(文件App.config的使用)
Oracle advanced (III) detailed explanation of data dictionary
Programming implementation of subscriber node of ROS learning 3 subscriber
EA introduction notes
Shift operation of complement
猜谜语啦(7)