Albatross_LC @ 2023-09-03 17:21:13
平衡树做法T#9
#include "cstdio"
#include "vector"
#include "algorithm"
#include "string"
using namespace std;
int n, k, a[1000010];
int mx[1000010];
vector<int> e;
int read() {
int ret = 0, sgn = 0, ch = getchar();
while (!isdigit(ch)) sgn |= ch == '-', ch = getchar();
while (isdigit(ch)) ret = ret * 10 + ch - '0', ch = getchar();
return sgn ? -ret : ret;
}
main() {
n = read(), k = read();
for (int i = 1; i <= n; i ++ ) {
a[i] = read();
e.insert(upper_bound(e.begin(), e.end(), a[i]), a[i]);
if (i >= k) {
if (i > k) e.erase(lower_bound(e.begin(), e.end(), a[i - k]));
mx[i] = e[k - 1];
printf("%d ", e[0]);
}
}
printf("\n");
for (int i = k; i <= n; i ++ )
printf("%d ", mx[i]);
}
想用平衡树试试,但T了,有没有大佬知道怎么回事,复杂度
by DELA @ 2023-09-03 17:48:28
@羊羊君的幻想 而且 nlogn 1e6 的题也不少啊,常数小凭啥不能过?
by 羊羊君的幻想 @ 2023-09-03 17:48:33
@Albatross_LC STL常数大
by Albatross_LC @ 2023-09-03 17:48:46
@DELA 平衡树是
by 羊羊君的幻想 @ 2023-09-03 17:49:10
@DELA lowerbound又不是严格log,STL常数都大
by DELA @ 2023-09-03 17:49:13
@Albatross_LC vector 是个几把平衡树
by Albatross_LC @ 2023-09-03 17:50:13
luogu不让手动常数优化我也没办法啊
by DELA @ 2023-09-03 17:50:49
@羊羊君的幻想 你说 STL 常数都大之前能不能先去核实一下。。。这个常数大能大在哪里啊?不都是一个很简单的二分吗,
啥叫不是严格 log,常数大小跟复杂度有啥关系?
by 羊羊君的幻想 @ 2023-09-03 17:53:05
@DELA 开小号口胡就是爽是吧,STL常数大是常识这都不知道?你看看谁冲最优解用STL
by Albatross_LC @ 2023-09-03 17:55:25
@羊羊君的幻想 注:我没想冲最优解,我只是想用平衡树A了这道题
by DELA @ 2023-09-03 17:55:35
@羊羊君的幻想 说不过就开始人身攻击了是吧/qd 你要不先写个程序测一下 stl 的速度再来 bb,,