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>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 2e5 + 100;
const int M = 2e6;
struct ST{
vector <pair <int, int>> seg;
vector <int> laz;
ST(int n) {
for (int i = 0; i <= 4 * n; i++) {
seg.pb({0, 0});
laz.pb(0);
}
}
void push(int id) {
int &t = laz[id];
laz[id * 2] += t;
laz[id * 2 + 1] += t;
seg[id * 2].f += t, seg[id * 2].s += t;
seg[id * 2 + 1].f += t, seg[id * 2 + 1].s += t;
t = 0;
}
pair <int, int> merge(pair <int, int> A, pair <int, int> B) {
pair <int, int> C;
C.f = min(A.f, B.f);
C.s = max(A.s, B.s);
return C;
}
void upd(int id, int l, int r, int u, int v, int lz) {
if (l > v || r < u)
return;
if (l >= u && r <= v) {
laz[id] += lz;
seg[id].f += lz;
seg[id].s += lz;
return;
}
push(id);
int m = (l + r) / 2;
upd(id * 2, l, m, u, v, lz);
upd(id * 2 + 1, m + 1, r, u, v, lz);
seg[id] = merge(seg[id * 2], seg[id * 2 + 1]);
}
pair <int, int> get(int id, int l, int r, int u, int v) {
if (l >= u && r <= v)
return seg[id];
push(id);
int m = (l + r) / 2;
if (m + 1 <= u) {
return get(id * 2 + 1, m + 1, r, u, v);
}
if (m >= v) {
return get(id * 2, l, m, u, v);
}
return merge(get(id * 2, l, m, u, v), get(id * 2 + 1, m + 1, r, u, v));
}
};
vector <int> pos[N];
int a[N], n;
bool intersect(pair <int, int> A, pair <int, int> B, int d) {
int l = A.f, r = A.s, l1 = B.f, r1 = B.s;
if (l1 - d >= l && l1 - d <= r)
return 1;
if (r1 - d >= l && r1 - d <= r)
return 1;
if (l + d >= l1 && l + d <= r1)
return 1;
if (r + d >= l1 && r + d <= r1)
return 1;
return 0;
}
bool check(int m) {
ST seg(n);
for (int i = 1; i <= n; i++) {
seg.upd(1, 0, n, i, n, 1);
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j < sz(pos[i]); j++) {
if (j >= m - 1) {
if (intersect(seg.get(1, 0, n, 0, pos[i][j - m + 1] - 1), seg.get(1, 0, n, pos[i][j], n), m * 2)) {
return 1;
}
}
}
for (int j = 0; j < sz(pos[i]); j++) {
seg.upd(1, 0, n, pos[i][j], n, -2);
}
}
return 0;
}
int sequence(int N, vector <int> A) {
n = N;
for (int i = 1; i <= n; i++)
pos[i].clear();
for (int i = 1; i <= n; i++) {
a[i] = A[i - 1];
pos[a[i]].pb(i);
}
int l = 0, r = n, m, ans = 1;
while (l <= r) {
m = (l + r) / 2;
if (check(m)) {
ans = m;
l = m + 1;
} else {
r = m - 1;
}
}
return ans;
}
# | 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... |