Submission #865565

#TimeUsernameProblemLanguageResultExecution timeMemory
865565RifalDiversity (CEOI21_diversity)C++14
0 / 100
1 ms464 KiB
#include <bits/stdc++.h> #include <fstream> //#define endl '\n' #define mod 1000000007 #define INF 9000000000000000 using namespace std; //ofstream fout("intel.out"); //ifstream fin("intel.in"); const int Max = 3e5 + 5; int cnt[Max]; int main() { ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0); int n, q; cin >> n >> q; long long sum = 0; long long dp[n+1] = {}; long long arr[n]; for(int i = 1; i <= n; i++) dp[i] = 1; pair<long long,long long> mn1 = {INF,0}, mn2 = {INF,0}; for(int i = 0; i < n; i++) { cin >> arr[i]; cnt[arr[i]]++; } for(int i = 1; i < Max; i++) { if(cnt[i] != 0) { if(mn1.first > cnt[i]) { mn2.first = mn1.first; mn2.second = mn1.second; mn1.first = cnt[i]; mn1.second = i; } else if(mn2.first > cnt[i]) { mn2.first = cnt[i]; mn2.second = i; } } } vector<int> v; while(cnt[mn1.second]--) { v.push_back(mn1.second); } for(int i = 1; i < Max; i++) { if(i == mn1.second || i == mn2.second) continue; if(cnt[i] != 0) { while(cnt[i]--) { v.push_back(i); } } } while(cnt[mn2.second]--) { v.push_back(mn2.second); } if(q == 1) { int l, r; cin >> l >> r; sum += dp[1]; for(long long i = 1; i < v.size(); i++) { if(v[i] != v[i-1]) { dp[i+1] += i; } dp[i+1] += dp[i]; sum += dp[i+1]; } cout << sum << endl; } return 0; }

Compilation message (stderr)

diversity.cpp: In function 'int main()':
diversity.cpp:55:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for(long long i = 1; 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...