Submission #760224

#TimeUsernameProblemLanguageResultExecution timeMemory
760224danikoynovSequence (APIO23_sequence)C++17
0 / 100
2073 ms35468 KiB
#include "sequence.h" #include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; vector < int > occ[maxn]; int val[maxn], pref[maxn]; int sequence(int N, vector<int> A) { A.insert(A.begin(), 0); for (int i = 1; i <= N; i ++) occ[A[i]].push_back(i); int ans = 0; for (int x = 1; x <= N; x ++) { for (int i = 1; i <= N; i ++) { if (A[i] < x) val[i] = -1; else if (A[i] == x) val[i] = 0; else val[i] = 1; pref[i] = pref[i - 1] + val[i]; } for (int i = 0; i < occ[x].size(); i ++) { int j = i + ans; if (j >= occ[x].size()) break; int l = occ[x][i], r = occ[x][j]; int min_lf = 1e9, max_lf = -1e9; int min_rf = 1e9, max_rf = -1e9; for (int p = 0; p < l; p ++) { min_lf = min(min_lf, pref[p]); max_lf = max(max_lf, pref[p]); } for (int p = r; p <= N; p ++) { min_rf = min(min_rf, pref[p]); max_rf = max(max_rf, pref[p]); } max_rf += (j - i + 1); min_rf -= (j - i + 1); if (max(min_rf, min_lf) <= min(max_rf, max_lf)) { ans ++; i --; } } } return ans; }

Compilation message (stderr)

sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:30:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for (int i = 0; i < occ[x].size(); i ++)
      |                         ~~^~~~~~~~~~~~~~~
sequence.cpp:33:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |             if (j >= occ[x].size())
      |                 ~~^~~~~~~~~~~~~~~~
#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...