제출 #954415

#제출 시각아이디문제언어결과실행 시간메모리
954415Mher777서열 (APIO23_sequence)C++17
11 / 100
2074 ms55120 KiB
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <iomanip> #include <array> #include <string> #include <algorithm> #include <cmath> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <vector> #include <stack> #include <queue> #include <deque> #include <bitset> #include <list> #include <iterator> #include <numeric> #include <complex> #include <utility> #include <random> #include <cassert> #include <fstream> #include "sequence.h" #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; mt19937 rnd(7069); typedef int itn; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef float fl; typedef long double ld; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; using vi = vector<int>; using vll = vector<ll>; using mii = map<int, int>; using mll = map<ll, ll>; using pii = pair<int, int>; using pll = pair<ll, ll>; #define ff first #define ss second #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define mpr make_pair #define yes cout<<"Yes\n" #define no cout<<"No\n" #define all(x) (x).begin(), (x).end() const int MAX = int(2e9 + 5); const ll MAXL = ll(1e18) + 5ll; const int N = 500005; int a[N], f[N]; int n; void add_fen(int ind, int val) { while (ind <= n) { f[ind] += val; ind += (ind & -ind); } } int sum_fen(int ind) { int ret = 0; while (ind) { ret += f[ind]; ind -= (ind & -ind); } return ret; } int qry_fen(int l, int r) { return sum_fen(r) - sum_fen(l - 1); } int sol1() { int len; int ret = 0; for (int i = 1; i <= n; ++i) { indexed_set s; for (int j = 1; j <= n; ++j) add_fen(j, -qry_fen(j, j)); set<int> st; len = 0; for (int j = i; j <= n; ++j) { ++len; s.insert(a[j]); st.insert(a[j]); add_fen(a[j], 1); int l = 0, r = st.size() - 1, mid; int ind1, ind2, val1, val2; if (len % 2) { ind1 = ind2 = len / 2 + 1; } else { ind1 = len / 2; ind2 = len / 2 + len % 2; } while (l <= r) { mid = (l + r) / 2; auto x = s.find_by_order(mid); int index = qry_fen(1, *x); int cnt_x = qry_fen(*x, *x); if (index - cnt_x >= ind2) { r = mid - 1; } else if (index < ind1) { l = mid + 1; } else if (index >= ind2 && index - cnt_x < ind1) { ret = max(ret, cnt_x); break; } else if (index >= ind2 && index - cnt_x >= ind1) { ret = max(ret, cnt_x); r = mid - 1; } else if (index == ind1) { ret = max(ret, cnt_x); l = mid + 1; } } } } return ret; } int sequence(int N, std::vector<int> A) { n = N; for (int i = 1; i <= n; ++i) { a[i] = A[i - 1]; } return sol1(); }

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp: In function 'int sol1()':
sequence.cpp:95:29: warning: unused variable 'val1' [-Wunused-variable]
   95 |             int ind1, ind2, val1, val2;
      |                             ^~~~
sequence.cpp:95:35: warning: unused variable 'val2' [-Wunused-variable]
   95 |             int ind1, ind2, val1, val2;
      |                                   ^~~~
#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...