https://codeforces.com/contest/1692/problem/H


이 문제에 대해서 



#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define TEST int tt; cin >> tt; while(tt--) solve();


ll MOD = 1000000007;
ll MOD2 = 998244353;
int INF = 0x3f3f3f3f;

int arr[200005];
vector<int> tmp;
vector<int> v[200005];
map<int,int> mp;
void solve(){
int i,j,k;
int n; cin >> n;

tmp.clear();
mp.clear();
for(i=0; i<=n; i++){
v[i].clear();
}

int start,end,ans,a,l,r;


for(i=0; i<n; i++){
cin >> arr[i];
tmp.push_back(arr[i]);
}
sort(tmp.begin(), tmp.end());
tmp.erase(unique(tmp.begin(),tmp.end()),tmp.end());
int len = 0;
for(i=0; i<n; i++){
int idx = lower_bound(tmp.begin(),tmp.end(), arr[i]) - tmp.begin();
v[idx].push_back(i);
mp.insert({idx, arr[i]});
len = max(len, idx+1);

}

ans = 1;
a = arr[0];
l = r = 1;
for(i=0; i<len; i++){
int now = 1;
start = 0;
end = 0;
if(v[i].size() == 1) continue;
while(1){
if(end + 1 == v[i].size()) break;

if(v[i][end]+1 == v[i][end+1]){
end++;
now++;
}else{
int other = v[i][end+1] - v[i][end] - 1;
int count = 1;
while(1){
if(end+count+1 < v[i].size() && v[i][end+count]+1 == v[i][end+count+1]){
count++;
}else break;
}

if(now > other && other < count){
now += count- other;
end += count;
}else{
now = count;
start = end+1;
end += count;
}
}

if(ans < now){
ans = now;
a = mp[i];
l = v[i][start];
r = v[i][end];
l++,r++;
}
}
}

cout << a << ' ' << l << ' ' << r << '\n';
cout << ans << '\n';
}
int main(){
FASTIO
TEST
}


먼저 이 문제에 대해서 다음과 같이 풀었습니다.


접근 방법은 주사위 숫자 범위가 너무 넓어 좌표압축을 먼저 진행하고 

각 번호에 해당하는 index 를 vector에 삽입합니다.

각 vector 번호에 따른 투 포인터 방식으로 정답을 찾는 방식이고


투 포인터 알고리즘은

만약 연속되어있다면 현재 상태를 업데이트를 진행 


만약 아닌 경우 

중간에 다른 숫자의 개수를 카운트

other = v[i][end+1] - v[i]+ - 1;


앞에 이어져있는 숫자를 카운트해서
now > other && other < count 라면 둘을 이어줌

now > other 가 아니라면 count로 새로 시작하는게 더 낫고
other < count 가 아니라면 굳이 이을 필요가 없으므로 현재 상태를 초기화합니다. 


왜 틀렸는지 잘 모르겠어요