HACK题解

P3369 【模板】普通平衡树

@[wlzhouzhuan](/user/112381)
by kradcigam @ 2021-04-07 15:35:29


@[Karry5307](/user/60990)
by kradcigam @ 2021-04-07 15:39:17


@[zhaohaikun](/user/180242) 实际数据保证了操作 3 时 x 一定存在 连 ```cpp #include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; int n; vector<int> bst; int main() { ios::sync_with_stdio(false);cin.tie();cout.tie(); int opt, x; // freopen("vector.in", "r", stdin); cin >> n; while (n--) { cin >> opt >> x; switch(opt) { case 1: bst.insert(lower_bound(bst.begin(), bst.end(), x), x); break; case 2: bst.erase(lower_bound(bst.begin(), bst.end(), x)); break; case 3: int t; cout << (t = lower_bound(bst.begin(), bst.end(), x)-bst.begin())+1 << endl; if (bst[t]!=x) return 1; break; case 4: cout << bst[x-1] << endl; break; case 5: cout << *(lower_bound(bst.begin(), bst.end(), x)-1) << endl; break; case 6: cout << *upper_bound(bst.begin(), bst.end(), x) << endl; break; } } // fclose(stdin); return 0; } ``` 都可以通过 (如果不想看代码的话,可以看成只要操作 3 序列不存在 x 时就错误结束程序的伪平衡树模板)
by lcyxds @ 2021-04-08 10:22:28


@[lcyxds](/user/124314) 题目没保证吧
by kradcigam @ 2021-04-08 16:59:19


@[zhaohaikun](/user/180242) 那就是这些题解没有考虑这种情况,反正这就是个板子hack也没啥意义
by lcyxds @ 2021-04-08 17:10:55


@[lcyxds](/user/124314) 啊,行
by kradcigam @ 2021-04-08 17:12:34


|