제출 #569710

#제출 시각아이디문제언어결과실행 시간메모리
569710hoanghq2004Diversity (CEOI21_diversity)C++14
64 / 100
7032 ms17688 KiB
#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) 메시지

diversity.cpp: In function 'int main()':
diversity.cpp:28:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   28 |         for (auto [_, __]: cnt) s.push_back(__);
      |                   ^
diversity.cpp:31:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for (int i = 0; i < s.size(); ++i) if (i % 2 == 0) a.push_back(s[i]);
      |                         ~~^~~~~~~~~~
diversity.cpp:36:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for (int i = 0; i < a.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...