# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
978849 | rakhim_ova | Sequence (APIO23_sequence) | C++17 | 2089 ms | 70120 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;
using ll = long long;
ll INF=1e13;
int sequence(int n, std::vector<int> a) {
vector<vector<int>> ind(n+1);
for(int i=0; i<n; i++){
ind[a[i]].push_back(i);
}
vector<int> new_a(n);
int mx=1;
for(int i=1; i<=n; i++){
if(i==1){
for(int j=0; j<n; j++){
if(a[j]<i) new_a[j]=-1;
else if(a[j]>i) new_a[j]=1;
else new_a[j]=-1;
}
}
else{
for(int j=0; j<ind[i-1].size(); j++){
new_a[ind[i-1][j]]=-1;
}
for(int j=0; j<ind[i].size(); j++){
new_a[ind[i][j]]=-1;
}
}
map<int, pair<int, int>> mp;
int sm=0;
// cout << i << '\n';
// for(auto x: new_a){
// cout << x << ' ';
// }
// cout << '\n';
for(int j=0; j<n; j++){
sm+=new_a[j];
// cout << sm << ' ';
if(mp.find(sm)!=mp.end()){
mp[sm].second=j;
}
else{
mp[sm].first=j;
mp[sm].second=j;
}
}
// cout << '\n';
vector<int> pref(n);
int cnt=0;
for(int j=0; j<n; j++){
if(a[j]==i){
cnt++;
}
pref[j]=cnt;
}
for(auto x: mp){
// cout << x.first << ' ' << x.second.first << ' ' << x.second.second << '\n';
if(x.second.first==0){
mx=max(mx, pref[x.second.second]);
}
else{
mx=max(mx, pref[x.second.second]-pref[x.second.first-1]);
}
}
// for(auto x: pref){
// cout << x << ' ';
// }
// cout << '\n';
}
return mx;
}
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... |