原题链接
带修莫队模板.
增加一维时间t.
需要注意:
1.排序第一关键字为l所在块编号,第二关键字为r所在块编号,第三关键字为t.
2.块的大小为cbrt(n*t), 即block = cbrt((double)n * max(1, nc));
3.对t处理时可交换原序列中颜色编号与该操作交换后的颜色编号.
时间复杂度O(n^5/3).证明略.
代码如下:
#include <cstdio>
#include <cctype>
#include <cmath>
#include <algorithm>
using namespace std;
inline int read(){
int res = 0, pdf = 0; char ch = getchar();
while(!isdigit(ch)) pdf = ch == '-', ch = getchar();
while(isdigit(ch)) res = (res<<3) + (res<<1) + (ch^48), ch = getchar();
return pdf ? -res : res;
}
inline void Print(int x) {
if (x < 0) x = -x, putchar('-');
if (x < 10) putchar(x + '0');
else {
Print(x / 10);
putchar(x % 10 + '0');
}
}
const int N = 2e6 + 10;
int n, m, ans, nq, nc, block, pos[N], col[N], ton[N];
struct Query {
int id, l, r, t, ans;
}q[N];
struct Change {
int p, k