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 Albatross_LC @ 2023-09-03 17:22:32
下载下来的数据在Dev c++上提交系统直接崩溃
by Regenbogen_71 @ 2023-09-03 17:26:06
vector当平衡树是吧(0_o;)
by Albatross_LC @ 2023-09-03 17:30:46
@Regenbogen_71 对,STL模板库里有
by 羊羊君的幻想 @ 2023-09-03 17:39:35
by DELA @ 2023-09-03 17:41:08
@羊羊君的幻想 nlogn 过 1e6 不一定没希望吧,,但是 vector 是 log?
by 羊羊君的幻想 @ 2023-09-03 17:44:13
@DELA lowerbound带log
by DELA @ 2023-09-03 17:44:59
@羊羊君的幻想 vector 不是暴力吗。。。
by 羊羊君的幻想 @ 2023-09-03 17:45:39
@DELA 这道题很明显要卡log
by Albatross_LC @ 2023-09-03 17:46:25
@羊羊君的幻想 n * log(n) = n * 20 = 2e7
,不是一定会超
by DELA @ 2023-09-03 17:47:46
@羊羊君的幻想 不管 nlogn 过不过得了这个跟楼主的一点关系都没有 楼主的都不是 log 的是暴力