답안 #1034015

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1034015 2024-07-25T08:47:10 Z vjudge1 Diversity (CEOI21_diversity) C++17
64 / 100
7000 ms 11048 KB
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define all(x) x.begin(), x.end()

const int N = 3e5;

int n, q, a[N];

signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  while (q--) {
    int l, r;
    cin >> l >> r;
    l--; r--;

    int sz = r-l+1;
    vector<int> vt(sz);
    for (int i = l; i <= r; i++) {
      vt[i-l] = a[i];
    }
    sort(all(vt));

    //for (int& x : vt) cerr << x << " ";
    //cerr << endl;

    vector<int> s;
    int cnt = 0;
    for (int i = 0; i < sz; i++) {
      if (i && vt[i] != vt[i-1]) {
        s.push_back(cnt);
        cnt = 1;
      }
      else cnt++;
    }
    s.push_back(cnt);

    sort(all(s));
  
    //for (int& x : s) cerr << x << " ";
    //cerr << endl;

    deque<int> dq;
    int szS = s.size();
    for (int i = 0; i < szS; i+=2) {
      dq.push_back(s[i]);
    }
    for (int i = szS - (szS % 2 ? 2 : 1); i >= 0; i-=2) {
      dq.push_back(s[i]);
    }

    //for (int& x : dq) cerr << x << " ";
    //cerr << endl;

    int ans = 0;
    int L = 1;
    while (!dq.empty()) {
      int x = dq.front() - 1; dq.pop_front();

      // sumar [L, L+x-1]
      ans += (L+x-1)*(L+x)/2 - (L-1)*(L)/2;
      L += x;

      ans += L * (sz-L+1);
      L++;
    }

    cout << ans << "\n";
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 856 KB Output is correct
4 Correct 10 ms 2396 KB Output is correct
5 Correct 19 ms 3944 KB Output is correct
6 Correct 29 ms 5724 KB Output is correct
7 Correct 30 ms 5720 KB Output is correct
8 Correct 29 ms 5772 KB Output is correct
9 Correct 32 ms 5724 KB Output is correct
10 Correct 29 ms 5724 KB Output is correct
11 Correct 30 ms 5724 KB Output is correct
12 Correct 30 ms 5724 KB Output is correct
13 Correct 31 ms 5724 KB Output is correct
14 Correct 29 ms 5724 KB Output is correct
15 Correct 34 ms 5720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 856 KB Output is correct
4 Correct 10 ms 2396 KB Output is correct
5 Correct 19 ms 3944 KB Output is correct
6 Correct 29 ms 5724 KB Output is correct
7 Correct 30 ms 5720 KB Output is correct
8 Correct 29 ms 5772 KB Output is correct
9 Correct 32 ms 5724 KB Output is correct
10 Correct 29 ms 5724 KB Output is correct
11 Correct 30 ms 5724 KB Output is correct
12 Correct 30 ms 5724 KB Output is correct
13 Correct 31 ms 5724 KB Output is correct
14 Correct 29 ms 5724 KB Output is correct
15 Correct 34 ms 5720 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 10 ms 2140 KB Output is correct
20 Correct 21 ms 4020 KB Output is correct
21 Correct 32 ms 5980 KB Output is correct
22 Correct 35 ms 5744 KB Output is correct
23 Correct 31 ms 5724 KB Output is correct
24 Correct 34 ms 5724 KB Output is correct
25 Correct 30 ms 5724 KB Output is correct
26 Correct 39 ms 5724 KB Output is correct
27 Correct 31 ms 5724 KB Output is correct
28 Correct 31 ms 5720 KB Output is correct
29 Correct 30 ms 5724 KB Output is correct
30 Correct 31 ms 5724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 856 KB Output is correct
4 Correct 10 ms 2396 KB Output is correct
5 Correct 19 ms 3944 KB Output is correct
6 Correct 29 ms 5724 KB Output is correct
7 Correct 30 ms 5720 KB Output is correct
8 Correct 29 ms 5772 KB Output is correct
9 Correct 32 ms 5724 KB Output is correct
10 Correct 29 ms 5724 KB Output is correct
11 Correct 30 ms 5724 KB Output is correct
12 Correct 30 ms 5724 KB Output is correct
13 Correct 31 ms 5724 KB Output is correct
14 Correct 29 ms 5724 KB Output is correct
15 Correct 34 ms 5720 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 604 KB Output is correct
19 Correct 10 ms 2140 KB Output is correct
20 Correct 21 ms 4020 KB Output is correct
21 Correct 32 ms 5980 KB Output is correct
22 Correct 35 ms 5744 KB Output is correct
23 Correct 31 ms 5724 KB Output is correct
24 Correct 34 ms 5724 KB Output is correct
25 Correct 30 ms 5724 KB Output is correct
26 Correct 39 ms 5724 KB Output is correct
27 Correct 31 ms 5724 KB Output is correct
28 Correct 31 ms 5720 KB Output is correct
29 Correct 30 ms 5724 KB Output is correct
30 Correct 31 ms 5724 KB Output is correct
31 Correct 0 ms 604 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 472 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 644 KB Output is correct
37 Correct 6 ms 1368 KB Output is correct
38 Correct 8 ms 1372 KB Output is correct
39 Correct 11 ms 2428 KB Output is correct
40 Correct 23 ms 4372 KB Output is correct
41 Correct 34 ms 6232 KB Output is correct
42 Correct 35 ms 6236 KB Output is correct
43 Correct 34 ms 6252 KB Output is correct
44 Correct 33 ms 6232 KB Output is correct
45 Correct 35 ms 6224 KB Output is correct
46 Correct 33 ms 6312 KB Output is correct
47 Correct 34 ms 6232 KB Output is correct
48 Correct 33 ms 6236 KB Output is correct
49 Correct 34 ms 6304 KB Output is correct
50 Correct 35 ms 6236 KB Output is correct
51 Correct 34 ms 6232 KB Output is correct
52 Correct 43 ms 6236 KB Output is correct
53 Correct 34 ms 6236 KB Output is correct
54 Correct 34 ms 6304 KB Output is correct
55 Correct 34 ms 6300 KB Output is correct
56 Correct 34 ms 6236 KB Output is correct
57 Correct 41 ms 6296 KB Output is correct
58 Correct 34 ms 6308 KB Output is correct
59 Correct 37 ms 6312 KB Output is correct
60 Correct 34 ms 6300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 856 KB Output is correct
14 Correct 10 ms 2396 KB Output is correct
15 Correct 19 ms 3944 KB Output is correct
16 Correct 29 ms 5724 KB Output is correct
17 Correct 30 ms 5720 KB Output is correct
18 Correct 29 ms 5772 KB Output is correct
19 Correct 32 ms 5724 KB Output is correct
20 Correct 29 ms 5724 KB Output is correct
21 Correct 30 ms 5724 KB Output is correct
22 Correct 30 ms 5724 KB Output is correct
23 Correct 31 ms 5724 KB Output is correct
24 Correct 29 ms 5724 KB Output is correct
25 Correct 34 ms 5720 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 10 ms 2140 KB Output is correct
30 Correct 21 ms 4020 KB Output is correct
31 Correct 32 ms 5980 KB Output is correct
32 Correct 35 ms 5744 KB Output is correct
33 Correct 31 ms 5724 KB Output is correct
34 Correct 34 ms 5724 KB Output is correct
35 Correct 30 ms 5724 KB Output is correct
36 Correct 39 ms 5724 KB Output is correct
37 Correct 31 ms 5724 KB Output is correct
38 Correct 31 ms 5720 KB Output is correct
39 Correct 30 ms 5724 KB Output is correct
40 Correct 31 ms 5724 KB Output is correct
41 Correct 0 ms 604 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 472 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 1 ms 644 KB Output is correct
47 Correct 6 ms 1368 KB Output is correct
48 Correct 8 ms 1372 KB Output is correct
49 Correct 11 ms 2428 KB Output is correct
50 Correct 23 ms 4372 KB Output is correct
51 Correct 34 ms 6232 KB Output is correct
52 Correct 35 ms 6236 KB Output is correct
53 Correct 34 ms 6252 KB Output is correct
54 Correct 33 ms 6232 KB Output is correct
55 Correct 35 ms 6224 KB Output is correct
56 Correct 33 ms 6312 KB Output is correct
57 Correct 34 ms 6232 KB Output is correct
58 Correct 33 ms 6236 KB Output is correct
59 Correct 34 ms 6304 KB Output is correct
60 Correct 35 ms 6236 KB Output is correct
61 Correct 34 ms 6232 KB Output is correct
62 Correct 43 ms 6236 KB Output is correct
63 Correct 34 ms 6236 KB Output is correct
64 Correct 34 ms 6304 KB Output is correct
65 Correct 34 ms 6300 KB Output is correct
66 Correct 34 ms 6236 KB Output is correct
67 Correct 41 ms 6296 KB Output is correct
68 Correct 34 ms 6308 KB Output is correct
69 Correct 37 ms 6312 KB Output is correct
70 Correct 34 ms 6300 KB Output is correct
71 Correct 6 ms 1368 KB Output is correct
72 Correct 7 ms 1372 KB Output is correct
73 Correct 6 ms 1400 KB Output is correct
74 Correct 6 ms 1372 KB Output is correct
75 Correct 6 ms 1372 KB Output is correct
76 Correct 12 ms 2512 KB Output is correct
77 Correct 15 ms 2396 KB Output is correct
78 Correct 13 ms 2392 KB Output is correct
79 Correct 13 ms 2772 KB Output is correct
80 Correct 13 ms 2392 KB Output is correct
81 Correct 26 ms 4692 KB Output is correct
82 Correct 25 ms 4692 KB Output is correct
83 Correct 26 ms 4688 KB Output is correct
84 Correct 26 ms 4688 KB Output is correct
85 Correct 25 ms 4688 KB Output is correct
86 Correct 29 ms 4908 KB Output is correct
87 Correct 28 ms 4948 KB Output is correct
88 Correct 29 ms 4948 KB Output is correct
89 Correct 28 ms 4948 KB Output is correct
90 Correct 27 ms 4956 KB Output is correct
91 Correct 49 ms 8288 KB Output is correct
92 Correct 48 ms 8400 KB Output is correct
93 Correct 49 ms 8408 KB Output is correct
94 Correct 50 ms 8312 KB Output is correct
95 Correct 47 ms 8396 KB Output is correct
96 Correct 57 ms 10184 KB Output is correct
97 Correct 57 ms 10044 KB Output is correct
98 Correct 57 ms 10200 KB Output is correct
99 Correct 56 ms 10012 KB Output is correct
100 Correct 57 ms 10184 KB Output is correct
101 Correct 56 ms 10188 KB Output is correct
102 Correct 56 ms 10020 KB Output is correct
103 Correct 58 ms 10188 KB Output is correct
104 Correct 62 ms 10184 KB Output is correct
105 Correct 58 ms 10184 KB Output is correct
106 Correct 61 ms 10872 KB Output is correct
107 Correct 60 ms 11048 KB Output is correct
108 Correct 60 ms 10956 KB Output is correct
109 Correct 60 ms 10864 KB Output is correct
110 Correct 58 ms 10964 KB Output is correct
111 Correct 66 ms 11028 KB Output is correct
112 Correct 58 ms 10952 KB Output is correct
113 Correct 56 ms 10924 KB Output is correct
114 Correct 58 ms 11024 KB Output is correct
115 Correct 59 ms 10956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 856 KB Output is correct
14 Correct 10 ms 2396 KB Output is correct
15 Correct 19 ms 3944 KB Output is correct
16 Correct 29 ms 5724 KB Output is correct
17 Correct 30 ms 5720 KB Output is correct
18 Correct 29 ms 5772 KB Output is correct
19 Correct 32 ms 5724 KB Output is correct
20 Correct 29 ms 5724 KB Output is correct
21 Correct 30 ms 5724 KB Output is correct
22 Correct 30 ms 5724 KB Output is correct
23 Correct 31 ms 5724 KB Output is correct
24 Correct 29 ms 5724 KB Output is correct
25 Correct 34 ms 5720 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 10 ms 2140 KB Output is correct
30 Correct 21 ms 4020 KB Output is correct
31 Correct 32 ms 5980 KB Output is correct
32 Correct 35 ms 5744 KB Output is correct
33 Correct 31 ms 5724 KB Output is correct
34 Correct 34 ms 5724 KB Output is correct
35 Correct 30 ms 5724 KB Output is correct
36 Correct 39 ms 5724 KB Output is correct
37 Correct 31 ms 5724 KB Output is correct
38 Correct 31 ms 5720 KB Output is correct
39 Correct 30 ms 5724 KB Output is correct
40 Correct 31 ms 5724 KB Output is correct
41 Correct 0 ms 604 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 472 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 1 ms 644 KB Output is correct
47 Correct 6 ms 1368 KB Output is correct
48 Correct 8 ms 1372 KB Output is correct
49 Correct 11 ms 2428 KB Output is correct
50 Correct 23 ms 4372 KB Output is correct
51 Correct 34 ms 6232 KB Output is correct
52 Correct 35 ms 6236 KB Output is correct
53 Correct 34 ms 6252 KB Output is correct
54 Correct 33 ms 6232 KB Output is correct
55 Correct 35 ms 6224 KB Output is correct
56 Correct 33 ms 6312 KB Output is correct
57 Correct 34 ms 6232 KB Output is correct
58 Correct 33 ms 6236 KB Output is correct
59 Correct 34 ms 6304 KB Output is correct
60 Correct 35 ms 6236 KB Output is correct
61 Correct 34 ms 6232 KB Output is correct
62 Correct 43 ms 6236 KB Output is correct
63 Correct 34 ms 6236 KB Output is correct
64 Correct 34 ms 6304 KB Output is correct
65 Correct 34 ms 6300 KB Output is correct
66 Correct 34 ms 6236 KB Output is correct
67 Correct 41 ms 6296 KB Output is correct
68 Correct 34 ms 6308 KB Output is correct
69 Correct 37 ms 6312 KB Output is correct
70 Correct 34 ms 6300 KB Output is correct
71 Correct 6 ms 1368 KB Output is correct
72 Correct 7 ms 1372 KB Output is correct
73 Correct 6 ms 1400 KB Output is correct
74 Correct 6 ms 1372 KB Output is correct
75 Correct 6 ms 1372 KB Output is correct
76 Correct 12 ms 2512 KB Output is correct
77 Correct 15 ms 2396 KB Output is correct
78 Correct 13 ms 2392 KB Output is correct
79 Correct 13 ms 2772 KB Output is correct
80 Correct 13 ms 2392 KB Output is correct
81 Correct 26 ms 4692 KB Output is correct
82 Correct 25 ms 4692 KB Output is correct
83 Correct 26 ms 4688 KB Output is correct
84 Correct 26 ms 4688 KB Output is correct
85 Correct 25 ms 4688 KB Output is correct
86 Correct 29 ms 4908 KB Output is correct
87 Correct 28 ms 4948 KB Output is correct
88 Correct 29 ms 4948 KB Output is correct
89 Correct 28 ms 4948 KB Output is correct
90 Correct 27 ms 4956 KB Output is correct
91 Correct 49 ms 8288 KB Output is correct
92 Correct 48 ms 8400 KB Output is correct
93 Correct 49 ms 8408 KB Output is correct
94 Correct 50 ms 8312 KB Output is correct
95 Correct 47 ms 8396 KB Output is correct
96 Correct 57 ms 10184 KB Output is correct
97 Correct 57 ms 10044 KB Output is correct
98 Correct 57 ms 10200 KB Output is correct
99 Correct 56 ms 10012 KB Output is correct
100 Correct 57 ms 10184 KB Output is correct
101 Correct 56 ms 10188 KB Output is correct
102 Correct 56 ms 10020 KB Output is correct
103 Correct 58 ms 10188 KB Output is correct
104 Correct 62 ms 10184 KB Output is correct
105 Correct 58 ms 10184 KB Output is correct
106 Correct 61 ms 10872 KB Output is correct
107 Correct 60 ms 11048 KB Output is correct
108 Correct 60 ms 10956 KB Output is correct
109 Correct 60 ms 10864 KB Output is correct
110 Correct 58 ms 10964 KB Output is correct
111 Correct 66 ms 11028 KB Output is correct
112 Correct 58 ms 10952 KB Output is correct
113 Correct 56 ms 10924 KB Output is correct
114 Correct 58 ms 11024 KB Output is correct
115 Correct 59 ms 10956 KB Output is correct
116 Correct 6721 ms 1396 KB Output is correct
117 Execution timed out 7036 ms 1364 KB Time limit exceeded
118 Halted 0 ms 0 KB -