Submission #684968

# Submission time Handle Problem Language Result Execution time Memory
684968 2023-01-23T03:26:35 Z moonhero Diversity (CEOI21_diversity) C++14
0 / 100
0 ms 212 KB
#include<bits/stdc++.h>
using namespace std;
const long long N = 1e1 + 5;
long long t[N][N * 4], a[N];
vector <long long> ans, res;
void build (long long v, long long tl, long long tr) {
    if (tl == tr) {
        for (int i = 0 ; i < N; i++) t[i][v] = 0;
        t[a[tl]][v] = 1;
        return;
    } long long tm = (tl + tr) / 2;
    build(v * 2, tl, tm);
    build(v * 2 + 1, tm + 1, tr);
    for (int i = 1; i < N; i++) t[i][v] = t[i][v * 2] + t[i][v * 2 + 1];
}
void get (int v, int tl, int tr, int l, int r) {
    if (tl >= l && tr <= r) {
        for (int i = 0; i < N; i++) 
            for (int j = 0; j < t[i][v]; j++) ans.push_back(i);
        return; 
    } if (tl > r || tr < l) return;
    int tm = (tl + tr) / 2;
    get(v * 2, tl, tm, l, r);
    get(v * 2 + 1, tm + 1, tr, l, r);
}
long long cont (long long r) {
    return (r + 1) * (r) / 2;
}
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, q; cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        ans.push_back(a[i]);
    }
    // build(1, 1, n);
    while (q--) {
        int l, r; cin >> l >> r;
        // get(1, 1, n, l, r);
        sort(ans.begin(), ans.end());
        for (int i = 0 ; i < ans.size();) {
            int cnt = 1, j = i + 1;
            while (j < ans.size()) {
                if (ans[j] == ans[i]) cnt++, j++;
                else break;
            } i = j;
            res.push_back(cnt);
        } 
        long long x = 0;
        for (int i = 0; i < res.size(); i++) {
            long long nw = 0, k = 2, nwres = res[i];
            for (int j = i + 1; j < res.size(); j++) {
                nw += k, nwres += k * res[j], k++;
            } x += nwres * res[i] - cont(res[i] - 1);
        } cout << x << '\n';
        // for (auto it : res) cout << it << ' ' ;
        // cout << '\n';
    }
    return 0;
}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:42:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for (int i = 0 ; i < ans.size();) {
      |                          ~~^~~~~~~~~~~~
diversity.cpp:44:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |             while (j < ans.size()) {
      |                    ~~^~~~~~~~~~~~
diversity.cpp:51:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for (int i = 0; i < res.size(); i++) {
      |                         ~~^~~~~~~~~~~~
diversity.cpp:53:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |             for (int j = i + 1; j < res.size(); j++) {
      |                                 ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -