求区间每种颜色出现次数平方和
写裸题练手
#include#include #include #include #include using namespace std;typedef long long ll;const int N=5e4+5;inline int read(){ char c=getchar();int x=0,f=1; while(c<'0'||c>'9'){ if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();} return x*f;}int n,a[N],Q,k, block,m,pos[N];struct meow{ int l,r,id; bool operator <(const meow &x) const { return pos[l] q[i].r) del(r), r--; while(l q[i].l) l--, add(l); ans[q[i].id]=now; }}int main(){ freopen("in","r",stdin); n=read();Q=read();k=read(); block=sqrt(n); m=(n-1)/block+1; for(int i=1;i<=n;i++) a[i]=read(), pos[i]=(i-1)/block+1; for(int i=1;i<=Q;i++) q[i].l=read(), q[i].r=read(), q[i].id=i; sort(q+1, q+1+Q); solve(); for(int i=1;i<=Q;i++) printf("%lld\n",ans[i]);}