记录编号 58241 评测结果 AAAAAAAAAA
题目名称 最终得分 100
用户昵称 Gravatarcstdio 是否通过 通过
代码语言 C++ 运行时间 3.108 s
提交时间 2013-04-18 18:36:18 内存使用 8.71 MiB
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<deque>
#include<algorithm>
#include<iomanip>
using namespace std;
const int SIZEN=200001;
class SEGMENT{
public:
	int l,r;
	int lchild,rchild;
	int s;
	SEGMENT(){l=r=lchild=rchild=s=0;}
	void build(int l,int r);
}tree[2*SIZEN];
int n;
int d[SIZEN]={0};
int tot=0;
void SEGMENT::build(int lnow,int rnow){
	l=lnow,r=rnow;
	if(l==r){
		s=d[l];
		lchild=rchild=-1;
	}
	else{
		int mid=(l+r)>>1;
		lchild=++tot;
		tree[lchild].build(l,mid);
		rchild=++tot;
		tree[rchild].build(mid+1,r);
		s=tree[lchild].s+tree[rchild].s;
	}
}
#define now tree[root]
void dec(int root,int x,int c){//把x号减去c
	if(root==-1||now.l>x||now.r<x) return;
	now.s-=c;
	dec(now.lchild,x,c);
	dec(now.rchild,x,c);
}
int getsum(int root,int x,int y){
	if(root==-1||now.l>y||now.r<x) return 0;
	if(x<=now.l&&y>=now.r) return now.s;
	else return getsum(now.lchild,x,y)+getsum(now.rchild,x,y);
}
void work(void){
	int m,x,y,mid;
	scanf("%d",&n);
	int i;
	for(i=1;i<=n;i++) scanf("%d",&d[i]);
	tree[tot].build(1,n);
	scanf("%d",&m);
	double ans;
	for(i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		ans=(double)getsum(0,x,y);
		cout<<ans*3.14<<endl;
		mid=(x+y)>>1;
		dec(0,mid,d[mid]);
		d[mid]=0;
	}
}
int main(){
	freopen("treed.in","r",stdin);
	freopen("treed.out","w",stdout);
	cout<<setiosflags(ios::fixed)<<setprecision(2);
	work();
	return 0;
}