답안 #576388

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
576388 2022-06-13T05:23:32 Z temporary_juggernaut Diversity (CEOI21_diversity) C++14
64 / 100
245 ms 20032 KB
#include<bits/stdc++.h>
#define fr first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
#define USING_ORDERED_SET 0
#if USING_ORDERED_SET
#include<bits/extc++.h>
using namespace __gnu_pbds;
template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
#endif
template<class T>void umax(T &a,T b){if(a<b)a=b;}
template<class T>void umin(T &a,T b){if(b<a)a=b;}
#ifdef juggernaut
    #define printl(args...)printf(args)
#else
    #define printl(args...)((void)0)
#endif
int a[300005];
ll tree[4*300005];
ll lazy[4*300005];
int cnt[300005];
void push(int v,int l,int r){
	if(l!=r){
		lazy[v<<1]+=lazy[v];
		lazy[v<<1|1]+=lazy[v];
	}
	tree[v]+=lazy[v]*(r-l+1);
	lazy[v]=0;
}
void update(int v,int l,int r,int ql,int qr){
	push(v,l,r);
	if(qr<l||r<ql)return;
	if(ql<=l&&r<=qr){
		lazy[v]++;
		push(v,l,r);
		return;
	}
	int mid=(l+r)>>1;
	update(v<<1,l,mid,ql,qr);
	update(v<<1|1,mid+1,r,ql,qr);
	tree[v]=tree[v<<1]+tree[v<<1|1];
}
ll get(int v,int l,int r,int ql,int qr){
	if(qr<l||r<ql)return 0ll;
	push(v,l,r);
	if(ql<=l&&r<=qr)return tree[v];
	int mid=(l+r)>>1;
	return get(v<<1,l,mid,ql,qr)+get(v<<1|1,mid+1,r,ql,qr);
}
int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	assert(q==1);
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		cnt[x]++;
	}
	vector<int>vec;
	for(int i=1;i<=300000;i++)if(cnt[i])vec.push_back(cnt[i]);
	sort(vec.begin(),vec.end());
	int idx=1;
	int ide=n;
	int val=1;
	for(int to:vec){
		if(val&1)
			while(to--)a[idx++]=val;
		else
			while(to--)a[ide--]=val;
		val++;
	}
	ll sum=0;
	for(int i=1;i<=n;i++){
		update(1,1,n,(a[i]==a[i-1]?i:1),i);
		sum+=get(1,1,n,1,i);
	}
	cout<<sum;
}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:54:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |  scanf("%d%d",&n,&q);
      |  ~~~~~^~~~~~~~~~~~~~
diversity.cpp:58:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |   scanf("%d",&x);
      |   ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 4 ms 852 KB Output is correct
