树形数组暴力

对不起,常数小就是可以为所欲为的。

题目

// luogu-judger-enable-o2
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
struct node
{
	int tree[100100];
	int num;
	int lowbit(int x)
	{
		return x&(-x);
	}
	void updata(int x,int i)
	{
		while(i<=num)
		{
			tree[i]+=x;
			i+=lowbit(i);
		}
	}
	int sum(int i)
	{
		int ans=0;
		while(i>0)
		{
			ans+=tree[i];
			i-=lowbit(i);
		}
		return ans;
	}
	int check(int l,int r)
	{
		return sum(r)-sum(l-1);
	}
};
node bit;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	bit.num=n;
	int a,b;
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a,&b);
		bit.updata(b,a);
	}
	int ans=0;
	for(int i=1;i+m-1<=n;i++)
		ans=max(ans,bit.check(i,i+m-1));
	printf("%d",ans);
}
原文地址:https://www.cnblogs.com/Lance1ot/p/8535411.html