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 "sequence.h"
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = int;
const ll mod = 998244353;
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define faster ios::sync_with_stdio(false);cin.tie(nullptr)
int sequence(int N, std::vector<int> A) {
int ans=0;
vector<vector<int>> cum(N+1,vector<ll>(N+1,0));
rep(i,N) cum[i+1][A[i]]++;
rep(i,N) rep(j,N+1) cum[i+1][j]+=cum[i][j];
rep(l,N){
multiset<ll> s1,s2;
for(ll r=l;r<N;r++){
s1.insert(A[r]);
while(s1.size()>0&&s2.size()>0&&*s1.rbegin()>*s2.begin()){
s1.insert(*s2.begin());
s2.erase(s2.find(*s2.begin()));
}
while(s1.size()-s2.size()>=2){
s2.insert(*s1.rbegin());
s1.erase(s1.find(*s1.rbegin()));
}
ans=max(ans,cum[r+1][*s1.rbegin()]-cum[l][*s1.rbegin()]);
if(s1.size()==s2.size()) ans=max(ans,cum[r+1][*s2.begin()]-cum[l][*s2.begin()]);
}
}
return ans;
}
# | 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... |