제출 #759688

#제출 시각아이디문제언어결과실행 시간메모리
759688IvanJ서열 (APIO23_sequence)C++17
7 / 100
88 ms31528 KiB
#include "sequence.h" #include<bits/stdc++.h> #define pb push_back #define x first #define y second #define all(a) (a).begin(), (a).end() using namespace std; typedef long long ll; typedef pair<int, int> ii; const int maxn = 5e5 + 5; vector<int> pos[maxn]; int sequence(int N, vector<int> A) { for(int i = 0;i < N;i++) pos[A[i]].pb(i); int X = 0; for(int i = 1;i < N;i++) if(A[i] > A[X]) X = i; int l = 0, ans = 0; for(int i = 1;i <= N;i++) { if(pos[i].size() == 0) continue; int lo = pos[i][0], hi = pos[i].back(); if(hi < X || lo > X) ans = max(ans, (int)pos[i].size()); else { int e = (int)pos[i].size(); int g = N - e - l; if(l < g - e) { int x = 0, y = 0; for(int j : pos[i]) if(j < X) x++; else y++; ans = max(ans, max(x, y)); } else ans = max(ans, e); } l += (int)pos[i].size(); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...