社区讨论
为什么本地AC提交WA?
P3939数颜色参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mi6maf5d
- 此快照首次捕获于
- 2025/11/20 07:12 4 个月前
- 此快照最后确认于
- 2025/11/20 07:12 4 个月前
本地测是AC的提交说输出的都是0
CPP#include<cstdio>
#include<cstdlib>
#include<algorithm>
using std :: pair ;
#define For(i, _l, _r) for (int i = (_l), i##r = (_r) ; i <= (i##r) ; ++i)
#define Lop(i, _l, _r) for (int i = (_l), i##r = (_r) ; i >= (i##r) ; --i)
#define Rep(i, _l, _r) for (int i = (_l) ; i ; i = (_r))
template <typename tp> inline tp max (tp x, tp y) { return x > y? x: y ; }
template <typename tp> inline tp min (tp x, tp y) { return x < y? x: y ; }
template <typename tp>
inline bool chkmax (tp& x, tp y) { return (x >= y)? false: (x = y, true) ; }
template <typename tp>
inline bool chkmin (tp& x, tp y) { return (x <= y)? false: (x = y, true) ; }
static const int len = 1 << 20 | 1 ;
char buffer[len], *Ser, *Ter ;
inline char Getchar() {
if (Ser == Ter) Ter = (Ser = buffer) + fread (buffer, 1, len, stdin) ;
return (Ser == Ter)? (char)EOF: (*Ser++) ;
}
#define Getchar() getchar()
template <typename tp>
inline tp scanf (tp& in) {
in = 0 ; char ch = Getchar() ; tp f = 1 ;
for (; ch > '9' || ch < '0' ; ch = Getchar()) if (ch == '-') f = -1 ;
for (; ch >='0' && ch <='9' ; ch = Getchar()) in = in * 10 + ch - '0' ;
return in *= f ;
}
static const int max1 = 1e6 + 11 ;
int n ;
int m ;
int cnt ;
int ai[max1] ;
int top ;
int stack[max1] ;
int sz[max1] ;
int fix[max1] ;
int val[max1] ;
int ch[max1][2] ;
const pair <int, int> emp ;
class treap {
private : int root ;
public :
inline void update (int x) { sz[x] = sz[ch[x][0]] + sz[ch[x][1]] + 1 ; }
int merge (int x, int y) {
if (!x || !y) return x ^ y ;
if (fix[x] < fix[y]) {
ch[x][1] = merge (ch[x][1], y) ;
return update (x), x ;
} else {
ch[y][0] = merge (x, ch[y][0]) ;
return update (y), y ;
}
}
pair <int, int> split (int x, int y) {
if (!x) return emp ;
pair <int, int> res ;
if (y <= sz[ch[x][0]]) {
res = split (ch[x][0], y) ;
ch[x][0] = res.second, res.second = x ;
} else {
res = split (ch[x][1], y - sz[ch[x][0]] - 1) ;
ch[x][1] = res.first, res.first = x ;
}
return update (x), res ;
}
inline int newnode (int key) {
if (!top) throw ;
int x = stack[top--] ;
val[x] = key ; sz[x] = 1 ;
ch[x][0] = ch[x][1] = 0 ; fix[x] = rand() ;
}
inline int find (int x) {
int p = root, res = 0 ;
while (p)
if (val[p] >= x) p = ch[p][0] ;
else res += sz[ch[p][0]] + 1, p = ch[p][1] ;
return res ;
}
inline void insert (int x) {
if (!root) return root = newnode (x), void() ;
pair <int, int> p = split (root, find (x)) ;
root = merge (merge (p.first, newnode (x)), p.second) ;
}
inline void erase (int x) {
pair <int, int> p1 = split (root, find (x)) ;
pair <int, int> p2 = split (p1.second, 1) ;
root = merge (p1.first, p2.second) ;
stack[++top] = p2.first ;
}
} T[max1] ;
inline void swap (int& x, int& y) { x ^= y ^= x ^= y ; }
int main() {
scanf(n) ; scanf(m) ;
For (i, 1, n) stack[++top] = i ;
For (i, 1, n) scanf(ai[i]), T[ai[i]].insert (i) ;
while (m--) {
int op, l, r, x ;
scanf(op) ;
if (op == 1) {
scanf(l), scanf(r), scanf(x) ;
int t1 = T[x].find (l), t2 = T[x].find (r + 1) ;
printf ("%d\n", t2 - t1) ;
} else {
scanf(x) ;
T[ai[x]].erase (x), T[ai[x + 1]].erase (x + 1) ;
T[ai[x]].insert (x + 1), T[ai[x + 1]].insert (x) ;
swap (ai[x], ai[x + 1]) ;
}
}
return 0 ;
}
回复
共 0 条回复,欢迎继续交流。
正在加载回复...