Submission #981154

#TimeUsernameProblemLanguageResultExecution timeMemory
981154math_rabbit_1028Sequence (APIO23_sequence)C++17
7 / 100
168 ms33700 KiB
#include "sequence.h" #include <bits/stdc++.h> using namespace std; int n, m, ans = 0; vector<int> arr; vector<int> pos[505050]; int sequence(int N, vector<int> A) { n = N; arr = A; sort(A.begin(), A.end()); A.erase(unique(A.begin(), A.end()), A.end()); m = A.size(); for (int i = 0; i < n; i++) { arr[i] = lower_bound(A.begin(), A.end(), arr[i]) - A.begin(); } for (int i = 0; i < n; i++) { pos[arr[i]].push_back(i); } for (int i = 0; i < m; i++) { int mn = pos[i].front(), mx = pos[i].back(); if (mx - mn + 1 == pos[i].size()) { ans = max(ans, mx - mn + 1); continue; } int ed, st; //[mn, ed] + [st, mx] for (int j = 1; ; j++) { assert(pos[i].size() > j); if (pos[i][j] > pos[i][j-1] + 1) { ed = pos[i][j-1]; st = pos[i][j]; break; } } ans = max(ans, ed - mn + 1); ans = max(ans, mx - st + 1); if (mx - mn + 1 <= n/2 + 1) ans = max(ans, ed - mn + 1 + mx - st + 1); } return ans; }

Compilation message (stderr)

sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:26:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         if (mx - mn + 1 == pos[i].size()) {
      |             ~~~~~~~~~~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from sequence.cpp:3:
sequence.cpp:32:34: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |             assert(pos[i].size() > j);
      |                    ~~~~~~~~~~~~~~^~~
#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...