Submission #759662

#TimeUsernameProblemLanguageResultExecution timeMemory
759662IvanJSequence (APIO23_sequence)C++17
28 / 100
2068 ms18648 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; struct tree { int pot; vector<int> T; void init(int N) { pot = 1; while(pot < N) pot <<= 1; for(int i = 0;i < pot * 2;i++) T.pb(0); } void add(int x) { x += pot; T[x]++; x >>= 1; while(x > 0) T[x] = T[x * 2] + T[x * 2 + 1], x >>= 1; } int find(int x, int lo, int hi, int target) { if(lo == hi) return lo; int mid = (lo + hi) / 2; if(T[x * 2] >= target) return find(x * 2, lo, mid, target); else return find(x * 2 + 1, mid + 1, hi, target - T[x * 2]); } ii medians() { int K = T[1]; int p1 = (K - 1) / 2 + 1; int p2 = K / 2 + 1; return {find(1, 0, pot - 1, p1), find(1, 0, pot - 1, p2)}; } }; int sequence(int N, vector<int> A) { tree T; T.init(N); for(int i = 0;i < N;i++) A[i]--; int ans = 0; for(int i = 0;i < N;i++) { vector<int> cnt(N, 0); tree T; T.init(N); for(int j = i;j < N;j++) { cnt[A[j]]++; T.add(A[j]); ii p = T.medians(); ans = max(ans, max(cnt[p.x], cnt[p.y])); } } 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...