1 solutions

  • 0
    @ 2025-11-5 17:26:53

    C++ :

    #include <cstdio>
    
    using namespace std;
    
    int n,tree[200001],data[200001],l,r,tp,m;
    
    inline int in(){
    	char c=getchar();
    	int x=0;
    	while(c<'0'||c>'9')c=getchar();
    	for(;c>='0'&&c<='9';c=getchar())x=x*10+c-'0';
    	return x;
    }
    
    void modify(int pos,int val)
    {
    	while(pos<=n)
    	{
    		tree[pos]+=val;
    		pos+=pos&(-pos);
    	}
    	return;
    }
    
    int SUM(int pos)
    {
    	int Sum=0;
    	while(pos>0)
    	{
    		Sum+=tree[pos];
    		pos-=pos&(-pos);
    	}
    	return Sum;
    }
    
    int main()
    {
    	scanf("%d",&n);
    	for(int i=1;i<=n;i++)
    	{
    		data[i]=in();
    		modify(i,data[i]);
    	}
    	scanf("%d",&m);
    	for(int i=1;i<=m;i++)
    	{
    		l=in();r=in();
    		printf("%.2lf\n",(SUM(r)-SUM(l-1))*3.14);
    		tp=(l+r)>>1;
    		modify(tp,-data[tp]);
    		data[tp]=0;
    	}
    	return 0;
    }
    
    • 1

    Information

    ID
    18437
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By