Submission #1085242

#TimeUsernameProblemLanguageResultExecution timeMemory
1085242TimoshSequence (APIO23_sequence)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "sequence.h" using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key int sequence(int n, vector<int> A) { int ans = 1; if (*max_element(A.begin(), A.end()) <= 3) { vector<vector<int>> ind(3), pref(n + 1, vector<int>(3)); for (int i = 0; i < n; i++) ind[A[i] - 1].push_back(i); int l = 1, r = ind[0].size(); while (l <= r) { int m = (l + r) / 2; bool f = 0; for (int i = 0; i + m - 1 < ind[0].size(); i++) { if (m * 2 >= ind[0][i + m - 1] - ind[0][i] + 1) { f = 1; ans = max(ans, m); } } if (f) l = m + 1; else r = m - 1; } int l = 1, r = ind[2].size(); while (l <= r) { int m = (l + r) / 2; bool f = 0; for (int i = 0; i + m - 1 < ind[2].size(); i++) { if (m * 2 >= ind[2][i + m - 1] - ind[2][i] + 1) { f = 1; ans = max(ans, m); } } if (f) l = m + 1; else r = m - 1; } for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) pref[i + 1][j] = pref[i][j]; pref[i + 1][A[i] - 1]++; } int l = 1, r = ind[1].size(); while (l <= r) { int m = (l + r) / 2; bool f = 0; for (int i = 0; i + m - 1 < ind[1].size(); i++) { int a = pref[0][ind[1][i + m - 1]] - pref[0][ind[1][i]]; int b = pref[2][ind[1][i + m - 1]] - pref[2][ind[1][i]]; int len = ind[1][i + m - 1] - ind[1][i] + 1 - 2 * abs(a - b); if (m * 2 >= len) ans = max(ans, m); f = 1; } if (f) l = m + 1; else r = m - 1; } return ans; } if (n <= 2e3) { for (int i = 0; i < n; i++) { ordered_set hm; for (int j = i; j < n; j++) { hm.insert(A[j]); int x = *hm.find_by_order((j - i) / 2); int y = *hm.find_by_order((j - i + 1) / 2); ans = max(ans, (int)hm.order_of_key(x + 1) - (int)hm.order_of_key(x)); ans = max(ans, (int)hm.order_of_key(y + 1) - (int)hm.order_of_key(y)); } } bool works = 1; int last = 0; for (int i = 0; i < n; i++) { if (last > A[i]) { for (int j = i; j < n; j++) { if (last < A[j]) works = 0; last = A[j]; } break; } last = A[i]; } if (!works) return ans; } int last = 0; vector<int> cnt(n + 1); for (int i = 0; i < n; i++) { if (last > A[i]) break; cnt[A[i]]++; ans = max(ans, cnt[A[i]]); last = A[i]; } last = 0; for (int i = 1; i <= n; i++) cnt[i] = 0; for (int i = n - 1; i >= 0; i--) { if (last > A[i]) break; last = A[i]; cnt[A[i]]++; ans = max(ans, cnt[A[i]]); } for (int i = 1; i <= n; i++) cnt[i] = 0; sort(A.begin(), A.end()); for (int i = 0; i < n; i++) cnt[A[i]]++; for (int i = n / 2; i < n; i++) ans = max(ans, cnt[A[i]]); return ans; }

Compilation message (stderr)

sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:23:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |       for (int i = 0; i + m - 1 < ind[0].size(); i++)
      |                       ~~~~~~~~~~^~~~~~~~~~~~~~~
sequence.cpp:36:9: error: redeclaration of 'int l'
   36 |     int l = 1, r = ind[2].size();
      |         ^
sequence.cpp:18:9: note: 'int l' previously declared here
   18 |     int l = 1, r = ind[0].size();
      |         ^
sequence.cpp:36:16: error: redeclaration of 'int r'
   36 |     int l = 1, r = ind[2].size();
      |                ^
sequence.cpp:18:16: note: 'int r' previously declared here
   18 |     int l = 1, r = ind[0].size();
      |                ^
sequence.cpp:41:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |       for (int i = 0; i + m - 1 < ind[2].size(); i++)
      |                       ~~~~~~~~~~^~~~~~~~~~~~~~~
sequence.cpp:60:9: error: redeclaration of 'int l'
   60 |     int l = 1, r = ind[1].size();
      |         ^
sequence.cpp:18:9: note: 'int l' previously declared here
   18 |     int l = 1, r = ind[0].size();
      |         ^
sequence.cpp:60:16: error: redeclaration of 'int r'
   60 |     int l = 1, r = ind[1].size();
      |                ^
sequence.cpp:18:16: note: 'int r' previously declared here
   18 |     int l = 1, r = ind[0].size();
      |                ^
sequence.cpp:65:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |       for (int i = 0; i + m - 1 < ind[1].size(); i++)
      |                       ~~~~~~~~~~^~~~~~~~~~~~~~~