# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1125320 | Peter2017 | Diversity (CEOI21_diversity) | C++20 | 32 ms | 4604 KiB |
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pii pair<int,int>
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define mem(a, b) memset(a, b, sizeof(a))
#define name "test"
using namespace std;
const int N = 3e5 + 5;
const int mod = 1e9 + 7;
template <typename T1, typename T2> bool maxi(T1 &a, T2 b){if (a < b){a = b; return 1;} return 0;}
template <typename T1, typename T2> bool mini(T1 &a, T2 b){if (a > b){a = b; return 1;} return 0;}
int n;
int q;
int a[N];
int L[N];
int R[N];
int cnt[N];
deque<int> dq;
vector<int> value;
void load(){
cin.tie(0)->sync_with_stdio(0);
if (fopen(name".inp", "r")){
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
}
void input(){
cin >> n >> q;
for (int i = 1; i <= n; i++){
cin >> a[i];
cnt[a[i]]++;
}
for (int i = 1; i <= q; i++)
cin >> L[i] >> R[i];
}
ll cal(ll n){
return n * (n + 1) / 2;
}
void solve(){
int MAX = 3e5;
for (int i = MAX; i >= 1; i--) if (cnt[i]) value.push_back(cnt[i]);
sort(value.begin(), value.end(), greater<int>());
bool type = 0;
for (int x : value){
if (type == 0) dq.push_front(x);
else dq.push_back(x);
type ^= 1;
}
value.clear();
while (dq.size()){
value.push_back(dq.front());
dq.pop_front();
}
ll ans = 0;
int sum = n;
for (int x : value){
for (int j = 1; j <= x; j++){
if (j == 1) ans += 1LL * (n - sum + 1) * sum;
else ans += sum;
sum--;
}
}
cout << ans;
}
int main(){
load();
input();
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |