12532

/*****Binary Index tree  12532******/
#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>

#define SZ 100005
#define ll long long

using namespace std;

int num[SZ];
int neg[SZ];
int zero[SZ];
int maxInd;

void update(int *arr,int ind,int val)
{
	while(ind<maxInd)
	{
		arr[ind]+=val;
		ind+=(ind & (-ind));
	}
}


int read(int *arr,int ind)
{
	int res =0;
	while(ind>0)
	{
		res+=arr[ind];
		ind-=(ind & (-ind));
	}
	return res;
}

int main()
{
	int a,n,k;
	string s;
	char ch;
	int valu,idx;
	while(cin>>n)
	{
		cin>>k;
		memset(zero,0,sizeof(zero));
		memset(neg,0,sizeof(neg));

		maxInd =n+1;
		for(int i=1;i<=n;i++)
		{
			cin>>a;
			if(a<0)
			{
				update(neg,i,1);
			}
			else if(a==0)
			{
				update(zero,i,1);
			}
			num[i]=a;
		}
		s="";
		//cout<<n<<" "<<k<<"\n";
		while(k--)
		{
			cin>>ch>>idx>>valu;

			if(ch=='C')
			{
				if(valu<0)
				{
					if(num[idx]==0)
					{
						update(zero,idx,-1);
						update(neg,idx,1);
					}
					else if(num[idx]>0)
					{
						update(neg,idx,1);
					}
				}
				else if(valu==0)
				{
					if(num[idx]>0)
					{
						update(zero,idx,1);
					}
					else if(num[idx]<0)
					{
						update(zero,idx,1);
						update(neg,idx,-1);
					}
				}
				else if(valu>0)
				{
					if(num[idx]==0)
					{
						update(zero,idx,-1);
					}
					else if(num[idx]<0)
					{
						update(neg,idx,-1);
					}
				}

				num[idx] = valu;
			}//end command type check

			else if(ch=='P')
			{
				int d,m;
				d = read(zero,valu) - read(zero,idx-1);
				m = read(neg,valu) - read(neg,idx-1);
				//cout<<"dm = "<<d<<" "<<m<<"\n";
				if(d>0)
				{
					s.append(1u,'0');
					//cout<<"0";
				}
				else if(m%2==1)
				{
					s.append(1u,'-');
					//cout<<"-";
				}
				else if(d==0 && (m%2)==0)
					s.append(1u,'+');
					//cout<<"+";

			}
		}
		cout<<s<<"\n";
	}

	return 0;
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *