题目链接:
ax+ax-1+...+ay = cntx+cnty 这样把一段序列变成两段相加跑莫队。
1 #include2 #include 3 #include 4 #include 5 using namespace std; 6 const int maxn = 200010; 7 int curR = 0, curL = 1, answer,a[maxn], ans[maxn], cnt[maxn], n, m, k, bl; 8 struct query{ 9 int l,r,p;10 }q[maxn];11 12 bool cmp(const query &a, const query &b)13 {14 return (a.l/bl) == (b.l/bl) ? a.r q[i].l) curL--,add(curL-1);52 while(curR < q[i].r) add(++curR);53 while(curR > q[i].r) remove(curR--);54 ans[q[i].p] = answer;55 }56 for(int i = 1; i <= m; i++)57 printf("%d\n",ans[i]);58 return 0;59 }