답안 #519420

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
519420 2022-01-26T10:44:21 Z AmShZ Diversity (CEOI21_diversity) C++11
64 / 100
7000 ms 7880 KB
//khodaya khodet komak kon
# include <bits/stdc++.h>

using namespace std;

typedef long long                                        ll;
typedef long double                                      ld;
typedef pair <int, int>                                  pii;
typedef pair <pii, int>                                  ppi;
typedef pair <int, pii>                                  pip;
typedef pair <pii, pii>                                  ppp;
typedef pair <ll, ll>                                    pll;

# define A                                               first
# define B                                               second
# define endl                                            '\n'
# define sep                                             ' '
# define all(x)                                          x.begin(), x.end()
# define kill(x)                                         return cout << x << endl, 0
# define SZ(x)                                           int(x.size())
# define lc                                              id << 1
# define rc                                              id << 1 | 1
# define fast_io                                         ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);

ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));}

const int xn = 3e5 + 10;
const int xm = - 20 + 10;
const int sq = 320;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const ld eps = 1e-15;
const int mod = 998244353;
const int base = 257;

int n, q, cnt[xn], a[xn], sum[2];
ll ans;
vector <int> vec[2], V;

ll CR(int n){
	return 1ll * n * (n + 1) / 2;
}

int main(){
	fast_io;

	cin >> n >> q;
	for (int i = 1; i <= n; ++ i)
		cin >> a[i];
	while (q --){
		int l, r;
		cin >> l >> r;
		memset(cnt, 0, sizeof cnt);
		for (int i = l; i <= r; ++ i)
			++ cnt[a[i]];
		V.clear(), vec[0].clear(), vec[1].clear();
		ans = sum[0] = sum[1] = 0;
		for (int i = 0; i < xn; ++ i)
			if (cnt[i])
				V.push_back(cnt[i]);
		sort(all(V));
		for (int x : V){
			if (sum[0] < sum[1])
				vec[0].push_back(x), sum[0] += x;
			else
				vec[1].push_back(x), sum[1] += x;
		}
		reverse(all(vec[1]));
		for (int x : vec[1])
			vec[0].push_back(x);
		int res = 0;
		for (int x : vec[0]){
			ans += CR(r - l + 1) - CR(r - l + 1 - res - x) - CR(res);
			res += x;
		}
		cout << ans << endl;
	}

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1472 KB Output is correct
6 Correct 1 ms 1464 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
8 Correct 1 ms 1484 KB Output is correct
9 Correct 1 ms 1484 KB Output is correct
10 Correct 1 ms 1472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 6 ms 1996 KB Output is correct
5 Correct 10 ms 2564 KB Output is correct
6 Correct 17 ms 3276 KB Output is correct
7 Correct 18 ms 3220 KB Output is correct
8 Correct 16 ms 3224 KB Output is correct
9 Correct 16 ms 3276 KB Output is correct
10 Correct 19 ms 3276 KB Output is correct
11 Correct 17 ms 3216 KB Output is correct
12 Correct 17 ms 3276 KB Output is correct
13 Correct 18 ms 3224 KB Output is correct
14 Correct 18 ms 3276 KB Output is correct
15 Correct 17 ms 3192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 6 ms 1996 KB Output is correct
5 Correct 10 ms 2564 KB Output is correct
6 Correct 17 ms 3276 KB Output is correct
7 Correct 18 ms 3220 KB Output is correct
8 Correct 16 ms 3224 KB Output is correct
9 Correct 16 ms 3276 KB Output is correct
10 Correct 19 ms 3276 KB Output is correct
11 Correct 17 ms 3216 KB Output is correct
12 Correct 17 ms 3276 KB Output is correct
13 Correct 18 ms 3224 KB Output is correct
14 Correct 18 ms 3276 KB Output is correct
15 Correct 17 ms 3192 KB Output is correct
16 Correct 1 ms 1476 KB Output is correct
17 Correct 1 ms 1484 KB Output is correct
18 Correct 2 ms 1508 KB Output is correct
19 Correct 6 ms 2036 KB Output is correct
20 Correct 12 ms 2764 KB Output is correct
21 Correct 17 ms 3396 KB Output is correct
22 Correct 18 ms 3396 KB Output is correct
23 Correct 22 ms 3404 KB Output is correct
24 Correct 23 ms 3396 KB Output is correct
25 Correct 17 ms 3296 KB Output is correct
26 Correct 18 ms 3396 KB Output is correct
27 Correct 17 ms 3396 KB Output is correct
28 Correct 18 ms 3348 KB Output is correct
29 Correct 22 ms 3396 KB Output is correct
30 Correct 19 ms 3408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 6 ms 1996 KB Output is correct
5 Correct 10 ms 2564 KB Output is correct
6 Correct 17 ms 3276 KB Output is correct
7 Correct 18 ms 3220 KB Output is correct
8 Correct 16 ms 3224 KB Output is correct
9 Correct 16 ms 3276 KB Output is correct
10 Correct 19 ms 3276 KB Output is correct
11 Correct 17 ms 3216 KB Output is correct
12 Correct 17 ms 3276 KB Output is correct
13 Correct 18 ms 3224 KB Output is correct
14 Correct 18 ms 3276 KB Output is correct
15 Correct 17 ms 3192 KB Output is correct
16 Correct 1 ms 1476 KB Output is correct
17 Correct 1 ms 1484 KB Output is correct
18 Correct 2 ms 1508 KB Output is correct
19 Correct 6 ms 2036 KB Output is correct
20 Correct 12 ms 2764 KB Output is correct
21 Correct 17 ms 3396 KB Output is correct
22 Correct 18 ms 3396 KB Output is correct
23 Correct 22 ms 3404 KB Output is correct
24 Correct 23 ms 3396 KB Output is correct
25 Correct 17 ms 3296 KB Output is correct
26 Correct 18 ms 3396 KB Output is correct
27 Correct 17 ms 3396 KB Output is correct
28 Correct 18 ms 3348 KB Output is correct
29 Correct 22 ms 3396 KB Output is correct
30 Correct 19 ms 3408 KB Output is correct
31 Correct 1 ms 1468 KB Output is correct
32 Correct 1 ms 1484 KB Output is correct
33 Correct 1 ms 1484 KB Output is correct
34 Correct 2 ms 1480 KB Output is correct
35 Correct 2 ms 1612 KB Output is correct
36 Correct 2 ms 1484 KB Output is correct
37 Correct 4 ms 1768 KB Output is correct
38 Correct 4 ms 1864 KB Output is correct
39 Correct 8 ms 2252 KB Output is correct
40 Correct 14 ms 3020 KB Output is correct
41 Correct 26 ms 3780 KB Output is correct
42 Correct 19 ms 3748 KB Output is correct
43 Correct 19 ms 3700 KB Output is correct
44 Correct 19 ms 3780 KB Output is correct
45 Correct 19 ms 3692 KB Output is correct
46 Correct 20 ms 3780 KB Output is correct
47 Correct 24 ms 3716 KB Output is correct
48 Correct 19 ms 3724 KB Output is correct
49 Correct 22 ms 3784 KB Output is correct
50 Correct 20 ms 3764 KB Output is correct
51 Correct 21 ms 3740 KB Output is correct
52 Correct 21 ms 3744 KB Output is correct
53 Correct 21 ms 3732 KB Output is correct
54 Correct 19 ms 3740 KB Output is correct
55 Correct 19 ms 3768 KB Output is correct
56 Correct 19 ms 3784 KB Output is correct
57 Correct 19 ms 3780 KB Output is correct
58 Correct 18 ms 3808 KB Output is correct
59 Correct 19 ms 3704 KB Output is correct
60 Correct 19 ms 3776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1472 KB Output is correct
6 Correct 1 ms 1464 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
8 Correct 1 ms 1484 KB Output is correct
9 Correct 1 ms 1484 KB Output is correct
10 Correct 1 ms 1472 KB Output is correct
11 Correct 1 ms 1484 KB Output is correct
12 Correct 1 ms 1484 KB Output is correct
13 Correct 1 ms 1484 KB Output is correct
14 Correct 6 ms 1996 KB Output is correct
15 Correct 10 ms 2564 KB Output is correct
16 Correct 17 ms 3276 KB Output is correct
17 Correct 18 ms 3220 KB Output is correct
18 Correct 16 ms 3224 KB Output is correct
19 Correct 16 ms 3276 KB Output is correct
20 Correct 19 ms 3276 KB Output is correct
21 Correct 17 ms 3216 KB Output is correct
22 Correct 17 ms 3276 KB Output is correct
23 Correct 18 ms 3224 KB Output is correct
24 Correct 18 ms 3276 KB Output is correct
25 Correct 17 ms 3192 KB Output is correct
26 Correct 1 ms 1476 KB Output is correct
27 Correct 1 ms 1484 KB Output is correct
28 Correct 2 ms 1508 KB Output is correct
29 Correct 6 ms 2036 KB Output is correct
30 Correct 12 ms 2764 KB Output is correct
31 Correct 17 ms 3396 KB Output is correct
32 Correct 18 ms 3396 KB Output is correct
33 Correct 22 ms 3404 KB Output is correct
34 Correct 23 ms 3396 KB Output is correct
35 Correct 17 ms 3296 KB Output is correct
36 Correct 18 ms 3396 KB Output is correct
37 Correct 17 ms 3396 KB Output is correct
38 Correct 18 ms 3348 KB Output is correct
39 Correct 22 ms 3396 KB Output is correct
40 Correct 19 ms 3408 KB Output is correct
41 Correct 1 ms 1468 KB Output is correct
42 Correct 1 ms 1484 KB Output is correct
43 Correct 1 ms 1484 KB Output is correct
44 Correct 2 ms 1480 KB Output is correct
45 Correct 2 ms 1612 KB Output is correct
46 Correct 2 ms 1484 KB Output is correct
47 Correct 4 ms 1768 KB Output is correct
48 Correct 4 ms 1864 KB Output is correct
49 Correct 8 ms 2252 KB Output is correct
50 Correct 14 ms 3020 KB Output is correct
51 Correct 26 ms 3780 KB Output is correct
52 Correct 19 ms 3748 KB Output is correct
53 Correct 19 ms 3700 KB Output is correct
54 Correct 19 ms 3780 KB Output is correct
55 Correct 19 ms 3692 KB Output is correct
56 Correct 20 ms 3780 KB Output is correct
57 Correct 24 ms 3716 KB Output is correct
58 Correct 19 ms 3724 KB Output is correct
59 Correct 22 ms 3784 KB Output is correct
60 Correct 20 ms 3764 KB Output is correct
61 Correct 21 ms 3740 KB Output is correct
62 Correct 21 ms 3744 KB Output is correct
63 Correct 21 ms 3732 KB Output is correct
64 Correct 19 ms 3740 KB Output is correct
65 Correct 19 ms 3768 KB Output is correct
66 Correct 19 ms 3784 KB Output is correct
67 Correct 19 ms 3780 KB Output is correct
68 Correct 18 ms 3808 KB Output is correct
69 Correct 19 ms 3704 KB Output is correct
70 Correct 19 ms 3776 KB Output is correct
71 Correct 6 ms 1868 KB Output is correct
72 Correct 5 ms 1864 KB Output is correct
73 Correct 6 ms 1916 KB Output is correct
74 Correct 4 ms 1868 KB Output is correct
75 Correct 5 ms 1868 KB Output is correct
76 Correct 8 ms 2348 KB Output is correct
77 Correct 8 ms 2380 KB Output is correct
78 Correct 10 ms 2328 KB Output is correct
79 Correct 8 ms 2380 KB Output is correct
80 Correct 8 ms 2440 KB Output is correct
81 Correct 15 ms 3396 KB Output is correct
82 Correct 15 ms 3288 KB Output is correct
83 Correct 15 ms 3300 KB Output is correct
84 Correct 14 ms 3280 KB Output is correct
85 Correct 17 ms 3380 KB Output is correct
86 Correct 17 ms 3652 KB Output is correct
87 Correct 17 ms 3652 KB Output is correct
88 Correct 18 ms 3620 KB Output is correct
89 Correct 17 ms 3632 KB Output is correct
90 Correct 17 ms 3660 KB Output is correct
91 Correct 27 ms 5960 KB Output is correct
92 Correct 27 ms 5908 KB Output is correct
93 Correct 30 ms 5924 KB Output is correct
94 Correct 26 ms 5956 KB Output is correct
95 Correct 26 ms 5872 KB Output is correct
96 Correct 33 ms 7360 KB Output is correct
97 Correct 33 ms 7340 KB Output is correct
98 Correct 32 ms 7256 KB Output is correct
99 Correct 33 ms 7356 KB Output is correct
100 Correct 33 ms 7348 KB Output is correct
101 Correct 33 ms 7360 KB Output is correct
102 Correct 31 ms 7356 KB Output is correct
103 Correct 32 ms 7264 KB Output is correct
104 Correct 32 ms 7284 KB Output is correct
105 Correct 32 ms 7364 KB Output is correct
106 Correct 40 ms 7820 KB Output is correct
107 Correct 32 ms 7836 KB Output is correct
108 Correct 32 ms 7872 KB Output is correct
109 Correct 40 ms 7880 KB Output is correct
110 Correct 38 ms 7788 KB Output is correct
111 Correct 35 ms 7784 KB Output is correct
112 Correct 32 ms 7788 KB Output is correct
113 Correct 32 ms 7784 KB Output is correct
114 Correct 35 ms 7876 KB Output is correct
115 Correct 34 ms 7812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1472 KB Output is correct
6 Correct 1 ms 1464 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
8 Correct 1 ms 1484 KB Output is correct
9 Correct 1 ms 1484 KB Output is correct
10 Correct 1 ms 1472 KB Output is correct
11 Correct 1 ms 1484 KB Output is correct
12 Correct 1 ms 1484 KB Output is correct
13 Correct 1 ms 1484 KB Output is correct
14 Correct 6 ms 1996 KB Output is correct
15 Correct 10 ms 2564 KB Output is correct
16 Correct 17 ms 3276 KB Output is correct
17 Correct 18 ms 3220 KB Output is correct
18 Correct 16 ms 3224 KB Output is correct
19 Correct 16 ms 3276 KB Output is correct
20 Correct 19 ms 3276 KB Output is correct
21 Correct 17 ms 3216 KB Output is correct
22 Correct 17 ms 3276 KB Output is correct
23 Correct 18 ms 3224 KB Output is correct
24 Correct 18 ms 3276 KB Output is correct
25 Correct 17 ms 3192 KB Output is correct
26 Correct 1 ms 1476 KB Output is correct
27 Correct 1 ms 1484 KB Output is correct
28 Correct 2 ms 1508 KB Output is correct
29 Correct 6 ms 2036 KB Output is correct
30 Correct 12 ms 2764 KB Output is correct
31 Correct 17 ms 3396 KB Output is correct
32 Correct 18 ms 3396 KB Output is correct
33 Correct 22 ms 3404 KB Output is correct
34 Correct 23 ms 3396 KB Output is correct
35 Correct 17 ms 3296 KB Output is correct
36 Correct 18 ms 3396 KB Output is correct
37 Correct 17 ms 3396 KB Output is correct
38 Correct 18 ms 3348 KB Output is correct
39 Correct 22 ms 3396 KB Output is correct
40 Correct 19 ms 3408 KB Output is correct
41 Correct 1 ms 1468 KB Output is correct
42 Correct 1 ms 1484 KB Output is correct
43 Correct 1 ms 1484 KB Output is correct
44 Correct 2 ms 1480 KB Output is correct
45 Correct 2 ms 1612 KB Output is correct
46 Correct 2 ms 1484 KB Output is correct
47 Correct 4 ms 1768 KB Output is correct
48 Correct 4 ms 1864 KB Output is correct
49 Correct 8 ms 2252 KB Output is correct
50 Correct 14 ms 3020 KB Output is correct
51 Correct 26 ms 3780 KB Output is correct
52 Correct 19 ms 3748 KB Output is correct
53 Correct 19 ms 3700 KB Output is correct
54 Correct 19 ms 3780 KB Output is correct
55 Correct 19 ms 3692 KB Output is correct
56 Correct 20 ms 3780 KB Output is correct
57 Correct 24 ms 3716 KB Output is correct
58 Correct 19 ms 3724 KB Output is correct
59 Correct 22 ms 3784 KB Output is correct
60 Correct 20 ms 3764 KB Output is correct
61 Correct 21 ms 3740 KB Output is correct
62 Correct 21 ms 3744 KB Output is correct
63 Correct 21 ms 3732 KB Output is correct
64 Correct 19 ms 3740 KB Output is correct
65 Correct 19 ms 3768 KB Output is correct
66 Correct 19 ms 3784 KB Output is correct
67 Correct 19 ms 3780 KB Output is correct
68 Correct 18 ms 3808 KB Output is correct
69 Correct 19 ms 3704 KB Output is correct
70 Correct 19 ms 3776 KB Output is correct
71 Correct 6 ms 1868 KB Output is correct
72 Correct 5 ms 1864 KB Output is correct
73 Correct 6 ms 1916 KB Output is correct
74 Correct 4 ms 1868 KB Output is correct
75 Correct 5 ms 1868 KB Output is correct
76 Correct 8 ms 2348 KB Output is correct
77 Correct 8 ms 2380 KB Output is correct
78 Correct 10 ms 2328 KB Output is correct
79 Correct 8 ms 2380 KB Output is correct
80 Correct 8 ms 2440 KB Output is correct
81 Correct 15 ms 3396 KB Output is correct
82 Correct 15 ms 3288 KB Output is correct
83 Correct 15 ms 3300 KB Output is correct
84 Correct 14 ms 3280 KB Output is correct
85 Correct 17 ms 3380 KB Output is correct
86 Correct 17 ms 3652 KB Output is correct
87 Correct 17 ms 3652 KB Output is correct
88 Correct 18 ms 3620 KB Output is correct
89 Correct 17 ms 3632 KB Output is correct
90 Correct 17 ms 3660 KB Output is correct
91 Correct 27 ms 5960 KB Output is correct
92 Correct 27 ms 5908 KB Output is correct
93 Correct 30 ms 5924 KB Output is correct
94 Correct 26 ms 5956 KB Output is correct
95 Correct 26 ms 5872 KB Output is correct
96 Correct 33 ms 7360 KB Output is correct
97 Correct 33 ms 7340 KB Output is correct
98 Correct 32 ms 7256 KB Output is correct
99 Correct 33 ms 7356 KB Output is correct
100 Correct 33 ms 7348 KB Output is correct
101 Correct 33 ms 7360 KB Output is correct
102 Correct 31 ms 7356 KB Output is correct
103 Correct 32 ms 7264 KB Output is correct
104 Correct 32 ms 7284 KB Output is correct
105 Correct 32 ms 7364 KB Output is correct
106 Correct 40 ms 7820 KB Output is correct
107 Correct 32 ms 7836 KB Output is correct
108 Correct 32 ms 7872 KB Output is correct
109 Correct 40 ms 7880 KB Output is correct
110 Correct 38 ms 7788 KB Output is correct
111 Correct 35 ms 7784 KB Output is correct
112 Correct 32 ms 7788 KB Output is correct
113 Correct 32 ms 7784 KB Output is correct
114 Correct 35 ms 7876 KB Output is correct
115 Correct 34 ms 7812 KB Output is correct
116 Execution timed out 7041 ms 2392 KB Time limit exceeded
117 Halted 0 ms 0 KB -