제출 #982025

#제출 시각아이디문제언어결과실행 시간메모리
982025vjudge1서열 (APIO23_sequence)C++17
28 / 100
2062 ms32128 KiB
#include "sequence.h" #include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector <ll>; using vi = vector <int>; using ii = pair <ll, ll>; using vii = vector <ii>; struct MedianDS { multiset <ll, greater <ll> > st1; // big to small (mid...0) multiset <ll> st2; // small to big (mid...n) MedianDS () {} void stabilize () { while (st2.size() > st1.size()) { st1.insert(*st2.begin()); st2.erase(st2.begin()); } while (st1.size() > st2.size()) { st2.insert(*st1.begin()); st1.erase(st1.begin()); } } void insert (ll x) { ll mid = (st2.size() ? *st2.begin() : 0); if (x >= mid) st2.insert(x); else st1.insert(x); stabilize(); } void erase (ll x) { ll mid = (st2.size() ? *st2.begin() : 0); if (x >= mid) st2.erase(st2.find(x)); else st1.erase(st1.find(x)); stabilize(); } pair <ll, ll> query () { if (st1.size() == st2.size()) { // two medians ll med1 = *st1.begin(); ll med2 = *st2.begin(); return { med1, med2 }; } else { // one median assert(st2.size() > st1.size()); ll med = *st2.begin(); return { med, med }; } } }; int sequence (int n, vi ve) { for (int &i : ve) i--; ll ans = 0; for (ll l = 0; l < n; l++) { vll freq(n, 0); MedianDS ds; for (ll r = l; r < n; r++) { freq[ve[r]]++; ds.insert(ve[r]); auto [a, b] = ds.query(); ans = max(ans, freq[a]); ans = max(ans, freq[b]); } } return int(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...