4 Correct 47 ms 4748 KB Output is correct
5 Correct 96 ms 9272 KB Output is correct
6 Correct 160 ms 17824 KB Output is correct
7 Correct 203 ms 17868 KB Output is correct
8 Correct 152 ms 17864 KB Output is correct
9 Correct 175 ms 17828 KB Output is correct
10 Correct 192 ms 17828 KB Output is correct
11 Correct 154 ms 17820 KB Output is correct
12 Correct 245 ms 17864 KB Output is correct
13 Correct 174 ms 17864 KB Output is correct
14 Correct 163 ms 17872 KB Output is correct
15 Correct 155 ms 17828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 4 ms 852 KB Output is correct
4 Correct 47 ms 4748 KB Output is correct
5 Correct 96 ms 9272 KB Output is correct
6 Correct 160 ms 17824 KB Output is correct
7 Correct 203 ms 17868 KB Output is correct
8 Correct 152 ms 17864 KB Output is correct
9 Correct 175 ms 17828 KB Output is correct
10 Correct 192 ms 17828 KB Output is correct
11 Correct 154 ms 17820 KB Output is correct
12 Correct 245 ms 17864 KB Output is correct
13 Correct 174 ms 17864 KB Output is correct
14 Correct 163 ms 17872 KB Output is correct
15 Correct 155 ms 17828 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 5 ms 852 KB Output is correct
19 Correct 59 ms 4756 KB Output is correct
20 Correct 112 ms 9292 KB Output is correct
21 Correct 156 ms 17868 KB Output is correct
22 Correct 158 ms 17876 KB Output is correct
23 Correct 162 ms 17868 KB Output is correct
24 Correct 157 ms 17820 KB Output is correct
25 Correct 159 ms 17832 KB Output is correct
26 Correct 183 ms 17880 KB Output is correct
27 Correct 167 ms 17876 KB Output is correct
28 Correct 194 ms 17904 KB Output is correct
29 Correct 178 ms 17876 KB Output is correct
30 Correct 167 ms 17804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 4 ms 852 KB Output is correct
4 Correct 47 ms 4748 KB Output is correct
5 Correct 96 ms 9272 KB Output is correct
6 Correct 160 ms 17824 KB Output is correct
7 Correct 203 ms 17868 KB Output is correct
8 Correct 152 ms 17864 KB Output is correct
9 Correct 175 ms 17828 KB Output is correct
10 Correct 192 ms 17828 KB Output is correct
11 Correct 154 ms 17820 KB Output is correct
12 Correct 245 ms 17864 KB Output is correct
13 Correct 174 ms 17864 KB Output is correct
14 Correct 163 ms 17872 KB Output is correct
15 Correct 155 ms 17828 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 5 ms 852 KB Output is correct
19 Correct 59 ms 4756 KB Output is correct
20 Correct 112 ms 9292 KB Output is correct
21 Correct 156 ms 17868 KB Output is correct
22 Correct 158 ms 17876 KB Output is correct
23 Correct 162 ms 17868 KB Output is correct
24 Correct 157 ms 17820 KB Output is correct
25 Correct 159 ms 17832 KB Output is correct
26 Correct 183 ms 17880 KB Output is correct
27 Correct 167 ms 17876 KB Output is correct
28 Correct 194 ms 17904 KB Output is correct
29 Correct 178 ms 17876 KB Output is correct
30 Correct 167 ms 17804 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 6 ms 852 KB Output is correct
35 Correct 5 ms 852 KB Output is correct
36 Correct 6 ms 852 KB Output is correct
37 Correct 27 ms 2472 KB Output is correct
38 Correct 37 ms 2564 KB Output is correct
39 Correct 50 ms 4768 KB Output is correct
40 Correct 101 ms 9192 KB Output is correct
41 Correct 184 ms 17788 KB Output is correct
42 Correct 154 ms 17816 KB Output is correct
43 Correct 167 ms 17828 KB Output is correct
44 Correct 161 ms 17844 KB Output is correct
45 Correct 183 ms 17896 KB Output is correct
46 Correct 156 ms 17788 KB Output is correct
47 Correct 159 ms 17896 KB Output is correct
48 Correct 231 ms 17796 KB Output is correct
49 Correct 173 ms 17904 KB Output is correct
50 Correct 151 ms 17808 KB Output is correct
51 Correct 155 ms 17816 KB Output is correct
52 Correct 178 ms 17856 KB Output is correct
53 Correct 169 ms 17908 KB Output is correct
54 Correct 166 ms 17900 KB Output is correct
55 Correct 173 ms 17880 KB Output is correct
56 Correct 190 ms 17884 KB Output is correct
57 Correct 151 ms 17888 KB Output is correct
58 Correct 157 ms 17788 KB Output is correct
59 Correct 178 ms 17824 KB Output is correct
60 Correct 152 ms 17876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 4 ms 852 KB Output is correct
14 Correct 47 ms 4748 KB Output is correct
15 Correct 96 ms 9272 KB Output is correct
16 Correct 160 ms 17824 KB Output is correct
17 Correct 203 ms 17868 KB Output is correct
18 Correct 152 ms 17864 KB Output is correct
19 Correct 175 ms 17828 KB Output is correct
20 Correct 192 ms 17828 KB Output is correct
21 Correct 154 ms 17820 KB Output is correct
22 Correct 245 ms 17864 KB Output is correct
23 Correct 174 ms 17864 KB Output is correct
24 Correct 163 ms 17872 KB Output is correct
25 Correct 155 ms 17828 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 5 ms 852 KB Output is correct
29 Correct 59 ms 4756 KB Output is correct
30 Correct 112 ms 9292 KB Output is correct
31 Correct 156 ms 17868 KB Output is correct
32 Correct 158 ms 17876 KB Output is correct
33 Correct 162 ms 17868 KB Output is correct
34 Correct 157 ms 17820 KB Output is correct
35 Correct 159 ms 17832 KB Output is correct
36 Correct 183 ms 17880 KB Output is correct
37 Correct 167 ms 17876 KB Output is correct
38 Correct 194 ms 17904 KB Output is correct
39 Correct 178 ms 17876 KB Output is correct
40 Correct 167 ms 17804 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 6 ms 852 KB Output is correct
45 Correct 5 ms 852 KB Output is correct
46 Correct 6 ms 852 KB Output is correct
47 Correct 27 ms 2472 KB Output is correct
48 Correct 37 ms 2564 KB Output is correct
49 Correct 50 ms 4768 KB Output is correct
50 Correct 101 ms 9192 KB Output is correct
51 Correct 184 ms 17788 KB Output is correct
52 Correct 154 ms 17816 KB Output is correct
53 Correct 167 ms 17828 KB Output is correct
54 Correct 161 ms 17844 KB Output is correct
55 Correct 183 ms 17896 KB Output is correct
56 Correct 156 ms 17788 KB Output is correct
57 Correct 159 ms 17896 KB Output is correct
58 Correct 231 ms 17796 KB Output is correct
59 Correct 173 ms 17904 KB Output is correct
60 Correct 151 ms 17808 KB Output is correct
61 Correct 155 ms 17816 KB Output is correct
62 Correct 178 ms 17856 KB Output is correct
63 Correct 169 ms 17908 KB Output is correct
64 Correct 166 ms 17900 KB Output is correct
65 Correct 173 ms 17880 KB Output is correct
66 Correct 190 ms 17884 KB Output is correct
67 Correct 151 ms 17888 KB Output is correct
68 Correct 157 ms 17788 KB Output is correct
69 Correct 178 ms 17824 KB Output is correct
70 Correct 152 ms 17876 KB Output is correct
71 Correct 26 ms 2584 KB Output is correct
72 Correct 25 ms 2516 KB Output is correct
73 Correct 24 ms 2572 KB Output is correct
74 Correct 26 ms 2560 KB Output is correct
75 Correct 27 ms 2516 KB Output is correct
76 Correct 53 ms 4904 KB Output is correct
77 Correct 54 ms 4848 KB Output is correct
78 Correct 50 ms 4768 KB Output is correct
79 Correct 48 ms 4836 KB Output is correct
80 Correct 55 ms 4816 KB Output is correct
81 Correct 107 ms 9416 KB Output is correct
82 Correct 133 ms 9480 KB Output is correct
83 Correct 103 ms 9324 KB Output is correct
84 Correct 103 ms 9400 KB Output is correct
85 Correct 109 ms 9504 KB Output is correct
86 Correct 121 ms 9548 KB Output is correct
87 Correct 119 ms 9588 KB Output is correct
88 Correct 105 ms 9532 KB Output is correct
89 Correct 103 ms 9516 KB Output is correct
90 Correct 103 ms 9584 KB Output is correct
91 Correct 216 ms 18784 KB Output is correct
92 Correct 172 ms 18768 KB Output is correct
93 Correct 158 ms 18768 KB Output is correct
94 Correct 188 ms 18844 KB Output is correct
95 Correct 171 ms 18736 KB Output is correct
96 Correct 177 ms 19568 KB Output is correct
97 Correct 206 ms 19596 KB Output is correct
98 Correct 182 ms 19612 KB Output is correct
99 Correct 169 ms 19500 KB Output is correct
100 Correct 169 ms 19500 KB Output is correct
101 Correct 175 ms 19528 KB Output is correct
102 Correct 169 ms 19588 KB Output is correct
103 Correct 170 ms 19492 KB Output is correct
104 Correct 171 ms 19484 KB Output is correct
105 Correct 171 ms 19508 KB Output is correct
106 Correct 166 ms 19960 KB Output is correct
107 Correct 187 ms 19964 KB Output is correct
108 Correct 170 ms 19952 KB Output is correct
109 Correct 177 ms 19904 KB Output is correct
110 Correct 165 ms 19904 KB Output is correct
111 Correct 167 ms 19880 KB Output is correct
112 Correct 174 ms 19940 KB Output is correct
113 Correct 174 ms 19904 KB Output is correct
114 Correct 167 ms 19896 KB Output is correct
115 Correct 171 ms 20032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 4 ms 852 KB Output is correct
14 Correct 47 ms 4748 KB Output is correct
15 Correct 96 ms 9272 KB Output is correct
16 Correct 160 ms 17824 KB Output is correct
17 Correct 203 ms 17868 KB Output is correct
18 Correct 152 ms 17864 KB Output is correct
19 Correct 175 ms 17828 KB Output is correct
20 Correct 192 ms 17828 KB Output is correct
21 Correct 154 ms 17820 KB Output is correct
22 Correct 245 ms 17864 KB Output is correct
23 Correct 174 ms 17864 KB Output is correct
24 Correct 163 ms 17872 KB Output is correct
25 Correct 155 ms 17828 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 5 ms 852 KB Output is correct
29 Correct 59 ms 4756 KB Output is correct
30 Correct 112 ms 9292 KB Output is correct
31 Correct 156 ms 17868 KB Output is correct
32 Correct 158 ms 17876 KB Output is correct
33 Correct 162 ms 17868 KB Output is correct
34 Correct 157 ms 17820 KB Output is correct
35 Correct 159 ms 17832 KB Output is correct
36 Correct 183 ms 17880 KB Output is correct
37 Correct 167 ms 17876 KB Output is correct
38 Correct 194 ms 17904 KB Output is correct
39 Correct 178 ms 17876 KB Output is correct
40 Correct 167 ms 17804 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 6 ms 852 KB Output is correct
45 Correct 5 ms 852 KB Output is correct
46 Correct 6 ms 852 KB Output is correct
47 Correct 27 ms 2472 KB Output is correct
48 Correct 37 ms 2564 KB Output is correct
49 Correct 50 ms 4768 KB Output is correct
50 Correct 101 ms 9192 KB Output is correct
51 Correct 184 ms 17788 KB Output is correct
52 Correct 154 ms 17816 KB Output is correct
53 Correct 167 ms 17828 KB Output is correct
54 Correct 161 ms 17844 KB Output is correct
55 Correct 183 ms 17896 KB Output is correct
56 Correct 156 ms 17788 KB Output is correct
57 Correct 159 ms 17896 KB Output is correct
58 Correct 231 ms 17796 KB Output is correct
59 Correct 173 ms 17904 KB Output is correct
60 Correct 151 ms 17808 KB Output is correct
61 Correct 155 ms 17816 KB Output is correct
62 Correct 178 ms 17856 KB Output is correct
63 Correct 169 ms 17908 KB Output is correct
64 Correct 166 ms 17900 KB Output is correct
65 Correct 173 ms 17880 KB Output is correct
66 Correct 190 ms 17884 KB Output is correct
67 Correct 151 ms 17888 KB Output is correct
68 Correct 157 ms 17788 KB Output is correct
69 Correct 178 ms 17824 KB Output is correct
70 Correct 152 ms 17876 KB Output is correct
71 Correct 26 ms 2584 KB Output is correct
72 Correct 25 ms 2516 KB Output is correct
73 Correct 24 ms 2572 KB Output is correct
74 Correct 26 ms 2560 KB Output is correct
75 Correct 27 ms 2516 KB Output is correct
76 Correct 53 ms 4904 KB Output is correct
77 Correct 54 ms 4848 KB Output is correct
78 Correct 50 ms 4768 KB Output is correct
79 Correct 48 ms 4836 KB Output is correct
80 Correct 55 ms 4816 KB Output is correct
81 Correct 107 ms 9416 KB Output is correct
82 Correct 133 ms 9480 KB Output is correct
83 Correct 103 ms 9324 KB Output is correct
84 Correct 103 ms 9400 KB Output is correct
85 Correct 109 ms 9504 KB Output is correct
86 Correct 121 ms 9548 KB Output is correct
87 Correct 119 ms 9588 KB Output is correct
88 Correct 105 ms 9532 KB Output is correct
89 Correct 103 ms 9516 KB Output is correct
90 Correct 103 ms 9584 KB Output is correct
91 Correct 216 ms 18784 KB Output is correct
92 Correct 172 ms 18768 KB Output is correct
93 Correct 158 ms 18768 KB Output is correct
94 Correct 188 ms 18844 KB Output is correct
95 Correct 171 ms 18736 KB Output is correct
96 Correct 177 ms 19568 KB Output is correct
97 Correct 206 ms 19596 KB Output is correct
98 Correct 182 ms 19612 KB Output is correct
99 Correct 169 ms 19500 KB Output is correct
100 Correct 169 ms 19500 KB Output is correct
101 Correct 175 ms 19528 KB Output is correct
102 Correct 169 ms 19588 KB Output is correct
103 Correct 170 ms 19492 KB Output is correct
104 Correct 171 ms 19484 KB Output is correct
105 Correct 171 ms 19508 KB Output is correct
106 Correct 166 ms 19960 KB Output is correct
107 Correct 187 ms 19964 KB Output is correct
108 Correct 170 ms 19952 KB Output is correct
109 Correct 177 ms 19904 KB Output is correct
110 Correct 165 ms 19904 KB Output is correct
111 Correct 167 ms 19880 KB Output is correct
112 Correct 174 ms 19940 KB Output is correct
113 Correct 174 ms 19904 KB Output is correct
114 Correct 167 ms 19896 KB Output is correct
115 Correct 171 ms 20032 KB Output is correct
116 Runtime error 1 ms 340 KB Execution killed with signal 6
117 Halted 0 ms 0 KB -