bzoj 3236: [Ahoi2013]作业 (莫队+分块)

3236: [Ahoi2013]作业

Time Limit: 100 Sec   Memory Limit: 512 MB
Submit: 1547   Solved: 635
[ Submit][ Status][ Discuss]

Description

Input

Output

Sample Input

3 4
1 2 2
1 2 1 3
1 2 1 1
1 3 1 3
2 3 2 3

Sample Output

2 2
1 1
3 2
2 1

HINT


N=100000,M=1000000

Source

By wangyisong1996加强数据

[ Submit][ Status][ Discuss] 

题解:莫队+分块

对于权值也进行分块,这样修改就变成了O(1),查询就是O(sqrt(n))

#include
#include
#include
#include
#include
#define N 1000003
using namespace std;
int n,m,belong[N],a[N],cnt[N],num[N],v[N],mark[N],block;
struct data{
	int l,r,a,b,id;
	data(int L=0,int R=0,int A=0,int B=0,int ID=0) {
		l=L,r=R,a=A,b=B,id=ID;
	};
}q[N],ans[N];
int cmp(data a,data b)
{
	return belong[a.l]l) change(l++,-1);
		while (q[i].r>r) change(++r,1);
		while (q[i].r


你可能感兴趣的:(分块,莫队)