其他分享
首页 > 其他分享> > HDU 1166

HDU 1166

作者:互联网

 

#include <string>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;
int n,m;
int c[500005];
int lowbit(int x)
{

	return (-x)&x;

}

void add(int pos,int x)

{

	while(pos<=n)

	{

		c[pos]+=x;

		pos+=lowbit(pos);

	}

}

void input()

{

	int x;

	for(int i=1; i<=n; i++)

	{

		scanf("%d",&x);

		add(i,x);

	}

}

int query(int pos)

{

	int res=0;

	while(pos>0)

	{

		res+=c[pos];

		pos-=lowbit(pos);

	}

	return res;

}

int main()

{

	int t,cnt = 0;
	scanf("%d",&t);
	while(t--) {
		printf("Case %d:\n",++cnt);
		scanf("%d",&n);
		memset(c,0,sizeof(c));
		input();
		int x,y;
		string f;
		while(cin>>f&&f[0]!='E') {
			cin>>x>>y;
			if(f[0]=='A')
				add(x,y);
			else if(f[0]=='Q')
				cout<<query(y)-query(x-1)<<endl;
			else if(f[0]=='S')
				add(x,-1*y);

		}
	//	if(t!=0)printf("\n");
	}


	return 0;

}

 

标签:HDU,int,res,1166,pos,while,cnt,include
来源: https://blog.csdn.net/qq_41603898/article/details/90550998