Submission #941264

#TimeUsernameProblemLanguageResultExecution timeMemory
941264LOLOLOSequence (APIO23_sequence)C++17
0 / 100
2050 ms69240 KiB
#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 = 5e5 + 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 + 10; 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 is(int l1, int r1, int l, int r) { return max(l1, l) <= min(r1, r); } 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, a = 0; if (l1 - d >= l && l1 - d <= r) a |= is(l1 - d * 2, l1 - d, l, r); if (r1 - d >= l && r1 - d <= r) a |= is(r1 - d * 2, r1 - d, l, r); if (l + d >= l1 && l + d <= r1) a |= is(l + d, l1 + d * 2, l1, r1); if (r + d >= l1 && r + d <= r1) a |= is(r + d, r + d * 2, l1, r1); return a; } 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 = 0; while (l <= r) { m = (l + r) / 2; if (check(m)) { ans = m; l = m + 1; } else { r = m - 1; } } return ans; } /*int main() { cout << sequence(14, {2, 6, 2, 5, 3, 4, 2, 1, 4, 3, 5, 6, 3, 2}) << '\n'; cout << sequence(9, {1, 1, 2, 3, 4, 3, 2, 1, 1}) << '\n'; cout << sequence(14, {2, 6, 2, 5, 3, 4, 2, 1, 4, 3, 5, 6, 3, 2}) << '\n'; return 0; }*/
#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...