Submission #998574

#TimeUsernameProblemLanguageResultExecution timeMemory
998574andrei_iorgulescuDiversity (CEOI21_diversity)C++14
38 / 100
7067 ms9412 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int n,a[300005],fr[300005],q,l1,r1; signed main() { cin >> n >> q; for (int i = 1; i <= n; i++) cin >> a[i],fr[a[i]]++; cin >> l1 >> r1; vector<int> poz_fr; for (int i = 1; i <= 300000; i++) if (fr[i] > 0) poz_fr.push_back(fr[i]); sort(poz_fr.begin(),poz_fr.end()); vector<int> v(poz_fr.size()); l1 = 0,r1 = poz_fr.size() - 1; for (int i = 0; i < poz_fr.size(); i++) { if (i % 2 == 0) v[l1] = poz_fr[i],l1++; else v[r1] = poz_fr[i],r1--; } int ans = 0; for (int i = 0; i < v.size(); i++) ans += v[i] * (v[i] + 1) / 2; for (int i = 0; i < v.size(); i++) for (int j = i + 1; j < v.size(); j++) ans += (j - i + 1) * v[i] * v[j]; cout << ans; return 0; }

Compilation message (stderr)

diversity.cpp: In function 'int main()':
diversity.cpp:22:23: 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]
   22 |     for (int i = 0; i < poz_fr.size(); i++)
      |                     ~~^~~~~~~~~~~~~~~
diversity.cpp:30:23: 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]
   30 |     for (int i = 0; i < v.size(); i++)
      |                     ~~^~~~~~~~~~
diversity.cpp:32:23: 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]
   32 |     for (int i = 0; i < v.size(); i++)
      |                     ~~^~~~~~~~~~
diversity.cpp:33:31: 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]
   33 |         for (int j = i + 1; j < v.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...