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>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
template<class T> using Tree = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#define sz(a) (int)a.size()
#define fi first
#define se second
#define pb push_back
vector<pair<int,int>> v[500000];
Tree<pair<int,int>> S;
map<int,int> tot;
int n;
int sequence(int N, vector<int> a) {
n = N; int ans = 1;
for(int i = 0; i < n; i++){
int j = i;
while(i<n-1 and a[i]==a[i+1]) i++;
v[a[i]].pb({j,i-j+1});
ans = max(ans, i-j+1);
}
for(int i = 1; i <= n; i++){
if(sz(v[i])<2)continue;
int y = v[i][0].se+v[i][1].se;
int z = v[i][1].fi-(v[i][0].fi+v[i][0].se);
int x = v[i][0].fi + n-1-(v[i][1].fi+v[i][1].se-1);
if(x>=z-y) ans = max(ans, y);
}
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... |