Submission #954428

#TimeUsernameProblemLanguageResultExecution timeMemory
954428Mher777Sequence (APIO23_sequence)C++17
28 / 100
2086 ms10104 KiB
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <iomanip> #include <array> #include <string> #include <algorithm> #include <cmath> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <vector> #include <stack> #include <queue> #include <deque> #include <bitset> #include <list> #include <iterator> #include <numeric> #include <complex> #include <utility> #include <random> #include <cassert> #include <fstream> #include "sequence.h" using namespace std; mt19937 rnd(7069); typedef int itn; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef float fl; typedef long double ld; using vi = vector<int>; using vll = vector<ll>; using mii = map<int, int>; using mll = map<ll, ll>; using pii = pair<int, int>; using pll = pair<ll, ll>; #define ff first #define ss second #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define mpr make_pair #define yes cout<<"Yes\n" #define no cout<<"No\n" #define all(x) (x).begin(), (x).end() const int MAX = int(2e9 + 5); const ll MAXL = ll(1e18) + 5ll; const int N = 500005; int a[N], f[N]; int n; void add_fen(int ind, int val) { while (ind <= n) { f[ind] += val; ind += (ind & -ind); } } int sum_fen(int ind) { int ret = 0; while (ind) { ret += f[ind]; ind -= (ind & -ind); } return ret; } int qry_fen(int l, int r) { return sum_fen(r) - sum_fen(l - 1); } int sol1() { int len; int ret = 0; vi cnt(n + 1); for (int i = 1; i <= n; ++i) { cnt.assign(n + 1, 0); for (int j = 1; j <= n; ++j) add_fen(j, -qry_fen(j, j)); len = 0; for (int j = i; j <= n; ++j) { ++cnt[a[j]]; add_fen(a[j], 1); ++len; int ind1, ind2; if (len % 2) { ind1 = ind2 = len / 2 + 1; } else { ind1 = len / 2; ind2 = len / 2 + 1; } int l = 1, r = n, mid; while (l <= r) { mid = (l + r) / 2; int index = qry_fen(1, mid); int cnt_x = cnt[mid]; if (index - cnt_x >= ind1) { r = mid - 1; } else if (index < ind1) { l = mid + 1; } else if (cnt_x) { ret = max(ret, cnt_x); break; } else { r = mid - 1; } } l = 1, r = n; while (l <= r) { mid = (l + r) / 2; int index = qry_fen(1, mid); int cnt_x = cnt[mid]; if (index - cnt_x >= ind2) { r = mid - 1; } else if (index < ind2) { l = mid + 1; } else if (cnt_x) { ret = max(ret, cnt_x); break; } else { r = mid - 1; } } } } return ret; } int sequence(int N, std::vector<int> A) { n = N; for (int i = 1; i <= n; ++i) { a[i] = A[i - 1]; } return sol1(); } /* 7 1 2 3 1 2 1 3 3 9 1 1 2 3 4 3 2 1 1 2 14 2 6 2 5 3 4 2 1 4 3 5 6 3 2 3 */
#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...