H 题 test2
wrong answer 85th numbers differ - expected: '2', found: '5'
大家有什么头绪吗qaq
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int R = 1e6;
int T, n, m, k;
int a[N];
typedef pair<int, int> P;
set <P> st;
set <int> b;
char op[10];
int pre[N], nxt[N];
bool vis[N];
inline void solve(){
st.clear(), b.clear();
cin >> n;
for(int i = 1; i <= n; ++i) cin >> a[i], b.insert(a[i]);
a[n + 1] = 4e6 + 10; b.insert(a[n + 1]);
a[0] = 0; b.insert(0);
for(int i = 1; i <= n + 1; ++i)
if(a[i] > a[i - 1]) st.insert(P(a[i] - a[i - 1] - 1, a[i - 1]));
cin >> m;
for(int i = 1; i <= m; ++i){
int x; cin >> op >> x;
// cout << i << " " << x << endl;
if(op[0] == '+'){
auto id = b.lower_bound(x);
int v = (*id); id--; int u = (*id);
auto p = st.lower_bound(P(v - u - 1, u));
st.erase(p);
b.insert(x);
st.insert(P(x - u - 1, u)), st.insert(P(v - x - 1, x));
}else if(op[0] == '-'){
auto id = b.lower_bound(x);
// cout << "dd " << (*id) << endl;
id++; int v = (*id);
// cout << "v " << v << endl;
id--; id--; int u = (*id);
id++; b.erase(id);
// cout << "uu " << u << " " << v << endl;
auto p1 = st.lower_bound(P(v - x - 1, x));
st.erase(p1);
p1 = st.lower_bound(P(x - u - 1, u)); st.erase(p1);
st.insert(P(v - u - 1, u));
}else{
auto p = st.lower_bound(P(x, 0));
cout << (*p).second + 1 << '\n';
for(auto ss : b) cout << ss << " ";
cout << endl;
}
}
cout << endl;
return;
}
signed main(){
#ifndef ONLINE_JUDGE
freopen("test.in", "r", stdin);
freopen("test.out", "w", stdout);
#endif
ios :: sync_with_stdio(false);
cin >> T;
while(T--) solve();
return 0;
}