# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
569710 | hoanghq2004 | Diversity (CEOI21_diversity) | C++14 | 7032 ms | 17688 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 3e5 + 10;
int n, q;
int a[N];
int main() {
ios :: sync_with_stdio(0); cin.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; ++i) cin >> a[i];
while (q--) {
int L, R;
cin >> L >> R;
map <int, int> cnt;
for (int i = L; i <= R; ++i) ++cnt[a[i]];
vector <int> s;
for (auto [_, __]: cnt) s.push_back(__);
sort(s.begin(), s.end());
vector <int> a;
for (int i = 0; i < s.size(); ++i) if (i % 2 == 0) a.push_back(s[i]);
for (int i = s.size() - 1; i >= 0; --i) if (i % 2 == 1) a.push_back(s[i]);
int tot = (R - L + 1);
long long ans = 0;
int cur = 0;
for (int i = 0; i < a.size(); ++i) {
ans += 1LL * a[i] * (a[i] + 1) / 2;
ans += 1LL * (cur + a[i]) * (tot - cur);
ans -= 1LL * a[i] * a[i];
cur += a[i];
}
cout << ans << '\n';
}
}
컴파일 시 표준 에러 (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... |