莫队基本知识

如果我们知道区间[L,R],就能在O(1)求出[L−1,R],[L+1,R],[L,R−1],[L,R+1]的话,那就可以用莫队算法了

就是对在区间之间的查询时常常使用莫队

莫队通常使用的模板:

#include
#include
#include
#include 
using namespace std;
struct question{
    int l;
    int r;
    int id;
}qst[1110000];           
int comp(const question & a,const question & b)
{
    if(a.l==b.l)    
		return a.rqst[i].r){
            mns(str[r]);
			r--;
		}

        while(lqst[i].l){
            l--;
			pls(str[l]);
		}
        
        ans[qst[i].id]=sum;
    }
    
    for(int i=1;i<=m;i++)
        cout<

 

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