# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
981942 | Maaxle | Cyberland (APIO23_cyberland) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "sequence.h"
#include <bits/stdc++.h>
#define range(it, a, b) for (ll it = a; it < b; it++)
#define all(x) begin(x), end(x)
#define ll long long
#define ull unsigned long long
#define INF64 ((ll) 1 << 62)
#define INF32 (1 << 30)
#define mset multiset
#define uset unordered_set
#define umap unordered_map
#define pqueue priority_queue
#define ptr(A) shared_ptr<A>
using namespace std;
struct BIT {
vector<int> bit;
BIT (int sz) {
bit.resize(sz, 0);
}
void update(int i, int d) {
for ( ; i < bit.size(); i |= i + 1)
bit[i] += d;
}
int sum(int i) {
int ans = 0;
for ( ; i >= 0; i = (i & (i + 1)) - 1)
ans += bit[i];
return ans;
}
int sum (int l, int r) {
return sum(r) - (l ? sum(l - 1) : 0);
}
};
int query(int i, BIT& ft, int& N) {
int l = 1, r = N, m;
while (l < r) {
m = (l+r)/2;
if (ft.sum(m) >= i)
r = m;
else l = m+1;
}
return ft.sum(l, l);
}
int sequence(int N, vector<int> A) {
int maxi = 0;
for (int l = 0; l < N; l++) {
BIT ft (N+1);
for (int r = l; r < N; r++) {
ft.update(A[r], 1);
int sz = r-l+1;
int a = sz/2;
maxi = max(maxi, query(a+1, ft, N));
if ((sz & 1) && sz > 1)
maxi = max(maxi, query(a+2, ft, N));
}
}
return maxi;
}