ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#164 | #8. 【模板】普通平衡树 | NagoriYuuuki | 100 | 236ms | 4704kb | C++23 | 1.0kb | 2025-04-17 14:49:13 | 2025-04-17 14:49:14 |
answer
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
using i64 = long long;
#define endl '\n'
#define xx first
#define yy second
signed main(void)
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> Tree;
int q;
cin >> q;
int id = 0;
while (q--)
{
int opt, x;
cin >> opt >> x;
if (opt == 1)
Tree.insert({x, ++id});
else if (opt == 2)
Tree.erase(Tree.lower_bound({x, 0}));
else if (opt == 3)
cout << Tree.order_of_key({x, 0}) + 1 << endl;
else if (opt == 4)
cout << (*Tree.find_by_order(x - 1)).xx << endl;
else if (opt == 5)
cout << (*--Tree.lower_bound({x, 0})).xx << endl;
else if (opt == 6)
cout << (*Tree.upper_bound({x, numeric_limits<int>::max()})).xx << endl;
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 11
Accepted
time: 3ms
memory: 3416kb
input:
20 1 964673 5 968705 4 1 3 964673 5 965257 1 915269 1 53283 3 964673 3 53283 3 53283 1 162641 5 9739...
output:
964673 964673 1 964673 3 1 1 964673 964673
result:
ok 9 numbers
Test #2:
score: 11
Accepted
time: 3ms
memory: 3508kb
input:
50 1 577793 1 408221 1 880861 2 408221 1 460353 1 223489 6 577713 4 2 5 889905 2 880861 1 100033 1 7...
output:
577793 460353 880861 577793 577793 100033 22575 22575 1 100033 643621 632329 643621 4 6 13 737721
result:
ok 17 numbers
Test #3:
score: 11
Accepted
time: 3ms
memory: 3512kb
input:
100 1 914241 1 639471 5 917713 6 912745 1 234811 1 297728 3 297728 1 6927 5 645391 1 664569 2 914241...
output:
914241 914241 2 639471 842266 6927 868271 297728 568845 639471 11 286545 234811 9 639471 531105 5311...
result:
ok 39 numbers
Test #4:
score: 11
Accepted
time: 4ms
memory: 3408kb
input:
1000 1 543050 1 599175 6 538214 1 208361 1 415495 1 376755 5 599771 6 415415 1 460416 3 599175 1 413...
output:
543050 599175 415495 6 599175 3 460416 430219 543050 8 838037 413857 543050 413857 14 17 60423 46041...
result:
ok 415 numbers
Test #5:
score: 11
Accepted
time: 8ms
memory: 3572kb
input:
10000 1 27217 5 30155 4 1 1 454393 6 453417 1 311109 1 172817 1 303817 1 446169 1 674881 4 1 6 44439...
output:
27217 27217 454393 27217 446169 303817 454393 674881 454393 454393 839081 839081 9 180795 674881 898...
result:
ok 3928 numbers
Test #6:
score: 11
Accepted
time: 39ms
memory: 4020kb
input:
50000 1 5227 6 -1792 6 445 1 175483 2 5227 1 562399 2 175483 1 956113 4 1 1 487125 1 851001 1 233057...
output:
5227 5227 562399 3 233057 3 40129 487125 3 40129 508946 7 478150 3 20 275201 487125 319065 487125 56...
result:
ok 19932 numbers
Test #7:
score: 11
Accepted
time: 52ms
memory: 4632kb
input:
100000 1 288297 1 535013 3 288297 1 457318 2 457318 3 535013 1 103045 1 964881 1 514921 1 640601 1 5...
output:
1 2 2 288297 103045 5 7 103045 524478 13 3 3 553201 4 349197 612362 199958 349197 535013 23 847953 5...
result:
ok 39610 numbers
Test #8:
score: 11
Accepted
time: 67ms
memory: 4704kb
input:
100000 1 634561 6 630913 1 254516 6 630481 1 966881 1 18529 1 873593 3 254516 2 966881 3 254516 4 1 ...
output:
634561 634561 2 2 18529 18529 634561 634561 1 74233 5 695277 74233 14 9 800499 74233 800499 6 14 873...
result:
ok 39797 numbers
Test #9:
score: 11
Accepted
time: 57ms
memory: 4592kb
input:
100000 1 104152 1 405622 4 2 1 564237 1 290523 1 441856 1 910218 1 97083 1 104393 1 485841 3 910218 ...
output:
405622 9 290523 97083 7 104393 438977 12 485841 1 86501 86501 735257 405622 290523 874917 438977 851...
result:
ok 39516 numbers