Submission #907477

#TimeUsernameProblemLanguageResultExecution timeMemory
907477vjudge1Izbori (COCI22_izbori)C++17
25 / 110
31 ms6092 KiB
#include<bits/stdc++.h> using namespace std; int n, a[200001], num = 0, cnt[200001], sz = 2, cnt2[200001], res = 0, c[200001], pfs[200001], dp[200001], sl[400001]; pair<int, int> b[200001]; vector<int> v; bool check[200001]; bool cmp(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; b[i].first = a[i]; b[i].second = i; } int last = -1; sort(b + 1, b + 1 + n); for (int i = 1; i <= n; i++) { int l2 = b[i].first; if(b[i].first == last) b[i].first = num; else b[i].first = ++num; last = l2; } sort(b + 1, b + 1 + n, cmp); for (int i = 1; i <= n; i++) { a[i] = b[i].first; cnt[a[i]]++; if(cnt[a[i]] > sz && !check[a[i]]) { v.push_back(a[i]); check[a[i]] = true; } } for (int i = 1; i <= n; i++) { int mx = 1; for (int j = i; j <= min(i + 2 * sz - 1, n); j++) { num = j - i + 1; if(cnt[a[j]] <= sz) { cnt2[a[j]]++; mx = max(mx, cnt2[a[j]]); if(mx > num / 2) res++; } } for (int j = i; j <= min(i + 2 * sz - 1, n); j++) { if(cnt[a[j]] < sz) cnt2[a[j]]--; } } for (int i = 0; i < v.size(); i++) { int bnum = v[i]; pfs[0] = n; sl[n] = 1; for (int j = 1; j <= n; j++) { if(a[j] == bnum) c[j] = 1; else c[j] = -1; pfs[j] = pfs[j - 1] + c[j]; if(pfs[j] > pfs[j - 1]) { dp[j] = dp[j - 1] + sl[pfs[j - 1]]; } else { dp[j] = dp[j - 1] - sl[pfs[j]]; } sl[pfs[j]]++; res += dp[j]; } for (int j = 1; j <= n; j++) { sl[pfs[j]] = 0; } } cout << res << '\n'; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for (int i = 0; i < v.size(); i++) {
      |                     ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...