// %%%Skyqwq#include<bits/stdc++.h>//#define int long long#define help {cin.tie(NULL); cout.tie(NULL);}#define pb push_back#define fi first#define se second#define mkp make_pairusingnamespace std;
typedeflonglong LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
template <typename T> boolchkMax(T &x, T y){ return (y > x) ? x = y, 1 : 0; }
template <typename T> boolchkMin(T &x, T y){ return (y < x) ? x = y, 1 : 0; }
template <typename T> voidinlineread(T &x){
int f = 1; x = 0; char s = getchar();
while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
x *= f;
}
constint N=1e6+5;
int n,q,lst[N],a[N],b[N];
intmain(){
scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=1;i<=q;i++)
{
int op,x,y;
scanf("%d",&op);
if(op==1)
{
scanf("%d%d",&x,&y);
a[x]=y;
lst[x]=i;
}
else {
scanf("%d",&x);
b[i]=x;
}
}
for(int i=q-1;~i;i--)b[i]=max(b[i],b[i+1]);
for(int i=1;i<=n;i++)printf("%d ",max(a[i],b[lst[i]]));
return0;
}
线段树
// %%%Skyqwq#include<bits/stdc++.h>//#define int long long#define help {cin.tie(NULL); cout.tie(NULL);}#define pb push_back#define fi first#define se second#define mkp make_pairusingnamespace std;
typedeflonglong LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
template <typename T> boolchkMax(T &x, T y){ return (y > x) ? x = y, 1 : 0; }
template <typename T> boolchkMin(T &x, T y){ return (y < x) ? x = y, 1 : 0; }
template <typename T> voidinlineread(T &x){
int f = 1; x = 0; char s = getchar();
while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
x *= f;
}
constint N=1e6+5;
int n,q;
structTr{
int l,r,val,lazy;
}tr[4*N];
voidpushup(int p){
tr[p].val=max(tr[p<<1].val,tr[p<<1|1].val);
}
voidpushdown(int p){
if(tr[p].lazy)
{
int &add=tr[p].lazy;
tr[p<<1].val=max(tr[p<<1].val,add);
tr[p<<1|1].val=max(tr[p<<1|1].val,add);
tr[p<<1].lazy=max(tr[p<<1].lazy,add);
tr[p<<1|1].lazy=max(tr[p<<1|1].lazy,add);
add=0;
}
}
voidbuild(int p,int l,int r){
tr[p]={l,r,0,0};
if(l==r)
{
scanf("%d",&tr[p].val);
tr[p].lazy=tr[p].val;
return ;
}
int mid=l+r>>1;
build(p<<1,l,mid);
build(p<<1|1,mid+1,r);
pushup(p);
}
voidchange1(int p,int l,int r,int x,int y){
if(l==r)
{
tr[p].val=y;
return ;
}
pushdown(p);
int mid=l+r>>1;
if(x<=mid)change1(p<<1,l,mid,x,y);
elsechange1(p<<1|1,mid+1,r,x,y);
pushup(p);
}
voidchange2(int p,int y){
tr[p].lazy=max(tr[p].lazy,y);
tr[p].val=max(tr[p].val,y);
}
intask(int p,int l,int r,int x){
if(l==r)return tr[p].val;
pushdown(p);
int mid=l+r>>1;
if(x<=mid)returnask(p<<1,l,mid,x);
elsereturnask(p<<1|1,mid+1,r,x);
pushup(p);
}
intmain(){
scanf("%d%d",&n,&q);
build(1,1,n);
while(q--)
{
int op,x,y;
scanf("%d",&op);
if(op==1)
{
scanf("%d%d",&x,&y);
change1(1,1,n,x,y);
}
else {
scanf("%d",&y);
change2(1,y);
}
}
for(int i=1;i<=n;i++)printf("%d ",ask(1,1,n,i));
return0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!