이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |