QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#821 | #569047 | #9314. The Median of the Median of the Median | tkt0506 | tkt0506 | Failed. | 2024-09-16 20:23:50 | 2024-09-16 20:23:52 |
Details
Extra Test:
Accepted
time: 0ms
memory: 3548kb
input:
4 1 1 1000 1000
output:
1
result:
ok 1 number(s): "1"
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#569047 | #9314. The Median of the Median of the Median | tkt0506 | AC ✓ | 526ms | 34892kb | C++14 | 1.2kb | 2024-09-16 20:09:38 | 2024-09-18 18:11:26 |
answer
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >> n;
vector<int>a(n+1), sa(n+1);
for(int i=1; i<=n; i++)cin >> a[i];
int b[n+1][n+1], sum[n+1][n+1];
memset(b, 0, sizeof b);
int l=0, r=1e9;
while(l<=r){
int m = (l+r)/2;
// compute b
sa[0] = 0;
for(int i=1; i<=n; i++){
sa[i] = sa[i-1];
if(a[i] <= m)sa[i]++;
else sa[i]--;
}
for(int i=1; i<=n; i++){
for(int j=i; j<=n; j++){
if(sa[j]-sa[i-1] >= 0)b[i][j] = 1;
else b[i][j] = -1;
}
}
// prefix sum
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + b[i][j];
}
}
// compute c
int tot = 0;
for(int i=1; i<=n; i++){
for(int j=i; j<=n; j++){
int v = sum[j][j] - sum[i-1][j] - sum[j][i-1] + sum[i-1][i-1];
if(v>=0)tot++;
else tot--;
}
}
if(tot >= 0)r = m-1;
else l = m+1;
}
cout << l;
}