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;
const int MAX_N = 1e5;
struct BIT {
vector<int> bit = vector<int> (MAX_N, 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, bool even) {
int l = 1, r = MAX_N, m;
while (l < r) {
m = (l+r)/2;
if (ft.sum(m) >= i)
r = m;
else l = m+1;
}
int ans = ft.sum(l, l);
if (even && i == ft.sum(l))
ans = max(ans, ft.sum(l+1, l+1));
// cout << l << ' ' << ans << '\n';
return ans;
}
int sequence(int N, vector<int> A) {
int maxi = 0;
for (int l = 0; l < N; l++) {
BIT ft;
for (int r = l; r < N; r++) {
// cout << "** " << l << ' ' << r << '\n';
ft.update(A[r], 1);
int sz = r-l+1;
int a = sz/2 + (sz & 1);
maxi = max(maxi, query(a, ft, !(sz & 1)));
}
}
return maxi;
}
Compilation message (stderr)
sequence.cpp: In member function 'void BIT::update(int, int)':
sequence.cpp:24:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for ( ; i < bit.size(); i |= i + 1)
| ~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |