Submission #883234

#TimeUsernameProblemLanguageResultExecution timeMemory
883234borisAngelovIzbori (COCI22_izbori)C++17
40 / 110
3048 ms12720 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int n; int a[maxn]; vector<int> byPosition[maxn]; void read() { cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } } void compress() { vector<pair<int, int>> v; for (int i = 1; i <= n; ++i) { v.push_back(make_pair(a[i], i)); } sort(v.begin(), v.end()); int maxNumber = 0; for (int i = 0; i < v.size(); ++i) { if (i == 0 || v[i].first != v[i - 1].first) { ++maxNumber; } a[v[i].second] = maxNumber; } } int b[maxn]; int pref[maxn]; struct FenwickTree { int tree[2 * maxn]; void reset() { for (int i = 1; i <= 2 * n; ++i) { tree[i] = 0; } } void update(int pos, int val) { for (int i = pos; i <= 2 * n; i += (i & (-i))) { tree[i] += val; } } int query(int pos) { int result = 0; for (int i = pos; i >= 1; i -= (i & (-i))) { result += tree[i]; } return result; } }; FenwickTree tree; void solve() { compress(); for (int i = 1; i <= n; ++i) { byPosition[a[i]].push_back(i); } long long ans = 0; for (int i = 1; i <= n; ++i) { if (byPosition[i].empty() == true) { continue; } for (int j = 1; j <= n; ++j) { b[j] = -1; } for (int j = 0; j < byPosition[i].size(); ++j) { b[byPosition[i][j]] = +1; } tree.reset(); tree.update(n, +1); for (int j = 1; j <= n; ++j) { pref[j] = pref[j - 1] + b[j]; tree.update(pref[j] + n, +1); ans += tree.query(pref[j] + n - 1); } } cout << ans << endl; } void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { fastIO(); read(); solve(); return 0; }

Compilation message (stderr)

Main.cpp: In function 'void compress()':
Main.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for (int i = 0; i < v.size(); ++i)
      |                     ~~^~~~~~~~~~
Main.cpp: In function 'void solve()':
Main.cpp:108:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |         for (int j = 0; j < byPosition[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...