답안 #1103434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1103434 2024-10-21T02:09:07 Z ro9669 Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 6008 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(v) v.begin() , v.end()
#define sz(v) int(v.size())
#define unq(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
using namespace std;

typedef long long ll;
typedef pair<int , int> ii;
typedef pair<long long , int> lli;

const int maxN = int(3e5)+7;

int n , q , a[maxN] , cnt[maxN] , sum[2];

void solve(){
    cin >> n >> q;
    for (int i = 1 ; i <= n ; i++) cin >> a[i];
    while (q--){
        int l , r;
        cin >> l >> r;
        for (int i = 1 ; i < maxN ; i++) cnt[i] = 0;
        for (int i = l ; i <= r ; i++) cnt[a[i]]++;
        vector<int> p;
        for (int i = 1 ; i < maxN ; i++){
            if (cnt[i] > 0) p.push_back(cnt[i]);
        }
        sort(all(p));
        ll ans = 0;
        sum[0] = sum[1] = 0;
        for (int i = 0 ; i < sz(p) ; i++){
            ans += 1ll * p[i] * (p[i] + 1) / 2;
            if (i % 2 == 0){
                int x = sum[0] , y = (r - l + 1) - sum[0] - p[i];
                ans += 1ll * x * y;
                ans += 1ll * (x + y) * p[i];
            }
            else{
                int x = sum[1] , y = (r - l + 1) - sum[1] - p[i];
                ans += 1ll * x * y;
                ans += 1ll * (x + y) * p[i];
            }
            sum[i % 2] += p[i];
        }
        cout << ans << "\n";
    }
}

#define name "A"

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen(name".INP" , "r")){
        freopen(name".INP" , "r" , stdin);
        freopen(name".OUT" , "w" , stdout);
    }
    int t = 1; //cin >> t;
    while (t--) solve();
    return 0;
}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         freopen(name".INP" , "r" , stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
diversity.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen(name".OUT" , "w" , stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2656 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2704 KB Output is correct
3 Correct 3 ms 2644 KB Output is correct
4 Correct 5 ms 2716 KB Output is correct
5 Correct 9 ms 2900 KB Output is correct
6 Correct 12 ms 3628 KB Output is correct
7 Correct 12 ms 3412 KB Output is correct
8 Correct 13 ms 3412 KB Output is correct
9 Correct 12 ms 3412 KB Output is correct
10 Correct 13 ms 3440 KB Output is correct
11 Correct 14 ms 3412 KB Output is correct
12 Correct 13 ms 3412 KB Output is correct
13 Correct 14 ms 3412 KB Output is correct
14 Correct 16 ms 3336 KB Output is correct
15 Correct 13 ms 3576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2704 KB Output is correct
3 Correct 3 ms 2644 KB Output is correct
4 Correct 5 ms 2716 KB Output is correct
5 Correct 9 ms 2900 KB Output is correct
6 Correct 12 ms 3628 KB Output is correct
7 Correct 12 ms 3412 KB Output is correct
8 Correct 13 ms 3412 KB Output is correct
9 Correct 12 ms 3412 KB Output is correct
10 Correct 13 ms 3440 KB Output is correct
11 Correct 14 ms 3412 KB Output is correct
12 Correct 13 ms 3412 KB Output is correct
13 Correct 14 ms 3412 KB Output is correct
14 Correct 16 ms 3336 KB Output is correct
15 Correct 13 ms 3576 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Correct 1 ms 2644 KB Output is correct
19 Correct 6 ms 2912 KB Output is correct
20 Correct 10 ms 3156 KB Output is correct
21 Correct 14 ms 3412 KB Output is correct
22 Correct 14 ms 3412 KB Output is correct
23 Correct 19 ms 3528 KB Output is correct
24 Correct 20 ms 3412 KB Output is correct
25 Correct 13 ms 3424 KB Output is correct
26 Correct 13 ms 3412 KB Output is correct
27 Correct 13 ms 3404 KB Output is correct
28 Correct 13 ms 3412 KB Output is correct
29 Correct 13 ms 3412 KB Output is correct
30 Correct 12 ms 3412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2704 KB Output is correct
3 Correct 3 ms 2644 KB Output is correct
4 Correct 5 ms 2716 KB Output is correct
5 Correct 9 ms 2900 KB Output is correct
6 Correct 12 ms 3628 KB Output is correct
7 Correct 12 ms 3412 KB Output is correct
8 Correct 13 ms 3412 KB Output is correct
9 Correct 12 ms 3412 KB Output is correct
10 Correct 13 ms 3440 KB Output is correct
11 Correct 14 ms 3412 KB Output is correct
12 Correct 13 ms 3412 KB Output is correct
13 Correct 14 ms 3412 KB Output is correct
14 Correct 16 ms 3336 KB Output is correct
15 Correct 13 ms 3576 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 1 ms 2644 KB Output is correct
18 Correct 1 ms 2644 KB Output is correct
19 Correct 6 ms 2912 KB Output is correct
20 Correct 10 ms 3156 KB Output is correct
21 Correct 14 ms 3412 KB Output is correct
22 Correct 14 ms 3412 KB Output is correct
23 Correct 19 ms 3528 KB Output is correct
24 Correct 20 ms 3412 KB Output is correct
25 Correct 13 ms 3424 KB Output is correct
26 Correct 13 ms 3412 KB Output is correct
27 Correct 13 ms 3404 KB Output is correct
28 Correct 13 ms 3412 KB Output is correct
29 Correct 13 ms 3412 KB Output is correct
30 Correct 12 ms 3412 KB Output is correct
31 Correct 1 ms 2644 KB Output is correct
32 Correct 1 ms 2644 KB Output is correct
33 Correct 2 ms 2812 KB Output is correct
34 Correct 1 ms 2644 KB Output is correct
35 Correct 2 ms 2644 KB Output is correct
36 Correct 2 ms 2644 KB Output is correct
37 Correct 4 ms 2644 KB Output is correct
38 Correct 4 ms 2644 KB Output is correct
39 Correct 5 ms 2900 KB Output is correct
40 Correct 11 ms 3412 KB Output is correct
41 Correct 14 ms 3908 KB Output is correct
42 Correct 13 ms 3912 KB Output is correct
43 Correct 14 ms 3924 KB Output is correct
44 Correct 14 ms 3788 KB Output is correct
45 Correct 14 ms 3924 KB Output is correct
46 Correct 15 ms 3912 KB Output is correct
47 Correct 13 ms 3912 KB Output is correct
48 Correct 13 ms 3792 KB Output is correct
49 Correct 13 ms 3924 KB Output is correct
50 Correct 13 ms 3924 KB Output is correct
51 Correct 13 ms 3924 KB Output is correct
52 Correct 13 ms 3924 KB Output is correct
53 Correct 14 ms 3908 KB Output is correct
54 Correct 13 ms 4088 KB Output is correct
55 Correct 13 ms 3788 KB Output is correct
56 Correct 13 ms 3924 KB Output is correct
57 Correct 13 ms 3924 KB Output is correct
58 Correct 14 ms 3912 KB Output is correct
59 Correct 20 ms 3936 KB Output is correct
60 Correct 13 ms 3924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2656 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 1 ms 2704 KB Output is correct
13 Correct 3 ms 2644 KB Output is correct
14 Correct 5 ms 2716 KB Output is correct
15 Correct 9 ms 2900 KB Output is correct
16 Correct 12 ms 3628 KB Output is correct
17 Correct 12 ms 3412 KB Output is correct
18 Correct 13 ms 3412 KB Output is correct
19 Correct 12 ms 3412 KB Output is correct
20 Correct 13 ms 3440 KB Output is correct
21 Correct 14 ms 3412 KB Output is correct
22 Correct 13 ms 3412 KB Output is correct
23 Correct 14 ms 3412 KB Output is correct
24 Correct 16 ms 3336 KB Output is correct
25 Correct 13 ms 3576 KB Output is correct
26 Correct 1 ms 2644 KB Output is correct
27 Correct 1 ms 2644 KB Output is correct
28 Correct 1 ms 2644 KB Output is correct
29 Correct 6 ms 2912 KB Output is correct
30 Correct 10 ms 3156 KB Output is correct
31 Correct 14 ms 3412 KB Output is correct
32 Correct 14 ms 3412 KB Output is correct
33 Correct 19 ms 3528 KB Output is correct
34 Correct 20 ms 3412 KB Output is correct
35 Correct 13 ms 3424 KB Output is correct
36 Correct 13 ms 3412 KB Output is correct
37 Correct 13 ms 3404 KB Output is correct
38 Correct 13 ms 3412 KB Output is correct
39 Correct 13 ms 3412 KB Output is correct
40 Correct 12 ms 3412 KB Output is correct
41 Correct 1 ms 2644 KB Output is correct
42 Correct 1 ms 2644 KB Output is correct
43 Correct 2 ms 2812 KB Output is correct
44 Correct 1 ms 2644 KB Output is correct
45 Correct 2 ms 2644 KB Output is correct
46 Correct 2 ms 2644 KB Output is correct
47 Correct 4 ms 2644 KB Output is correct
48 Correct 4 ms 2644 KB Output is correct
49 Correct 5 ms 2900 KB Output is correct
50 Correct 11 ms 3412 KB Output is correct
51 Correct 14 ms 3908 KB Output is correct
52 Correct 13 ms 3912 KB Output is correct
53 Correct 14 ms 3924 KB Output is correct
54 Correct 14 ms 3788 KB Output is correct
55 Correct 14 ms 3924 KB Output is correct
56 Correct 15 ms 3912 KB Output is correct
57 Correct 13 ms 3912 KB Output is correct
58 Correct 13 ms 3792 KB Output is correct
59 Correct 13 ms 3924 KB Output is correct
60 Correct 13 ms 3924 KB Output is correct
61 Correct 13 ms 3924 KB Output is correct
62 Correct 13 ms 3924 KB Output is correct
63 Correct 14 ms 3908 KB Output is correct
64 Correct 13 ms 4088 KB Output is correct
65 Correct 13 ms 3788 KB Output is correct
66 Correct 13 ms 3924 KB Output is correct
67 Correct 13 ms 3924 KB Output is correct
68 Correct 14 ms 3912 KB Output is correct
69 Correct 20 ms 3936 KB Output is correct
70 Correct 13 ms 3924 KB Output is correct
71 Correct 6 ms 2900 KB Output is correct
72 Correct 4 ms 2900 KB Output is correct
73 Correct 5 ms 2900 KB Output is correct
74 Correct 5 ms 2900 KB Output is correct
75 Correct 6 ms 2900 KB Output is correct
76 Correct 6 ms 3156 KB Output is correct
77 Correct 7 ms 3320 KB Output is correct
78 Correct 7 ms 3156 KB Output is correct
79 Correct 7 ms 3156 KB Output is correct
80 Correct 6 ms 3156 KB Output is correct
81 Correct 12 ms 3656 KB Output is correct
82 Correct 15 ms 3548 KB Output is correct
83 Correct 12 ms 3668 KB Output is correct
84 Correct 12 ms 3668 KB Output is correct
85 Correct 12 ms 3668 KB Output is correct
86 Correct 14 ms 3760 KB Output is correct
87 Correct 13 ms 3924 KB Output is correct
88 Correct 14 ms 3808 KB Output is correct
89 Correct 14 ms 3924 KB Output is correct
90 Correct 13 ms 3940 KB Output is correct
91 Correct 21 ms 5072 KB Output is correct
92 Correct 22 ms 5080 KB Output is correct
93 Correct 27 ms 5080 KB Output is correct
94 Correct 21 ms 5080 KB Output is correct
95 Correct 21 ms 5080 KB Output is correct
96 Correct 25 ms 5844 KB Output is correct
97 Correct 25 ms 5844 KB Output is correct
98 Correct 24 ms 5832 KB Output is correct
99 Correct 25 ms 5744 KB Output is correct
100 Correct 24 ms 5856 KB Output is correct
101 Correct 26 ms 5824 KB Output is correct
102 Correct 25 ms 5844 KB Output is correct
103 Correct 26 ms 6008 KB Output is correct
104 Correct 25 ms 5844 KB Output is correct
105 Correct 24 ms 5844 KB Output is correct
106 Correct 31 ms 5844 KB Output is correct
107 Correct 25 ms 5844 KB Output is correct
108 Correct 24 ms 5844 KB Output is correct
109 Correct 24 ms 5844 KB Output is correct
110 Correct 35 ms 5724 KB Output is correct
111 Correct 32 ms 5836 KB Output is correct
112 Correct 38 ms 5696 KB Output is correct
113 Correct 26 ms 5856 KB Output is correct
114 Correct 26 ms 5824 KB Output is correct
115 Correct 26 ms 5724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2656 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 1 ms 2704 KB Output is correct
13 Correct 3 ms 2644 KB Output is correct
14 Correct 5 ms 2716 KB Output is correct
15 Correct 9 ms 2900 KB Output is correct
16 Correct 12 ms 3628 KB Output is correct
17 Correct 12 ms 3412 KB Output is correct
18 Correct 13 ms 3412 KB Output is correct
19 Correct 12 ms 3412 KB Output is correct
20 Correct 13 ms 3440 KB Output is correct
21 Correct 14 ms 3412 KB Output is correct
22 Correct 13 ms 3412 KB Output is correct
23 Correct 14 ms 3412 KB Output is correct
24 Correct 16 ms 3336 KB Output is correct
25 Correct 13 ms 3576 KB Output is correct
26 Correct 1 ms 2644 KB Output is correct
27 Correct 1 ms 2644 KB Output is correct
28 Correct 1 ms 2644 KB Output is correct
29 Correct 6 ms 2912 KB Output is correct
30 Correct 10 ms 3156 KB Output is correct
31 Correct 14 ms 3412 KB Output is correct
32 Correct 14 ms 3412 KB Output is correct
33 Correct 19 ms 3528 KB Output is correct
34 Correct 20 ms 3412 KB Output is correct
35 Correct 13 ms 3424 KB Output is correct
36 Correct 13 ms 3412 KB Output is correct
37 Correct 13 ms 3404 KB Output is correct
38 Correct 13 ms 3412 KB Output is correct
39 Correct 13 ms 3412 KB Output is correct
40 Correct 12 ms 3412 KB Output is correct
41 Correct 1 ms 2644 KB Output is correct
42 Correct 1 ms 2644 KB Output is correct
43 Correct 2 ms 2812 KB Output is correct
44 Correct 1 ms 2644 KB Output is correct
45 Correct 2 ms 2644 KB Output is correct
46 Correct 2 ms 2644 KB Output is correct
47 Correct 4 ms 2644 KB Output is correct
48 Correct 4 ms 2644 KB Output is correct
49 Correct 5 ms 2900 KB Output is correct
50 Correct 11 ms 3412 KB Output is correct
51 Correct 14 ms 3908 KB Output is correct
52 Correct 13 ms 3912 KB Output is correct
53 Correct 14 ms 3924 KB Output is correct
54 Correct 14 ms 3788 KB Output is correct
55 Correct 14 ms 3924 KB Output is correct
56 Correct 15 ms 3912 KB Output is correct
57 Correct 13 ms 3912 KB Output is correct
58 Correct 13 ms 3792 KB Output is correct
59 Correct 13 ms 3924 KB Output is correct
60 Correct 13 ms 3924 KB Output is correct
61 Correct 13 ms 3924 KB Output is correct
62 Correct 13 ms 3924 KB Output is correct
63 Correct 14 ms 3908 KB Output is correct
64 Correct 13 ms 4088 KB Output is correct
65 Correct 13 ms 3788 KB Output is correct
66 Correct 13 ms 3924 KB Output is correct
67 Correct 13 ms 3924 KB Output is correct
68 Correct 14 ms 3912 KB Output is correct
69 Correct 20 ms 3936 KB Output is correct
70 Correct 13 ms 3924 KB Output is correct
71 Correct 6 ms 2900 KB Output is correct
72 Correct 4 ms 2900 KB Output is correct
73 Correct 5 ms 2900 KB Output is correct
74 Correct 5 ms 2900 KB Output is correct
75 Correct 6 ms 2900 KB Output is correct
76 Correct 6 ms 3156 KB Output is correct
77 Correct 7 ms 3320 KB Output is correct
78 Correct 7 ms 3156 KB Output is correct
79 Correct 7 ms 3156 KB Output is correct
80 Correct 6 ms 3156 KB Output is correct
81 Correct 12 ms 3656 KB Output is correct
82 Correct 15 ms 3548 KB Output is correct
83 Correct 12 ms 3668 KB Output is correct
84 Correct 12 ms 3668 KB Output is correct
85 Correct 12 ms 3668 KB Output is correct
86 Correct 14 ms 3760 KB Output is correct
87 Correct 13 ms 3924 KB Output is correct
88 Correct 14 ms 3808 KB Output is correct
89 Correct 14 ms 3924 KB Output is correct
90 Correct 13 ms 3940 KB Output is correct
91 Correct 21 ms 5072 KB Output is correct
92 Correct 22 ms 5080 KB Output is correct
93 Correct 27 ms 5080 KB Output is correct
94 Correct 21 ms 5080 KB Output is correct
95 Correct 21 ms 5080 KB Output is correct
96 Correct 25 ms 5844 KB Output is correct
97 Correct 25 ms 5844 KB Output is correct
98 Correct 24 ms 5832 KB Output is correct
99 Correct 25 ms 5744 KB Output is correct
100 Correct 24 ms 5856 KB Output is correct
101 Correct 26 ms 5824 KB Output is correct
102 Correct 25 ms 5844 KB Output is correct
103 Correct 26 ms 6008 KB Output is correct
104 Correct 25 ms 5844 KB Output is correct
105 Correct 24 ms 5844 KB Output is correct
106 Correct 31 ms 5844 KB Output is correct
107 Correct 25 ms 5844 KB Output is correct
108 Correct 24 ms 5844 KB Output is correct
109 Correct 24 ms 5844 KB Output is correct
110 Correct 35 ms 5724 KB Output is correct
111 Correct 32 ms 5836 KB Output is correct
112 Correct 38 ms 5696 KB Output is correct
113 Correct 26 ms 5856 KB Output is correct
114 Correct 26 ms 5824 KB Output is correct
115 Correct 26 ms 5724 KB Output is correct
116 Correct 6570 ms 3476 KB Output is correct
117 Correct 6569 ms 3564 KB Output is correct
118 Execution timed out 7044 ms 3756 KB Time limit exceeded
119 Halted 0 ms 0 KB -