제출 #980772

#제출 시각아이디문제언어결과실행 시간메모리
980772davitmarg서열 (APIO23_sequence)C++17
31 / 100
2023 ms49884 KiB
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <cstring> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <queue> #include <bitset> #include <stack> #include <cassert> #include <iterator> #include <random> #include <chrono> #include <fstream> #define fastIO \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define mod 1000000007ll #define LL long long #define LD long double #define MP make_pair #define PB push_back #define all(v) v.begin(), v.end() using namespace std; const int N = 500005; int n, a[N], ans; vector<int> pos[N]; pair<int, int> t[(N + N) * 4]; int d[(N + N) * 4]; pair<int, int> merge(pair<int, int> a, pair<int, int> b) { return MP(min(a.first, b.first), max(a.second, b.second)); } void push(int v, int l, int r) { if (d[v] == 0) return; if (l != r) { d[v * 2] += d[v]; d[v * 2 + 1] += d[v]; } t[v] = MP(t[v].first + d[v], t[v].second + d[v]); d[v] = 0; } void add(int v, int l, int r, int i, int j, int val) { push(v, l, r); if (i > j) return; if (i == l && j == r) { d[v] += val; push(v, l, r); return; } int m = (l + r) / 2; add(v * 2, l, m, i, min(m, j), val); add(v * 2 + 1, m + 1, r, max(m + 1, i), j, val); t[v] = merge(t[v * 2], t[v * 2 + 1]); } pair<int, int> get(int v, int l, int r, int i, int j) { push(v, l, r); if (i > j) return MP(mod, -mod); if (i == l && j == r) return t[v]; int m = (l + r) / 2; return merge( get(v * 2, l, m, i, min(m, j)), get(v * 2 + 1, m + 1, r, max(m + 1, i), j) ); } int sequence(int nn, vector<int> aa) { n = nn; for (int i = 1; i <= n; i++) a[i] = aa[i - 1]; for (int i = 1; i <= n; i++) pos[a[i]].push_back(i); for (int i = 1; i <= n; i++) add(1, 0, n, i, n, 1); for (int x = 1; x <= n; x++) { for (int p = 0; p < pos[x].size(); p++) { int i = pos[x][p]; add(1, 0, n, i, n, -1); } int l = 1; int r = pos[x].size(); while (l <= r) { int len = (l + r) / 2; bool f = 0; for (int p = len - 1; p < pos[x].size(); p++) { int i = pos[x][p]; int k = p - len + 1; int j = pos[x][k]; pair<int, int> dr = get(1, 0, n, i, n); pair<int, int> dl = get(1, 0, n, 0, j - 1); pair<int, int> d = MP(dr.first - dl.second, dr.second - dl.first); if ((d.second < 0 && len >= -d.second) || (d.first > 0 && len >= d.first) || (d.first <= 0 && d.second >= 0)) { ans = max(ans, len); f = true; } } if (f) l = len + 1; else r = len - 1; } for (int p = 0; p < pos[x].size(); p++) { int i = pos[x][p]; add(1, 0, n, i, n, -1); } } return ans; } #ifdef death void solve() { int nn; vector<int> aa; cin >> nn; for (int i = 0; i < nn; i++) { int x; cin >> x; aa.push_back(x); } cout << sequence(nn, aa) << endl; } int main() { fastIO; int T = 1; //cin >> T; while (T--) solve(); return 0; } #endif // death /* 9 1 1 2 3 4 3 2 1 1 14 2 6 2 5 3 4 2 1 4 3 5 6 3 2 */

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

sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:109:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |         for (int p = 0; p < pos[x].size(); p++)
      |                         ~~^~~~~~~~~~~~~~~
sequence.cpp:123:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  123 |             for (int p = len - 1; p < pos[x].size(); p++)
      |                                   ~~^~~~~~~~~~~~~~~
sequence.cpp:154:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  154 |         for (int p = 0; p < pos[x].size(); p++)
      |                         ~~^~~~~~~~~~~~~~~
#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...