ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#213986 | #2380. 中位数 | huangyuhe | 40 | 879ms | 1460kb | C++11 | 1.3kb | 2024-11-14 21:17:14 | 2024-11-14 23:07:41 |
answer
#include <bits/stdc++.h>
#define C__ const
#define int long long
using namespace std;
C__ int N_ = 2e5 + 10, inf = 0x3f3f3f3f3f3f3f3fLL;
int n, m, a[N_], b[N_];
signed main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
priority_queue<pair<int, int> > que1;
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > que2;
que1.push({-inf, 0}), que2.push({inf, 0});
for (int j = i; j <= n; j++) {
int x = a[j], y = j;
if ((j - i) & 1) {
if (x < que1.top().first) {
que1.push({x, y});
x = que1.top().first, y = que1.top().second;
que1.pop();
}
que2.push({x, y});
} else {
if (x > que2.top().first) {
que2.push({x, y});
x = que2.top().first, y = que2.top().second;
que2.pop();
}
que1.push({x, y});
}
++b[que1.top().second];
}
}
vector<int> idx(n);
iota(idx.begin(), idx.end(), 1);
sort(idx.begin(), idx.end(), [&](int i, int j) { return a[i] < a[j]; } );
for (int c = 0; c < (int) idx.size(); c++)
if (c > 0) b[idx[c]] += b[idx[c - 1]];
m = (b[idx[n - 1]] + 1) / 2;
int l = 0, r = n - 1;
while (l < r) {
int mid = l + (r - l) / 2;
if (b[idx[mid]] < m) l = mid + 1;
else r = mid;
}
cout << a[idx[l]] << "\n";
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 3ms
memory: 1268kb
input:
200 247837946 222748444 549404903 934970141 181690491 116150147 755881953 912914845 578004877 589768...
output:
411892743
result:
ok 1 number(s): "411892743"
Test #2:
score: 10
Accepted
time: 3ms
memory: 1268kb
input:
200 504553675 321343511 781936447 172776833 779139954 643752948 106 164 303976944 828799931 11502170...
output:
451369372
result:
ok 1 number(s): "451369372"
Test #3:
score: 10
Accepted
time: 3ms
memory: 1268kb
input:
200 738368650 91602659 340556191 835209882 409442204 656938221 258295858 90658347 126689369 56196859...
output:
420852999
result:
ok 1 number(s): "420852999"
Test #4:
score: 0
Time Limit Exceeded
input:
5000 300051244 685920750 122806687 315801142 33592358 339985437 262520930 380010194 687330910 550362...
output:
result:
Test #5:
score: 10
Accepted
time: 870ms
memory: 1460kb
input:
5000 108135249 950186870 146626753 682580494 744412491 4159 995071655 157947560 668940645 878891308 ...
output:
466892796
result:
ok 1 number(s): "466892796"
Test #6:
score: 0
Time Limit Exceeded
input:
5000 246610103 780664789 678774940 716124165 518453378 300121008 135383319 939869983 430946660 13412...
output:
result:
Test #7:
score: 0
Runtime Error
input:
300000 786856547 380253059 684225515 795392038 881780483 18437791 793783577 832330260 801624996 3466...
output:
result:
Test #8:
score: 0
Runtime Error
input:
300000 951000485 930070933 3566360 157114366 150196488 611226665 123590886 950624066 472150346 57976...
output:
result:
Test #9:
score: 0
Runtime Error
input:
300000 728509094 406128756 696166390 756254976 31403187 672131182 35544213 870708756 3659210 5227553...
output:
result:
Test #10:
score: 0
Runtime Error
input:
300000 804874490 52247250 546638789 400214210 383796618 47995083 814777769 507157584 466189162 28296...