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 <bits/stdc++.h>
//#include "sequence.h"
using namespace std;
#define ll long long
#define sz size()
#define ff first
#define ss second
#define pb push_back
#define pii pair <int, int>
const int N = 5e5 + 5;
int a[N], st[N], n, val[N];
void gosh (int x) {
for (int i = x; i <= n; i += i&(-i)) {
st[i]++;
}
}
int answer (int x) {
int ret = 0;
// int kk = 0;
for (int i = x; i > 0; i -= i&(-i)) {
// cout << i << " --> " ;
// kk++;
// if (kk == 15) {
// exit(0);
// }
ret += st[i];
}
return ret;
}
int cykar (int x, int den) {
// cout << x << "\n";
int l = 1, r = n;
while (l <= r) {
int md = (l + r) / 2;
// cout << l << " " << r << "\n";
int jj = answer(md);
if (jj < x) {
l = md + 1;
}
else if (x <= jj and answer(md - 1) < x) {
return md;
}
else {
r = md - 1;
}
}
}
int sequence(int N, vector<int> A) {
n = N;
for (int i = 0; i < N; ++i) {
a[i] = A[i];
}
int jogap = 0;
for (int i = 0; i < n; ++i) {
for (int j = i; j < n; ++j) {
gosh(a[j]);
val[a[j]]++;
pii x;
int san = j - i + 1;
x.ff = cykar ((san - 1) / 2 + 1, san);
x.ss = cykar (san / 2 + 1, san);
int ans1 = val[x.ff], ans2 = val[x.ss];
jogap = max ({ans1, ans2, jogap});
}
for (int j = 0; j <= n; ++j) {
st[j] = 0;
val[j] = 0;
}
}
return jogap;
}
//int main() {
// freopen ("input.txt", "r", stdin);
// int N;
// assert(1 == scanf("%d", &N));
//
// std::vector<int> A(N);
// for (int i = 0; i < N; ++i) {
// assert(1 == scanf("%d", &A[i]));
// }
//
// int result = sequence(N, A);
// printf("%d\n", result);
// return 0;
//}
//
Compilation message (stderr)
sequence.cpp: In function 'int cykar(int, int)':
sequence.cpp:51:1: warning: control reaches end of non-void function [-Wreturn-type]
51 | }
| ^
# | 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... |