QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#720760 | #5417. Chat Program | Calculatelove# | TL | 2520ms | 151344kb | C++14 | 1.9kb | 2024-11-07 13:59:02 | 2024-11-07 13:59:03 |
Judging History
answer
#include <bits/stdc++.h>
typedef long long s64;
const int N = 200100;
const s64 sup = 1000000000000000000;
int n, k, m, c, d;
int a[N];
namespace SGT {
const int pond = 20001000;
int nClock, root[N];
struct node {
int lc, rc;
int cnt;
} t[pond];
void insert(int &p, int q, s64 l, s64 r, s64 x) {
p = ++ nClock, t[p] = t[q];
t[p].cnt ++;
if (l == r) return;
s64 mid = (l + r) >> 1;
if (x <= mid)
insert(t[p].lc, t[q].lc, l, mid, x);
else
insert(t[p].rc, t[q].rc, mid + 1, r, x);
}
int ask(int p, int q, s64 l, s64 r, s64 s, s64 e) {
if (s <= l && r <= e) return t[q].cnt - t[p].cnt;
s64 mid = (l + r) >> 1;
int cnt = 0;
if (s <= mid)
cnt += ask(t[p].lc, t[q].lc, l, mid, s, e);
if (mid < e)
cnt += ask(t[p].rc, t[q].rc, mid + 1, r, s, e);
return cnt;
}
}
int pre[N], suf[N];
bool check(s64 mid) {
pre[0] = 0;
for (int i = 1; i <= n; i ++) pre[i] = pre[i - 1] + (a[i] >= mid);
suf[n + 1] = 0;
for (int i = n; i >= 1; i --) suf[i] = suf[i + 1] + (a[i] >= mid);
for (int x = 1; x <= n - m + 1; x ++) {
int l = x, r = x + m - 1;
int cnt = pre[l - 1] + suf[r + 1] + SGT::ask(SGT::root[l - 1], SGT::root[r], 0, sup, mid + 1ll * x * d - c, sup);
if (cnt >= k) return 1;
}
return 0;
}
int main() {
scanf("%d%d%d%d%d", &n, &k, &m, &c, &d);
for (int i = 1; i <= n; i ++)
scanf("%d", &a[i]);
for (int i = 1; i <= n; i ++)
SGT::insert(SGT::root[i], SGT::root[i - 1], 0, sup, a[i] + 1ll * i * d);
s64 l = 0, r = 1000000000000000;
while (l < r) {
s64 mid = (l + r + 1) >> 1;
if (check(mid)) l = mid; else r = mid - 1;
}
printf("%lld\n", l);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7984kb
input:
6 4 3 1 2 1 1 4 5 1 4
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 1ms
memory: 6012kb
input:
7 3 2 4 0 1 9 1 9 8 1 0
output:
9
result:
ok 1 number(s): "9"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3784kb
input:
8 3 5 0 0 2 0 2 2 1 2 1 8
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 2520ms
memory: 151284kb
input:
200000 200000 100000 0 1000000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 1275ms
memory: 149896kb
input:
200000 1 100000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100000000...
output:
100001000000000
result:
ok 1 number(s): "100001000000000"
Test #6:
score: 0
Accepted
time: 80ms
memory: 151344kb
input:
200000 1 200000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 100000000...
output:
200001000000000
result:
ok 1 number(s): "200001000000000"
Test #7:
score: -100
Time Limit Exceeded
input:
200000 24420 17993 881138881 700368758 231187558 519018952 260661004 740633836 931672020 155904999 647179942 13217847 779799803 382810661 242588977 708308843 309853544 225488875 389115097 588643904 644409212 704920939 231829287 39891424 881158891 341251089 486868469 808002305 629160633 317239613 771...