Submission #1114535

# Submission time Handle Problem Language Result Execution time Memory
1114535 2024-11-19T07:19:40 Z vjudge1 Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 22624 KB
//Dost SEFEROĞLU
#include <bits/stdc++.h>
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<    
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
const int MOD = 1e9+7,inf = 2e18;
const int N = 2e5+50,Q = 2e5+50;
 
void solve() { 
    int n,q;
    cin >> n >> q;
    vi a(n+1);
    for (int i=1;i<=n;i++) cin >> a[i];
    while (q--) {
        int L,R;
        cin >> L >> R;
        n = R-L+1;
        map<int,int> mp;
        for (int j = L;j<=R;j++) mp[a[j]]++;
        vi ps;
        for (auto it : mp) ps.push_back(it.ss);
        sort(ps.begin(),ps.end());
        deque<int> dq;
        int coin = 0;
        while (!ps.empty()) {
            if (!coin) dq.push_front(ps.back());
            else dq.push_back(ps.back());
            coin^=1;
            ps.pop_back();
        }
        int ans = 0;
        int cur = 1;
        for (auto it : dq) {
            int r = cur+it-1;
            ans+=n*(n+1)/2-cur*(cur-1)/2-(n-r)*(n-r+1)/2;
            cur = r+1;
        }
        cout << ans << '\n';
    }
}                    
                             
signed main() { 
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef Dodi
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int t = 1;
    //cin >> t; 
    while (t --> 0) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 6 ms 1104 KB Output is correct
5 Correct 10 ms 2020 KB Output is correct
6 Correct 16 ms 2640 KB Output is correct
7 Correct 14 ms 2640 KB Output is correct
8 Correct 15 ms 2812 KB Output is correct
9 Correct 15 ms 2976 KB Output is correct
10 Correct 15 ms 2640 KB Output is correct
11 Correct 15 ms 2812 KB Output is correct
12 Correct 15 ms 2640 KB Output is correct
13 Correct 15 ms 2808 KB Output is correct
14 Correct 15 ms 2640 KB Output is correct
15 Correct 16 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 6 ms 1104 KB Output is correct
5 Correct 10 ms 2020 KB Output is correct
6 Correct 16 ms 2640 KB Output is correct
7 Correct 14 ms 2640 KB Output is correct
8 Correct 15 ms 2812 KB Output is correct
9 Correct 15 ms 2976 KB Output is correct
10 Correct 15 ms 2640 KB Output is correct
11 Correct 15 ms 2812 KB Output is correct
12 Correct 15 ms 2640 KB Output is correct
13 Correct 15 ms 2808 KB Output is correct
14 Correct 15 ms 2640 KB Output is correct
15 Correct 16 ms 2640 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 7 ms 1248 KB Output is correct
20 Correct 13 ms 2044 KB Output is correct
21 Correct 19 ms 2808 KB Output is correct
22 Correct 18 ms 2640 KB Output is correct
23 Correct 18 ms 2640 KB Output is correct
24 Correct 19 ms 2640 KB Output is correct
25 Correct 17 ms 2640 KB Output is correct
26 Correct 18 ms 2808 KB Output is correct
27 Correct 17 ms 2640 KB Output is correct
28 Correct 18 ms 2812 KB Output is correct
29 Correct 20 ms 2640 KB Output is correct
30 Correct 18 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 6 ms 1104 KB Output is correct
5 Correct 10 ms 2020 KB Output is correct
6 Correct 16 ms 2640 KB Output is correct
7 Correct 14 ms 2640 KB Output is correct
8 Correct 15 ms 2812 KB Output is correct
9 Correct 15 ms 2976 KB Output is correct
10 Correct 15 ms 2640 KB Output is correct
11 Correct 15 ms 2812 KB Output is correct
12 Correct 15 ms 2640 KB Output is correct
13 Correct 15 ms 2808 KB Output is correct
14 Correct 15 ms 2640 KB Output is correct
15 Correct 16 ms 2640 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 7 ms 1248 KB Output is correct
20 Correct 13 ms 2044 KB Output is correct
21 Correct 19 ms 2808 KB Output is correct
22 Correct 18 ms 2640 KB Output is correct
23 Correct 18 ms 2640 KB Output is correct
24 Correct 19 ms 2640 KB Output is correct
25 Correct 17 ms 2640 KB Output is correct
26 Correct 18 ms 2808 KB Output is correct
27 Correct 17 ms 2640 KB Output is correct
28 Correct 18 ms 2812 KB Output is correct
29 Correct 20 ms 2640 KB Output is correct
30 Correct 18 ms 2640 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 2 ms 592 KB Output is correct
37 Correct 5 ms 848 KB Output is correct
38 Correct 6 ms 848 KB Output is correct
39 Correct 10 ms 1104 KB Output is correct
40 Correct 19 ms 2080 KB Output is correct
41 Correct 30 ms 2640 KB Output is correct
42 Correct 27 ms 2640 KB Output is correct
43 Correct 28 ms 2896 KB Output is correct
44 Correct 32 ms 2640 KB Output is correct
45 Correct 28 ms 2640 KB Output is correct
46 Correct 27 ms 2640 KB Output is correct
47 Correct 28 ms 2640 KB Output is correct
48 Correct 27 ms 2848 KB Output is correct
49 Correct 28 ms 2640 KB Output is correct
50 Correct 28 ms 2868 KB Output is correct
51 Correct 30 ms 2640 KB Output is correct
52 Correct 27 ms 2808 KB Output is correct
53 Correct 28 ms 2640 KB Output is correct
54 Correct 27 ms 2640 KB Output is correct
55 Correct 31 ms 2856 KB Output is correct
56 Correct 33 ms 2640 KB Output is correct
57 Correct 27 ms 2812 KB Output is correct
58 Correct 27 ms 2812 KB Output is correct
59 Correct 31 ms 2808 KB Output is correct
60 Correct 29 ms 2640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 6 ms 1104 KB Output is correct
15 Correct 10 ms 2020 KB Output is correct
16 Correct 16 ms 2640 KB Output is correct
17 Correct 14 ms 2640 KB Output is correct
18 Correct 15 ms 2812 KB Output is correct
19 Correct 15 ms 2976 KB Output is correct
20 Correct 15 ms 2640 KB Output is correct
21 Correct 15 ms 2812 KB Output is correct
22 Correct 15 ms 2640 KB Output is correct
23 Correct 15 ms 2808 KB Output is correct
24 Correct 15 ms 2640 KB Output is correct
25 Correct 16 ms 2640 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 7 ms 1248 KB Output is correct
30 Correct 13 ms 2044 KB Output is correct
31 Correct 19 ms 2808 KB Output is correct
32 Correct 18 ms 2640 KB Output is correct
33 Correct 18 ms 2640 KB Output is correct
34 Correct 19 ms 2640 KB Output is correct
35 Correct 17 ms 2640 KB Output is correct
36 Correct 18 ms 2808 KB Output is correct
37 Correct 17 ms 2640 KB Output is correct
38 Correct 18 ms 2812 KB Output is correct
39 Correct 20 ms 2640 KB Output is correct
40 Correct 18 ms 2640 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 1 ms 336 KB Output is correct
45 Correct 1 ms 336 KB Output is correct
46 Correct 2 ms 592 KB Output is correct
47 Correct 5 ms 848 KB Output is correct
48 Correct 6 ms 848 KB Output is correct
49 Correct 10 ms 1104 KB Output is correct
50 Correct 19 ms 2080 KB Output is correct
51 Correct 30 ms 2640 KB Output is correct
52 Correct 27 ms 2640 KB Output is correct
53 Correct 28 ms 2896 KB Output is correct
54 Correct 32 ms 2640 KB Output is correct
55 Correct 28 ms 2640 KB Output is correct
56 Correct 27 ms 2640 KB Output is correct
57 Correct 28 ms 2640 KB Output is correct
58 Correct 27 ms 2848 KB Output is correct
59 Correct 28 ms 2640 KB Output is correct
60 Correct 28 ms 2868 KB Output is correct
61 Correct 30 ms 2640 KB Output is correct
62 Correct 27 ms 2808 KB Output is correct
63 Correct 28 ms 2640 KB Output is correct
64 Correct 27 ms 2640 KB Output is correct
65 Correct 31 ms 2856 KB Output is correct
66 Correct 33 ms 2640 KB Output is correct
67 Correct 27 ms 2812 KB Output is correct
68 Correct 27 ms 2812 KB Output is correct
69 Correct 31 ms 2808 KB Output is correct
70 Correct 29 ms 2640 KB Output is correct
71 Correct 7 ms 848 KB Output is correct
72 Correct 8 ms 848 KB Output is correct
73 Correct 7 ms 848 KB Output is correct
74 Correct 7 ms 848 KB Output is correct
75 Correct 7 ms 848 KB Output is correct
76 Correct 16 ms 1616 KB Output is correct
77 Correct 15 ms 1452 KB Output is correct
78 Correct 15 ms 1616 KB Output is correct
79 Correct 20 ms 1532 KB Output is correct
80 Correct 15 ms 1616 KB Output is correct
81 Correct 32 ms 2628 KB Output is correct
82 Correct 33 ms 2632 KB Output is correct
83 Correct 33 ms 2640 KB Output is correct
84 Correct 32 ms 2640 KB Output is correct
85 Correct 32 ms 2632 KB Output is correct
86 Correct 42 ms 3524 KB Output is correct
87 Correct 40 ms 3656 KB Output is correct
88 Correct 41 ms 3564 KB Output is correct
89 Correct 44 ms 3656 KB Output is correct
90 Correct 41 ms 3664 KB Output is correct
91 Correct 90 ms 10428 KB Output is correct
92 Correct 98 ms 10428 KB Output is correct
93 Correct 92 ms 10428 KB Output is correct
94 Correct 90 ms 10428 KB Output is correct
95 Correct 86 ms 10468 KB Output is correct
96 Correct 122 ms 18784 KB Output is correct
97 Correct 143 ms 18872 KB Output is correct
98 Correct 131 ms 18872 KB Output is correct
99 Correct 129 ms 18876 KB Output is correct
100 Correct 127 ms 18872 KB Output is correct
101 Correct 117 ms 18872 KB Output is correct
102 Correct 118 ms 18872 KB Output is correct
103 Correct 115 ms 18872 KB Output is correct
104 Correct 127 ms 18872 KB Output is correct
105 Correct 121 ms 18920 KB Output is correct
106 Correct 131 ms 22456 KB Output is correct
107 Correct 142 ms 22428 KB Output is correct
108 Correct 131 ms 22508 KB Output is correct
109 Correct 136 ms 22560 KB Output is correct
110 Correct 138 ms 22468 KB Output is correct
111 Correct 144 ms 22372 KB Output is correct
112 Correct 155 ms 22456 KB Output is correct
113 Correct 178 ms 22624 KB Output is correct
114 Correct 147 ms 22456 KB Output is correct
115 Correct 147 ms 22472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 6 ms 1104 KB Output is correct
15 Correct 10 ms 2020 KB Output is correct
16 Correct 16 ms 2640 KB Output is correct
17 Correct 14 ms 2640 KB Output is correct
18 Correct 15 ms 2812 KB Output is correct
19 Correct 15 ms 2976 KB Output is correct
20 Correct 15 ms 2640 KB Output is correct
21 Correct 15 ms 2812 KB Output is correct
22 Correct 15 ms 2640 KB Output is correct
23 Correct 15 ms 2808 KB Output is correct
24 Correct 15 ms 2640 KB Output is correct
25 Correct 16 ms 2640 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 7 ms 1248 KB Output is correct
30 Correct 13 ms 2044 KB Output is correct
31 Correct 19 ms 2808 KB Output is correct
32 Correct 18 ms 2640 KB Output is correct
33 Correct 18 ms 2640 KB Output is correct
34 Correct 19 ms 2640 KB Output is correct
35 Correct 17 ms 2640 KB Output is correct
36 Correct 18 ms 2808 KB Output is correct
37 Correct 17 ms 2640 KB Output is correct
38 Correct 18 ms 2812 KB Output is correct
39 Correct 20 ms 2640 KB Output is correct
40 Correct 18 ms 2640 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 1 ms 336 KB Output is correct
44 Correct 1 ms 336 KB Output is correct
45 Correct 1 ms 336 KB Output is correct
46 Correct 2 ms 592 KB Output is correct
47 Correct 5 ms 848 KB Output is correct
48 Correct 6 ms 848 KB Output is correct
49 Correct 10 ms 1104 KB Output is correct
50 Correct 19 ms 2080 KB Output is correct
51 Correct 30 ms 2640 KB Output is correct
52 Correct 27 ms 2640 KB Output is correct
53 Correct 28 ms 2896 KB Output is correct
54 Correct 32 ms 2640 KB Output is correct
55 Correct 28 ms 2640 KB Output is correct
56 Correct 27 ms 2640 KB Output is correct
57 Correct 28 ms 2640 KB Output is correct
58 Correct 27 ms 2848 KB Output is correct
59 Correct 28 ms 2640 KB Output is correct
60 Correct 28 ms 2868 KB Output is correct
61 Correct 30 ms 2640 KB Output is correct
62 Correct 27 ms 2808 KB Output is correct
63 Correct 28 ms 2640 KB Output is correct
64 Correct 27 ms 2640 KB Output is correct
65 Correct 31 ms 2856 KB Output is correct
66 Correct 33 ms 2640 KB Output is correct
67 Correct 27 ms 2812 KB Output is correct
68 Correct 27 ms 2812 KB Output is correct
69 Correct 31 ms 2808 KB Output is correct
70 Correct 29 ms 2640 KB Output is correct
71 Correct 7 ms 848 KB Output is correct
72 Correct 8 ms 848 KB Output is correct
73 Correct 7 ms 848 KB Output is correct
74 Correct 7 ms 848 KB Output is correct
75 Correct 7 ms 848 KB Output is correct
76 Correct 16 ms 1616 KB Output is correct
77 Correct 15 ms 1452 KB Output is correct
78 Correct 15 ms 1616 KB Output is correct
79 Correct 20 ms 1532 KB Output is correct
80 Correct 15 ms 1616 KB Output is correct
81 Correct 32 ms 2628 KB Output is correct
82 Correct 33 ms 2632 KB Output is correct
83 Correct 33 ms 2640 KB Output is correct
84 Correct 32 ms 2640 KB Output is correct
85 Correct 32 ms 2632 KB Output is correct
86 Correct 42 ms 3524 KB Output is correct
87 Correct 40 ms 3656 KB Output is correct
88 Correct 41 ms 3564 KB Output is correct
89 Correct 44 ms 3656 KB Output is correct
90 Correct 41 ms 3664 KB Output is correct
91 Correct 90 ms 10428 KB Output is correct
92 Correct 98 ms 10428 KB Output is correct
93 Correct 92 ms 10428 KB Output is correct
94 Correct 90 ms 10428 KB Output is correct
95 Correct 86 ms 10468 KB Output is correct
96 Correct 122 ms 18784 KB Output is correct
97 Correct 143 ms 18872 KB Output is correct
98 Correct 131 ms 18872 KB Output is correct
99 Correct 129 ms 18876 KB Output is correct
100 Correct 127 ms 18872 KB Output is correct
101 Correct 117 ms 18872 KB Output is correct
102 Correct 118 ms 18872 KB Output is correct
103 Correct 115 ms 18872 KB Output is correct
104 Correct 127 ms 18872 KB Output is correct
105 Correct 121 ms 18920 KB Output is correct
106 Correct 131 ms 22456 KB Output is correct
107 Correct 142 ms 22428 KB Output is correct
108 Correct 131 ms 22508 KB Output is correct
109 Correct 136 ms 22560 KB Output is correct
110 Correct 138 ms 22468 KB Output is correct
111 Correct 144 ms 22372 KB Output is correct
112 Correct 155 ms 22456 KB Output is correct
113 Correct 178 ms 22624 KB Output is correct
114 Correct 147 ms 22456 KB Output is correct
115 Correct 147 ms 22472 KB Output is correct
116 Correct 4110 ms 940 KB Output is correct
117 Correct 5502 ms 1460 KB Output is correct
118 Execution timed out 7078 ms 1472 KB Time limit exceeded
119 Halted 0 ms 0 KB -