求调!样例过了,但提交12TLE,5个RE,竟然一个没过,郁闷
#include <bits/stdc++.h>
using namespace std;
#define it set<node> :: iterator
const int maxn = 5e5 + 5;
struct node{
int l, r;
mutable int val;
node(int L, int R = 0, int V = 0) :
l(L), r(R), val(V) {}
};
bool operator<(const node &a, const node &b) {
return a.l < b.l;
}
set<node> s;
int cnt[maxn];
it split(int pos, int a) {
it u = s.lower_bound(node(pos));
int v = u->val;
it x = u;
--x;
int l = u->l, r = u->r;
// 往左边暴力扩展
while (1) {
if (x->val == v) {
l = x->l;
} else {
break;
}
cnt[v] -= x->r - x->l + 1;
it t = x;
if (t == s.begin()) {
s.erase(t);
break;
}
--x;
s.erase(t);
}
x = u;
++x;
while (x != s.end()) {
if (x->val == v) {
r = x->r;
} else {
break;
}
cnt[v] -= x->r - x->l + 1;
it t = x;
++x;
s.erase(t);
}
cnt[v] -= u->r - u->l + 1;
s.erase(u);
cnt[a] += r - l + 1;
s.insert(node{l, r, a});
}
void best() {
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; ++i) {
s.insert(node{i, i, i});
++cnt[i];
}
while(q--) {
int opt;
cin >> opt;
if (opt == 1) {
int x, c;
cin >> x >> c;
split(x, c);
} else {
int x;
cin >> x;
cout << cnt[x] << '\n';
}
}
}
int main() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
best();
return 0;
}