社区讨论
这到底哪里有错呀,跪求大牛排错
P1531I Hate It参与者 1已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mi6m2th9
- 此快照首次捕获于
- 2025/11/20 07:06 4 个月前
- 此快照最后确认于
- 2025/11/20 07:06 4 个月前
样例输出 5669
CPP#include<cstdio>
#include<iostream>
#include<algorithm>
//#define ll long long
using namespace std;
int n,p,a,b,m,x,y;
int ans;
struct node
{
int l;
int r;
int w;
int f;
int minn;
int maxn;
}tree[4000001];
void build(int k,int ll,int rr)//建树
{
tree[k].l=ll,tree[k].r=rr;
if(tree[k].l==tree[k].r)
{
cin>>tree[k].w;
tree[k].minn=tree[k].w;
tree[k].maxn=tree[k].w;
return;
}
int m=(ll+rr)/2;
build(2*k,ll,m);
build(2*k+1,m+1,rr);
tree[k].w=tree[k*2].w+tree[k*2+1].w;
tree[k].minn=min(tree[k*2].minn,tree[k*2+1].minn);
tree[k].maxn=max(tree[k*2].maxn,tree[k*2+1].maxn);
}
void ask_p(int k)//单点查询
{
if(tree[k].l==tree[k].r)
{
ans=tree[k].w;
return;
}
if(tree[k].f)down(k);
int m=(tree[k].l+tree[k].r)/2;
if(x<=m)ask_p(k*2);
else ask_p(k*2+1);
}
void change_p(int k)//单点修改
{
if(tree[k].l==tree[k].r)
{
tree[k].w=y;
tree[k].maxn=y;
tree[k].minn=y;
return;
}
//if(tree[k].f)down(k);
int m=(tree[k].l+tree[k].r)/2;
if(x<=m)change_p(k*2);
else change_p(k*2+1);
tree[k].w=tree[k*2].w+tree[k*2+1].w;
tree[k].minn=min(tree[k*2].minn,tree[k*2+1].minn);
tree[k].maxn=max(tree[k*2].maxn,tree[k*2+1].maxn);
}
void ask_max(int k)
{
if(tree[k].l>=a&&tree[k].r<=b)
{
ans=max(ans,tree[k].maxn);
return;
}
// down(k);
int m=(tree[k].l+tree[k].r)/2;
if(a<=m)ask_max(k*2);
if(b>m)ask_max(k*2+1);
// tree[k].maxn=max(tree[k*2].maxn,tree[k*2+1].maxn);
}
int main()
{
//freopen("123.txt","r",stdin);
cin>>n;
cin>>m;
build(1,1,n);
char a;
for(int i=1;i<=m;i++)
{ ans=0;
cin>>a;
x=0;y=0;
if(a=='Q')
{ ans=-23;
cin>>a>>b;
ask_max(1);
cout<<ans<<"\n";
ans=-23;
}
if(a=='U')
{
cin>>x;
cin>>y;
ask_p(1);
if(ans>=y)continue;
else {
change_p(1);
}
}
}
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...