题目传送门:https://codeforces.com/problemset/problem/86/D
题目大意: 给定一个长度为\(n\)的序列,有\(m\)组询问,每次询问\([l,r]\)中,\(\sum\limits_{s}K_s^2\times s\)的值,其中,\(K_s\)表示\(s\)在子串\([l,r]\)中的出现次数
由于这题没有修改,仅有询问,故我们可以考虑莫队算法
/*program from Wolfycz*/ #include #include #include #include #include #include #include #define Fi first #define Se second #define ll_inf 1e18 #define MK make_pair #define sqr(x) ((x)*(x)) #define pii pair #define int_inf 0x7f7f7f7f using namespace std; typedef long long ll; typedef unsigned int ui; typedef unsigned long long ull; inline char gc(){ static char buf[1000000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++; } templateinline T frd(T x){ int f=1; char ch=gc(); for (;ch<'0'||ch>'9';ch=gc()) if (ch=='-') f=-1; for (;ch>='0'&&ch<='9';ch=gc()) x=(x<<1)+(x<<3)+ch-'0'; return x*f; } templateinline T read(T x){ int f=1; char ch=getchar(); for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1; for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0'; return x*f; } inline void print(int x){ if (x<0) putchar('-'),x=-x; if (x>9) print(x/10); putchar(x%10+'0'); } const int N=2e5,M=1e6; int A[N+10],pos[N+10]; struct node{ int l,r,ID; void Read(int i){l=read(0),r=read(0),ID=i;} node(int _l=0,int _r=0,int _ID=0){l=_l,r=_r,ID=_ID;} bool operator <(const node &tis)const{return pos[l]!=pos[tis.l]?lB[i].r) Add(A[r--],-1); while (lB[i].l) Add(A[--l], 1); Ans[B[i].ID]=All; // printf("\n"); } for (int i=1;i<=m;i++) printf("%lld\n",Ans[i]); return 0; }