P1494 [国家集训队]小Z的袜子(莫队)

就只是莫队而已,非常的无脑,转移也很好想

区间的贡献就是相同颜色的个数乘以个数减一

注意特判一下0的情况

代码:

#include 
#define int long long
#define sc(a) scanf("%lld",&a)
#define scc(a,b) scanf("%lld %lld",&a,&b)
#define sccc(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define scs(a) scanf("%s",a) 
#define schar(a) scanf("%c",&a)
#define pr(a) printf("%lld",a)
#define fo(i,a,b) for(int i=a;ib;--i)
#define rre(i,a,b) for(int i=a;i>=b;--i)
#define prn() printf("\n")
#define prs() printf(" ")
#define mkp make_pair
#define pii pair
#define pub(a) push_back(a)
#define pob() pop_back()
#define puf(a) push_front(a)
#define pof() pop_front()
#define fst first
#define snd second
#define frt front()
#define bak back()
#define mem0(a) memset(a,0,sizeof(a))
#define memmx(a) memset(a,0x3f3f,sizeof(a))
#define memmn(a) memset(a,-0x3f3f,sizeof(a))
#define debug
#define db double
#define yyes cout<<"YES"< vei;
typedef vector vep;
typedef map mpii;
typedef map mpci;
typedef map mpsi;
typedef deque deqi;
typedef deque deqc;
typedef priority_queue mxpq;
typedef priority_queue,greater > mnpq;
typedef priority_queue mxpqii;
typedef priority_queue,greater > mnpqii;
const int maxn=500005;
const int inf=0x3f3f3f3f3f3f3f3f;
const int MOD=100000007;
const db eps=1e-10;
const db pi=3.1415926535;
int qpow(int a,int b){int tmp=a%MOD,ans=1;while(b){if(b&1){ans*=tmp,ans%=MOD;}tmp*=tmp,tmp%=MOD,b>>=1;}return ans;}
int lowbit(int x){return x&-x;}
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return ab||fabs(a-b)<=eps)return true;return false;}
bool eql(db a,db b){if(fabs(a-b)57){if(ch=='-')w=-1;ch=getchar();}
    while(ch>=48&&ch<=57){s=(s<<1)+(s<<3)+ch-48;ch=getchar();}
    return s*w;
}
inline void write(int x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)write(x/10);
    putchar(x%10+48);
}
int gcd(int a, int b){
    if(a==0) return b;
    if(b==0) return a;
    if(!(a&1)&&!(b&1)) return gcd(a>>1,b>>1)<<1;
    else if(!(b&1)) return gcd(a,b>>1);
    else if(!(a&1)) return gcd(a>>1,b);
    else return gcd(abs(a-b),min(a,b));
}
int lcm(int x,int y){return x*y/gcd(x,y);}

int n,m;
struct node{
    int l,r,id,ans;
}q[maxn];
int a[maxn],cnt[maxn],ans[maxn],len[maxn];
int sz;

bool cmp(node a,node b){
    if(a.id==b.id){
        if(a.id%2==1) return a.rb.r;
    }
    else return a.idq[i].l) add(--L);
        while(R>q[i].r) del(R--);
        while(R

你可能感兴趣的:(P1494 [国家集训队]小Z的袜子(莫队))