제출 #974311

#제출 시각아이디문제언어결과실행 시간메모리
974311Pannda서열 (APIO23_sequence)C++17
40 / 100
2103 ms51536 KiB
#include "sequence.h" #include <bits/stdc++.h> using namespace std; int sequence(int n, vector<int> a) { vector<vector<int>> mp(n); for (int i = 0; i < n; i++) { a[i]--; mp[a[i]].push_back(i); } auto ok = [&](int x) -> bool { for (int med = 0; med < n; med++) { if (mp[med].empty()) continue; vector<int> cnt(n + 1, 0); vector<int> le_lr(n + 1, 0), mx_le_lr(n + 1, 0); vector<int> le_rl(n + 1, 0), mx_le_rl(n + 1, 0); vector<int> ge_lr(n + 1, 0), mx_ge_lr(n + 1, 0); vector<int> ge_rl(n + 1, 0), mx_ge_rl(n + 1, 0); for (int i = 0; i < n; i++) { cnt[i + 1] = cnt[i] + (a[i] <= med); le_lr[i + 1] = le_lr[i] + 2 * (a[i] <= med) - 1; ge_lr[i + 1] = ge_lr[i] + 2 * (a[i] >= med) - 1; } for (int i = n - 1; i >= 0; i--) { le_rl[i] = le_rl[i + 1] + 2 * (a[i] <= med) - 1; ge_rl[i] = ge_rl[i + 1] + 2 * (a[i] >= med) - 1; } mx_le_lr[n] = le_lr[n], mx_ge_lr[n] = ge_lr[n]; for (int i = n - 1; i >= 0; i--) { mx_le_lr[i] = max(le_lr[i], mx_le_lr[i + 1]); mx_ge_lr[i] = max(ge_lr[i], mx_ge_lr[i + 1]); } mx_le_rl[0] = le_rl[0], mx_ge_rl[0] = ge_rl[0]; for (int i = 1; i <= n; i++) { mx_le_rl[i] = max(le_rl[i], mx_le_rl[i - 1]); mx_ge_rl[i] = max(ge_rl[i], mx_ge_rl[i - 1]); } for (int ii = 0; ii + x <= mp[med].size(); ii++) { int l = mp[med][ii]; int r = mp[med][ii + x - 1] + 1; int lem = cnt[r] - cnt[l]; int gem = (r - l) - lem + x; if (2 * lem >= r - l && 2 * gem >= r - l) return true; if (2 * lem < r - l) { int val = 2 * lem - r + l; // < 0 int up = mx_le_lr[r] - le_lr[r] + mx_le_rl[l] - le_rl[l]; if (val + up >= 0) return true; } else { int val = 2 * gem - r + l; // < 0 int up = mx_ge_lr[r] - ge_lr[r] + mx_ge_rl[l] - ge_rl[l]; if (val + up >= 0) return true; } } } return false; }; int ans = [&]() -> int { int l = 1, r = n; while (l < r) { int m = (l + r + 1) >> 1; if (ok(m)) { l = m; } else { r = m - 1; } } return l; }(); return ans; }

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

sequence.cpp: In lambda function:
sequence.cpp:42:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |             for (int ii = 0; ii + x <= mp[med].size(); ii++) {
      |                              ~~~~~~~^~~~~~~~~~~~~~~~~
#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...