| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1357176 | sally | Gift Boxes (EGOI25_giftboxes) | C++20 | 598 ms | 53280 KiB |
#include<iostream>
#include<vector>
#include<set>
#include<cstring>
using namespace std;
const int mx = 5e5+5;
vector<int> team(mx);
int T, N;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin>>T>>N;
for(int i=0; i<N; i++) {
cin>>team[i];
}
set<int> st1, st2;
vector<int> nxt1(N, -1), nxt2(N, -1);
int L= -1, R = -1;
for(int i=0; i<N; i++) {
int t = team[i];
if(L == -1) {
if(st1.count(t)) {
L = R = i;
st2.insert(t);
}else {
st1.insert(t);
}
}
else {
if(st1.count(t)) {
R = i;
st2.clear();
}
else if(st2.count(t)) {
for(int j = R+1; j<=nxt1[t]; j++) {
st2.erase(team[j]);
}
R = nxt1[t];
}
else {
st2.insert(t);
}
}
nxt1[t] = i;
}
set<int> st3, st4;
int l= -1, r = -1;
for(int i=N-1; i>=0; i--) {
int t = team[i];
if(r == -1) {
if(st3.count(t)) {
l = r = i;
st4.insert(t);
}else {
st3.insert(t);
}
}
else {
if(st3.count(t)) {
l = i;
st4.clear();
}
else if(st4.count(t)) {
for(int j = l-1; j>=nxt2[t]; j--) {
st4.erase(team[j]);
}
l = nxt2[t];
}
else {
st4.insert(t);
}
}
nxt2[t] = i;
}
if(R - L > r - l) cout<<l<<" "<<r;
else cout<<L<<" "<<R;
}| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
