求助这段代码为什么RE
  • 板块灌水区
  • 楼主xiaoyang111
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/1/28 18:25
  • 上次更新2024/1/28 20:31:57
查看原帖
求助这段代码为什么RE
890311
xiaoyang111楼主2024/1/28 18:25
#include <iostream>
#include <vector>
#include <tuple>
using namespace std;
void pushup(vector<tuple<int,int,int>> &t,int root){
	get<2>(t[root])=max(get<2>(t[root<<1]),get<2>(t[root<<1|1]));
}
void build(vector<tuple<int,int,int>> &t,const vector<int> &w,
		   int root,int left,int right){
	if (left==right){
		t[root]=make_tuple(left,right,w[right]);
		return;
	}
	t[root]=make_tuple(left,right,-2e9);
	int mid=left+right>>1;
	build(t,w,root<<1,left,mid);
	build(t,w,root<<1|1,mid+1,right);
	pushup(t,root);
}
int query(vector<tuple<int,int,int>> &t,int root,
		  int left,int right){
	if (left<=get<0>(t[root]) && get<1>(t[root])<=right){
		return get<2>(t[root]);
	}
	int mid=get<0>(t[root])+get<1>(t[root])>>1;
	int sm=-2e9;
	if (left<=mid){
		sm=max(query(t,root<<1,left,right),sm); 
	}
	if (right>mid){
		sm=max(query(t,root<<1|1,left,right),sm);
	}
	return sm;
}
void modify(vector<tuple<int,int,int>> &t,int root,
			int x,int v){
	if (get<0>(t[root])==get<1>(t[root])){
		get<2>(t[root])=max(v,get<2>(t[root]));
		return;
	}
	int mid=get<0>(t[root])+get<1>(t[root])>>1;
	if (x<=mid){
		modify(t,root<<1,x,v);
	}else{
		modify(t,root<<1|1,x,v);
	}
	pushup(t,root);
}
int main(){
	int n=1e6,m=3e5;
//	cin >> n >> m;
	vector<int> w(n+1);
	vector<tuple<int,int,int>> t(2*n);
	for (int i=1;i<=n;++i){
//		scanf("%d",&w[i]);
		w[i]=i;
	}
	build(t,w,1,1,n);
	for (int i=0;i<m;++i){
		int x=1,y=n-1;
//		scanf("%d%d",&x,&y);
		printf("%d ",query(t,1,x,y));
	}
	return 0;
}

我还是太菜了

2024/1/28 18:25
加载中...