제출 #474669

#제출 시각아이디문제언어결과실행 시간메모리
474669MilosMilutinovicDiversity (CEOI21_diversity)C++14
64 / 100
67 ms9064 KiB
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 500; int A[N], n, q, cnt[N], B[N], ans[N]; long long sum[N]; int main(){ scanf("%d%d", &n, &q); for(int i = 1;i <= n;i++){ scanf("%d", A + i); cnt[A[i]]++; } for(int i = 1;i <= q;i++){ int l, r; scanf("%d%d", &l, &r); } iota(B, B + N, 0); sort(B, B + N, [&](int i, int j){ return cnt[i] < cnt[j]; }); int l = 1, r = n; for(int i = 1;i <= N;i++){ for(int j = 1;j <= cnt[B[i]];j++){ if(i & 1) ans[l++] = B[i]; else ans[r--] = B[i]; } } int diff = 0; sum[n + 1] = 0; for(int i = n;i >= 1;i--){ sum[i] = sum[i + 1] + 1; if(i == n || ans[i] != ans[i + 1]) sum[i] += (n - i); } long long total = 0; for(int i = 1;i <= n;i++){ total += sum[i]; } printf("%lld", total); return 0; } /* */

컴파일 시 표준 에러 (stderr) 메시지

diversity.cpp: In function 'int main()':
diversity.cpp:30:13: warning: unused variable 'diff' [-Wunused-variable]
   30 |         int diff = 0;
      |             ^~~~
diversity.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         scanf("%d%d", &n, &q);
      |         ~~~~~^~~~~~~~~~~~~~~~
diversity.cpp:13:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |                 scanf("%d", A + i);
      |                 ~~~~~^~~~~~~~~~~~~
diversity.cpp:17:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |                 int l, r; scanf("%d%d", &l, &r);
      |                           ~~~~~^~~~~~~~~~~~~~~~
diversity.cpp:25:43: warning: iteration 300499 invokes undefined behavior [-Waggressive-loop-optimizations]
   25 |                 for(int j = 1;j <= cnt[B[i]];j++){
      |                                        ~~~^
diversity.cpp:24:25: note: within this loop
   24 |         for(int i = 1;i <= N;i++){
      |                       ~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...