版本比较
莫队学习笔记
正文
增加 6 行删除 6 行
72 行未改动73747576777778798081828384858687878889909177 行未改动16917017117217317317417517617717817918018118218218318418518633 行未改动22022122222322422422522622722822923023123123223323423524 行未改动72 行未改动 return r;}//略略卡常struct Qry { int l, r, id; bool operator < (const Qry& p) const { bool operator < (const Qry& p) const { if (l / blen != p.l / blen) return l < p.l;//不同块 return (l / blen) % 2 ? r > p.r : r < p.r;//同块 }//排序策略} q[N];void add_cur(int x) { cur_ans += cnt[a[x]]; cnt[a[x]]++;}//挪进了这个元素void del_cur(int x) { cnt[a[x]]--; cnt[a[x]]--; cur_ans -= cnt[a[x]];}//挪出了这个元素int main() { ios::sync_with_stdio(false);77 行未改动const int MAXN = 133335;const int MAXM = 133335;const int MAXC = 1000005;int n, m;int a[MAXN]; int a[MAXN];int blockSize;struct Query { int l, r, t, id; //加了个t,时间 int blockL, blockR;} q[MAXM];struct Modify { int pos, val, pre;} mod[MAXM];int qcnt = 0, mcnt = 0; int qcnt = 0, mcnt = 0;int ans[MAXM];int cnt[MAXC];int colorCount = 0;bool cmp(const Query& a, const Query& b) {33 行未改动 for (int i = 1; i <= m; i++) { char op; int x, y; cin >> op >> x >> y;
if (op == 'Q') { q[++qcnt] = {x, y, mcnt, qcnt, 0, 0}; q[qcnt].blockL = (x - 1) / blockSize; q[qcnt].blockR = (y - 1) / blockSize; } else { mod[++mcnt] = {x, y, a[x]}; a[x] = y; a[x] = y; } } for (int i = mcnt; i >= 1; i--) { a[mod[i].pos] = mod[i].pre;24 行未改动