Submission #412853

#TimeUsernameProblemLanguageResultExecution timeMemory
412853aryan12Global Warming (NOI13_gw)C++17
19 / 40
799 ms65540 KiB
#include <bits/stdc++.h> using namespace std; #define int long long mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); void Solve() { int n; cin >> n; vector<int> a(n + 1); vector<bool> isTaken(n + 3); vector<vector<int> > positions(n + 1); map<int, int> cc; for(int i = 1; i <= n; i++) { cin >> a[i]; cc[a[i]]++; isTaken[i] = false; } isTaken[0] = true; isTaken[n + 1] = true; int cnt = 1; for(auto i: cc) { cc[i.first] = cnt++; } for(int i = 1; i <= n; i++) { a[i] = cc[a[i]]; positions[a[i]].push_back(i); } int ans = 0, curr = 0; for(int i = 1; i <= n; i++) { for(int j = 0; j < positions[i].size(); j++) { int curPosition = positions[i][j]; isTaken[curPosition] = true; if(!isTaken[curPosition - 1] && !isTaken[curPosition + 1]) { curr++; } else if(isTaken[curPosition - 1] && isTaken[curPosition + 1]) { curr--; } } ans = max(ans, curr); } cout << ans + 1 << "\n"; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; //cin >> t; while(t--) { Solve(); } return 0; }

Compilation message (stderr)

gw.cpp: In function 'void Solve()':
gw.cpp:31:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(int j = 0; j < positions[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...