| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 709019 | Sanzhar23 | Diversity (CEOI21_diversity) | C++14 | 72 ms | 12128 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define bug cout << "bug" << endl
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pll pair <ll, ll>
#define pii pair <int, int>
#define triple pair <pair <ll, ll> , ll>
#define ull unsigned long long
#define ld long double
#define pinode pair <node*, node*>
const ll INF = 9e18 + 5;
const ll inf = 1e9 + 5;
const ll N = 3e5 + 5;
const ll shift = 2e6;
const ll mod = 998244353;
const ll mod2 = 1e9 + 9;
const ll M = 1e3 + 5;
const ll LOG = 21;
const ll sp = 263;
const ll sp2 = 9973;
const int block = 100;
const double eps = 1e-10;
int n, q;
int a[N], cnt[N], pref[N], suf[N];
int main(){
speed;
cin >> n >> q;
for(int i = 1; i <= n; i++){
cin >> a[i];
cnt[a[i]]++;
}
int l, r;
cin >> l >> r;
vector <pii> vt;
for(int i = 1; i <= 300000; i++){
if(cnt[i] != 0)
vt.pb({cnt[i], i});
}
sort(all(vt));
vector <int> nw;
vector <pii> gt;
gt.pb({0, 0});
for(int i = 0; i < vt.size(); i++){
int x = vt[i].S, col = vt[i].F;
if(i % 2 == 0){
gt.pb({x, col});
for(int j = 0; j < col; j++){
nw.pb(x);
}
}
}
for(int i = vt.size() - 1; i >= 0; i--){
int x = vt[i].S, col = vt[i].F;
if(i % 2 == 1){
gt.pb({x, col});
for(int j = 0; j < col; j++){
nw.pb(x);
}
}
}
ll ans = 0;
/*
for(int i = 0; i < nw.size(); i++){
set <int> st;
for(int j = i; j < nw.size(); j++){
st.insert(nw[j]);
ans += (int) st.size();
}
}
*/
int len = gt.size() - 1;
for(int i = 1; i <= len; i++){
pref[i] = pref[i - 1] + gt[i].S;
}
for(int i = len; i >= 1; i--){
suf[i] = suf[i + 1] + gt[i].S;
}
for(int i = 1; i <= len; i++){
int x = gt[i].F, col = gt[i].S;
ll f1 = pref[i - 1] * 1ll * suf[i + 1];
ll f2 = col * 1ll * (col + 1) / 2ll;
ll f3 = col * 1ll * pref[i - 1];
ll f4 = col * 1ll * suf[i + 1];
ans += (f1 + f2 + f3 + f4);
}
cout << ans << endl;
}
/*
%I64d6
%I64d
*/
컴파일 시 표준 에러 (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... | ||||
