이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define spc << " " <<
#define endl "\n"
#define all(x) x.begin(), x.end()
#define int long long
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>
#define st first
#define nd second
#define mid (l+r)/2
#define inf 1e15
#define MOD 998244353
#define MX 200005
using namespace std;
void solve(){
int n,q; cin >> n >> q;
int arr[n+1];
map<int, int> cnt;
for(int i=1; i<=n; i++){
cin >> arr[i];
cnt[arr[i]]++;
}
for(int i=1; i<=q; i++){int a,b; cin >> a >> b;}
vi wow;
for(auto p:cnt) wow.pb(p.nd);
sort(all(wow));
int p1=0, p2=0, ans=n*(n+1)/2;
for(int i=0; i<wow.size()-1; i++){
if(p1>p2) swap(p1,p2);
p1+=wow[i];
ans+=p1*(n-p1);
}
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
/*#else
freopen("248.in","r",stdin);
freopen("248.out","w",stdout);*/
#endif
int t=1;
//cin >> t;
while(t--) solve();
}
컴파일 시 표준 에러 (stderr) 메시지
diversity.cpp: In function 'void solve()':
diversity.cpp:33:19: 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 i=0; i<wow.size()-1; i++){
| ~^~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |