# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
951488 | SmuggingSpun | Sequence (APIO23_sequence) | C++17 | 2097 ms | 9556 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int sequence(int n, vector<int>a){
vector<int>bit(n + 1);
function<void(int)>update = [&] (int p){
for(; p <= n; p += p & -p){
bit[p]++;
}
};
function<int(int)>get = [&] (int p){
int ans = 0;
for(; p > 0; p -= p & -p){
ans += bit[p];
}
return ans;
};
function<void(int&, int)>maximize = [&] (int& a, int b){
if(a < b){
a = b;
}
};
int ans = 0;
for(int i = 0; i < n; i++){
fill(bit.begin(), bit.end(), 0);
for(int j = i; j < n; j++){
update(a[j]);
int low = 1, high = n, x = j - i + 1, median;
while(low <= high){
int mid = (low + high) >> 1;
if(get(mid) >= (x >> 1) + (x & 1)){
high = (median = mid) - 1;
}
else{
low = mid + 1;
}
}
maximize(ans, get(median) - get(median - 1));
if((~x & 1) && get(median) == (x >> 1)){
low = median + 1;
high = n;
while(low <= high){
int mid = (low + high) >> 1;
if(get(mid) > (x >> 1)){
high = (median = mid) - 1;
}
else{
low = mid + 1;
}
}
maximize(ans, get(median) - get(median - 1));
}
}
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |