QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#820248#9877. Segment TreeProsperityWA 1ms5776kbC++231.9kb2024-12-18 20:24:082024-12-18 20:24:14

Judging History

你现在查看的是最新测评结果

  • [2024-12-18 20:24:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5776kb
  • [2024-12-18 20:24:08]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;

inline ll read(){
	ll s=0,k=1;
	char c=getchar();
	while(c>'9'||c<'0'){
		if(c=='-') k=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		s=(s<<3)+(s<<1)+(c^48);
		c=getchar();
	}
	return s*k;
}

const int N=262200;
int n,q;
bool vis[N<<2];
struct Tree{
	ll s,v,f[2];
}t[N<<2];
struct node{
	int id,l,r;
};

void build(int s,int l,int r){
	if(l==r) {
		t[s].s=t[s].v;
		return ;
	}
	int mid=l+r>>1;
	build(s<<1,l,mid);
	build(s<<1|1,mid+1,r);
	t[s].s=min(t[s].v,t[s<<1].s+t[s<<1|1].s);
}

void update(int s,int l,int r,int L,int R){
	if(L<=l&&r<=R){
		t[s].f[0]=t[s].s;
		t[s].f[1]=0;
		return ;
	}
	int mid=l+r>>1;
	if(L<=mid) update(s<<1,l,mid,L,R);
	else t[s<<1].f[0]=0,t[s<<1].f[1]=t[s<<1].s;
	if(R>mid) update(s<<1|1,mid+1,r,L,R);
	else t[s<<1|1].f[0]=0,t[s<<1|1].f[1]=t[s<<1|1].s;
	t[s].f[0]=t[s<<1].f[0]+t[s<<1|1].f[0];
	t[s].f[1]=t[s<<1].f[1]+t[s<<1|1].f[1];
	ll f0=t[s].f[1]+t[s].s,f1=t[s].f[0]+t[s].s;
	t[s].f[0]=min(t[s].f[0],f0);
	t[s].f[1]=min(t[s].f[1],f1);
}

int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n=read();
	n=1<<n;
	{
	queue<node>q;
	q.push({1,1,n});
	while(!q.empty()){
		node x=q.front();
		q.pop();
		t[x.id].v=read();
		if(x.l==x.r){
			vis[x.id]=1;
			continue;	
		}
		int mid=x.l+x.r>>1;
		q.push({x.id<<1,x.l,mid});
		q.push({x.id<<1|1,mid+1,x.r});
	}
	}
	build(1,1,n);
	q=read();
	while(q--){
		int op=read();
		if(op==1){
			int x=read();
			ll w=read();
			t[x].v=w;
			t[x].s=w;
			if(!vis[x]) t[x].s=min(t[x].v,t[x<<1].s+t[x<<1|1].s);
			x>>=1;
			while(x){
				t[x].s=min(t[x].v,t[x<<1].s+t[x<<1|1].s);
				x>>=1;
			}
		}
		else{
			int s=read(),R=read();
			update(1,1,n,s+1,R);
			printf("%lld\n",t[1].f[0]);
		}
		for(int i=1;i<=3;i++) printf("%lld %lld\n",t[i].s,t[i].v);puts("");
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5776kb

input:

3
7 1 14 3 9 4 8 2 6 5 5 13 8 2 3
10
2 0 1
2 0 4
2 4 6
2 4 8
2 3 5
1 6 30
2 3 5
2 4 6
1 1 10000000
2 0 8

output:

2
7 7
1 1
9 14

1
7 7
1 1
9 14

4
7 7
1 1
9 14

8
7 7
1 1
9 14

17
7 7
1 1
9 14

7 7
1 1
14 14

18
7 7
1 1
14 14

13
7 7
1 1
14 14

15 10000000
1 1
14 14

15
15 10000000
1 1
14 14


result:

wrong answer 2nd words differ - expected: '1', found: '7'