社区讨论
为什么本地样例没过交上去过了
P1903【模板】带修莫队 / [国家集训队] 数颜色 / 维护队列参与者 1已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mjy44xuz
- 此快照首次捕获于
- 2026/01/03 17:41 2 个月前
- 此快照最后确认于
- 2026/01/07 13:00 上个月
CPP
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, V = 1e6 + 5;
int cnt1, cnt2, t[V], n, m, a[N], b, ans, pos[N];
struct Node {
int x, y, z, id, ans;
} q[N];
struct node {
int x, y;
} c[N];
__inline__ bool cmp(Node x1, Node x2) {
if(pos[x1.x] != pos[x2.x]) {
return x1.x < x2.x;
}
if(pos[x1.y] != pos[x2.y]) {
return x1.y < x2.y;
}
return x1.z < x2.z;
}
__inline__ bool cmp1(Node x1, Node x2) {
return x1.id < x2.id;
}
__inline__ void add(int x) {
if(t[x] == 0) {
ans ++;
}
t[x] ++;
}
__inline__ void del(int x) {
if(t[x] == 1) {
ans --;
}
t[x] --;
}
__inline__ void push(int p, int x) {
if(q[p].x <= c[x].x && q[p].y >= c[x].x) {
del(a[c[x].x]);
add(c[x].y);
}
swap(a[c[x].x], c[x].y);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> m;
b = pow(n, 0.6666);
for(int i = 1; i <= n; i ++) {
cin >> a[i];
pos[i] = (i - 1) / b + 1;
}
for(int i = 1; i <= m; i ++) {
char ch;
cin >> ch;
if(ch == 'Q') {
cin >> q[++ cnt1].x >> q[cnt1].y;
q[cnt1].z = cnt2, q[cnt1].id = cnt1;
}
else {
cin >> c[++ cnt2].x >> c[cnt2].y;
}
}
sort(q + 1, q + cnt1 + 1, cmp);
int x = 1, y = 0, z = 0;
for(int i = 1; i <= cnt1; i ++) {
while(x > q[i].x) {
add(a[-- x]);
}
while(x < q[i].x) {
del(a[x ++]);
}
while(y < q[i].y) {
add(a[++ y]);
}
while(y > q[i].y) {
del(a[y --]);
}
while(z > q[i].z) {
push(i, z --);
}
while(z < q[i].z) {
push(i, ++ z);
}
q[i].ans = ans;
}
sort(q + 1, q + cnt1 + 1, cmp1);
for(int i = 1; i <= cnt1; i ++) {
cout << q[i].ans << '\n';
}
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...