求区间不同数的个数【树状数组求解】

树状数组求解

离线

模板

#include
#include

using namespace std;
const int N=300005,M=200005;
struct Query{
	int l,r,id;
	bool operator<(const Query &a)const
	{
		return r==a.r?(l0){
		ans+=sum[x];
		x-=lowbit(x);
	}
	return ans;
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	  scanf("%d",&a[i]);
	int Q;
	scanf("%d",&Q);
	for(int i=0;i

 

你可能感兴趣的:(数据结构)