树状数组的区间更新,单点查询

CSU 1335 高桥和低桥(树状数组)

#include 
#include 
#include 
#include 
using namespace std;
const int maxn = 1e5+1;
typedef long long ll;
ll bridge[maxn];
struct node{
	ll a;             
	ll b;          
}flood[maxn];        
int n,m,k;
ll C[maxn];   
int lowbit(int x) 
{
	return (-x)&x;
}
ll get(int i)
{
	ll s = 0;
	while(i <= n)
	{
		s+=C[i];
		i+=lowbit(i);
	}
	return s;
}
void update(int n,int num)
{
	while(n > 0)
	{
		C[n]+=num;
		n-=lowbit(i);
	}
}
int main()
{
	while(~scanf("%d%d%d",&n,&m,&k))
	{
		memset(C,0,sizeof C);
		for(int i = 1; i <= n ;i++)
			scanf("%d",&bridge[i]);
		sort(bridge + 1,bridge + n + 1);
		ll cur = 1;
		for(int i = 1; i <= m ;i++)
		{
			scanf("%d%d",flood[i].a,flood[i].b);
			int from = upper_bound(bridge,bridge+n,cur) - bridge;
			int to =  upper_bound(bridge,bridge+n,flood[i].a) - bridge; 
			update(from-1 ,-1);
			update(to-1,1);
			cur = flood[i].b;
		}
	}
	ll ans = 0;
	for(int i = 1; i<= m; i++){
		if(update(i)> k)
			ans++;		
	}
	cout<

你可能感兴趣的:(树状数组的区间更新,单点查询)