Submission #1052866

# Submission time Handle Problem Language Result Execution time Memory
1052866 2024-08-11T05:04:25 Z kunzaZa183 Diversity (CEOI21_diversity) C++17
64 / 100
77 ms 30556 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  cin.tie(0)->ios::sync_with_stdio(0);
  cin.exceptions(cin.failbit);
  int n, q;
  cin >> n >> q;

  const int maxn = 300005, maxk = 1000;

  int block = sqrt(n) + 3;

  int arr[maxn];
  for (int i = 0; i < n; i++) cin >> arr[i];

  pair<int, int> pii[maxn];
  for (int i = 0; i < q; i++) {
    cin >> pii[i].first >> pii[i].second;
  }

  sort(pii, pii + n, [&](pair<int, int> a, pair<int, int> b) {
    if (a.first / block != b.first / block) return a.first < b.first;
    return a.second > b.second;
  });

  struct fenwick {
    int arr[2 * maxn + 1] = {};

    int sum(int r) {
      int ret = 0;
      for (r++; r > 0; r -= r & (-r)) ret += arr[r];
      return ret;
    }

    void add(int in, int val) {
      for (in++; in <= 2 * maxn; in += in & (-in)) {
        arr[in] += val;
      }
    }
  } ok, rev, normal;

  pair<int, int> status[maxn + 1];  // bef, cur
  status[0] = {0, n};
  for (int i = 1; i <= maxn; i++) status[i] = {n, n};

  int at[maxn] = {};

  int curans = 0;
  auto add = [&](int in) {
    int tmp = status[at[arr[in]]].second - 1;
    curans -= (at[arr[in]] + 1) * at[arr[in]] / 2;
    curans += (at[arr[in]] + 2) * (at[arr[in]] + 1) / 2;

    int coord;
    if (tmp % 2 == 1) {
      coord = maxn + 1 + (n - tmp  - 1) / 2;
    } else if (tmp % 2 == 0) {
      coord = maxn - (n - tmp - 1) / 2;
    }

    normal.add(coord, 1);
    ok.add(coord, coord);
    rev.add(coord, 2 * maxn - coord);

    curans += ok.sum(2 * maxn - 1) - ok.sum(coord) -
              (coord - 1) * (normal.sum(2 * maxn - 1) - normal.sum(coord));
    curans += rev.sum(coord - 1) - rev.sum(0) -
              (2 * maxn - coord - 1) * (normal.sum(coord - 1) - normal.sum(0));

    status[at[arr[in]]].second--;
    at[arr[in]]++;

    status[at[arr[in]]].first--;
  };

  for (int i = 0; i < n; i++) {
    add(i);
  }

  cout << curans << "\n";
}

Compilation message

diversity.cpp: In function 'int main()':
diversity.cpp:10:28: warning: unused variable 'maxk' [-Wunused-variable]
   10 |   const int maxn = 300005, maxk = 1000;
      |                            ^~~~
diversity.cpp:69:33: warning: 'coord' may be used uninitialized in this function [-Wmaybe-uninitialized]
   69 |               (2 * maxn - coord - 1) * (normal.sum(coord - 1) - normal.sum(0));
      |               ~~~~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 28508 KB Output is correct
2 Correct 14 ms 28380 KB Output is correct
3 Correct 13 ms 28508 KB Output is correct
4 Correct 13 ms 28508 KB Output is correct
5 Correct 12 ms 28504 KB Output is correct
6 Correct 11 ms 28520 KB Output is correct
7 Correct 12 ms 28476 KB Output is correct
8 Correct 12 ms 28412 KB Output is correct
9 Correct 13 ms 28508 KB Output is correct
10 Correct 12 ms 28508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 28508 KB Output is correct
2 Correct 12 ms 28508 KB Output is correct
3 Correct 14 ms 28424 KB Output is correct
4 Correct 27 ms 28552 KB Output is correct
5 Correct 43 ms 29020 KB Output is correct
6 Correct 61 ms 29128 KB Output is correct
7 Correct 60 ms 29016 KB Output is correct
8 Correct 58 ms 29020 KB Output is correct
9 Correct 59 ms 29236 KB Output is correct
10 Correct 58 ms 29276 KB Output is correct
11 Correct 61 ms 29272 KB Output is correct
12 Correct 60 ms 29280 KB Output is correct
13 Correct 63 ms 29276 KB Output is correct
14 Correct 66 ms 29020 KB Output is correct
15 Correct 61 ms 29124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 28508 KB Output is correct
2 Correct 12 ms 28508 KB Output is correct
3 Correct 14 ms 28424 KB Output is correct
4 Correct 27 ms 28552 KB Output is correct
5 Correct 43 ms 29020 KB Output is correct
6 Correct 61 ms 29128 KB Output is correct
7 Correct 60 ms 29016 KB Output is correct
8 Correct 58 ms 29020 KB Output is correct
9 Correct 59 ms 29236 KB Output is correct
10 Correct 58 ms 29276 KB Output is correct
11 Correct 61 ms 29272 KB Output is correct
12 Correct 60 ms 29280 KB Output is correct
13 Correct 63 ms 29276 KB Output is correct
14 Correct 66 ms 29020 KB Output is correct
15 Correct 61 ms 29124 KB Output is correct
16 Correct 12 ms 28508 KB Output is correct
17 Correct 12 ms 28628 KB Output is correct
18 Correct 13 ms 28564 KB Output is correct
19 Correct 27 ms 28908 KB Output is correct
20 Correct 44 ms 29020 KB Output is correct
21 Correct 56 ms 29524 KB Output is correct
22 Correct 61 ms 29392 KB Output is correct
23 Correct 58 ms 29272 KB Output is correct
24 Correct 66 ms 29276 KB Output is correct
25 Correct 62 ms 29284 KB Output is correct
26 Correct 60 ms 29276 KB Output is correct
27 Correct 59 ms 29272 KB Output is correct
28 Correct 59 ms 29272 KB Output is correct
29 Correct 63 ms 29264 KB Output is correct
30 Correct 59 ms 29276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 28508 KB Output is correct
2 Correct 12 ms 28508 KB Output is correct
3 Correct 14 ms 28424 KB Output is correct
4 Correct 27 ms 28552 KB Output is correct
5 Correct 43 ms 29020 KB Output is correct
6 Correct 61 ms 29128 KB Output is correct
7 Correct 60 ms 29016 KB Output is correct
8 Correct 58 ms 29020 KB Output is correct
9 Correct 59 ms 29236 KB Output is correct
10 Correct 58 ms 29276 KB Output is correct
11 Correct 61 ms 29272 KB Output is correct
12 Correct 60 ms 29280 KB Output is correct
13 Correct 63 ms 29276 KB Output is correct
14 Correct 66 ms 29020 KB Output is correct
15 Correct 61 ms 29124 KB Output is correct
16 Correct 12 ms 28508 KB Output is correct
17 Correct 12 ms 28628 KB Output is correct
18 Correct 13 ms 28564 KB Output is correct
19 Correct 27 ms 28908 KB Output is correct
20 Correct 44 ms 29020 KB Output is correct
21 Correct 56 ms 29524 KB Output is correct
22 Correct 61 ms 29392 KB Output is correct
23 Correct 58 ms 29272 KB Output is correct
24 Correct 66 ms 29276 KB Output is correct
25 Correct 62 ms 29284 KB Output is correct
26 Correct 60 ms 29276 KB Output is correct
27 Correct 59 ms 29272 KB Output is correct
28 Correct 59 ms 29272 KB Output is correct
29 Correct 63 ms 29264 KB Output is correct
30 Correct 59 ms 29276 KB Output is correct
31 Correct 12 ms 28508 KB Output is correct
32 Correct 13 ms 28628 KB Output is correct
33 Correct 12 ms 28508 KB Output is correct
34 Correct 14 ms 28508 KB Output is correct
35 Correct 13 ms 28664 KB Output is correct
36 Correct 14 ms 28508 KB Output is correct
37 Correct 20 ms 28820 KB Output is correct
38 Correct 19 ms 28760 KB Output is correct
39 Correct 29 ms 28760 KB Output is correct
40 Correct 46 ms 29264 KB Output is correct
41 Correct 65 ms 29528 KB Output is correct
42 Correct 64 ms 29528 KB Output is correct
43 Correct 61 ms 29520 KB Output is correct
44 Correct 61 ms 29760 KB Output is correct
45 Correct 61 ms 29532 KB Output is correct
46 Correct 62 ms 29528 KB Output is correct
47 Correct 62 ms 29532 KB Output is correct
48 Correct 61 ms 29628 KB Output is correct
49 Correct 61 ms 29528 KB Output is correct
50 Correct 62 ms 29532 KB Output is correct
51 Correct 65 ms 29756 KB Output is correct
52 Correct 65 ms 29748 KB Output is correct
53 Correct 61 ms 29532 KB Output is correct
54 Correct 63 ms 29756 KB Output is correct
55 Correct 62 ms 29532 KB Output is correct
56 Correct 63 ms 29532 KB Output is correct
57 Correct 71 ms 29788 KB Output is correct
58 Correct 60 ms 29748 KB Output is correct
59 Correct 60 ms 29520 KB Output is correct
60 Correct 61 ms 29532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 28508 KB Output is correct
2 Correct 14 ms 28380 KB Output is correct
3 Correct 13 ms 28508 KB Output is correct
4 Correct 13 ms 28508 KB Output is correct
5 Correct 12 ms 28504 KB Output is correct
6 Correct 11 ms 28520 KB Output is correct
7 Correct 12 ms 28476 KB Output is correct
8 Correct 12 ms 28412 KB Output is correct
9 Correct 13 ms 28508 KB Output is correct
10 Correct 12 ms 28508 KB Output is correct
11 Correct 12 ms 28508 KB Output is correct
12 Correct 12 ms 28508 KB Output is correct
13 Correct 14 ms 28424 KB Output is correct
14 Correct 27 ms 28552 KB Output is correct
15 Correct 43 ms 29020 KB Output is correct
16 Correct 61 ms 29128 KB Output is correct
17 Correct 60 ms 29016 KB Output is correct
18 Correct 58 ms 29020 KB Output is correct
19 Correct 59 ms 29236 KB Output is correct
20 Correct 58 ms 29276 KB Output is correct
21 Correct 61 ms 29272 KB Output is correct
22 Correct 60 ms 29280 KB Output is correct
23 Correct 63 ms 29276 KB Output is correct
24 Correct 66 ms 29020 KB Output is correct
25 Correct 61 ms 29124 KB Output is correct
26 Correct 12 ms 28508 KB Output is correct
27 Correct 12 ms 28628 KB Output is correct
28 Correct 13 ms 28564 KB Output is correct
29 Correct 27 ms 28908 KB Output is correct
30 Correct 44 ms 29020 KB Output is correct
31 Correct 56 ms 29524 KB Output is correct
32 Correct 61 ms 29392 KB Output is correct
33 Correct 58 ms 29272 KB Output is correct
34 Correct 66 ms 29276 KB Output is correct
35 Correct 62 ms 29284 KB Output is correct
36 Correct 60 ms 29276 KB Output is correct
37 Correct 59 ms 29272 KB Output is correct
38 Correct 59 ms 29272 KB Output is correct
39 Correct 63 ms 29264 KB Output is correct
40 Correct 59 ms 29276 KB Output is correct
41 Correct 12 ms 28508 KB Output is correct
42 Correct 13 ms 28628 KB Output is correct
43 Correct 12 ms 28508 KB Output is correct
44 Correct 14 ms 28508 KB Output is correct
45 Correct 13 ms 28664 KB Output is correct
46 Correct 14 ms 28508 KB Output is correct
47 Correct 20 ms 28820 KB Output is correct
48 Correct 19 ms 28760 KB Output is correct
49 Correct 29 ms 28760 KB Output is correct
50 Correct 46 ms 29264 KB Output is correct
51 Correct 65 ms 29528 KB Output is correct
52 Correct 64 ms 29528 KB Output is correct
53 Correct 61 ms 29520 KB Output is correct
54 Correct 61 ms 29760 KB Output is correct
55 Correct 61 ms 29532 KB Output is correct
56 Correct 62 ms 29528 KB Output is correct
57 Correct 62 ms 29532 KB Output is correct
58 Correct 61 ms 29628 KB Output is correct
59 Correct 61 ms 29528 KB Output is correct
60 Correct 62 ms 29532 KB Output is correct
61 Correct 65 ms 29756 KB Output is correct
62 Correct 65 ms 29748 KB Output is correct
63 Correct 61 ms 29532 KB Output is correct
64 Correct 63 ms 29756 KB Output is correct
65 Correct 62 ms 29532 KB Output is correct
66 Correct 63 ms 29532 KB Output is correct
67 Correct 71 ms 29788 KB Output is correct
68 Correct 60 ms 29748 KB Output is correct
69 Correct 60 ms 29520 KB Output is correct
70 Correct 61 ms 29532 KB Output is correct
71 Correct 20 ms 28764 KB Output is correct
72 Correct 20 ms 28764 KB Output is correct
73 Correct 23 ms 28764 KB Output is correct
74 Correct 23 ms 28860 KB Output is correct
75 Correct 21 ms 28764 KB Output is correct
76 Correct 29 ms 29016 KB Output is correct
77 Correct 29 ms 29020 KB Output is correct
78 Correct 29 ms 28980 KB Output is correct
79 Correct 29 ms 29016 KB Output is correct
80 Correct 28 ms 29020 KB Output is correct
81 Correct 47 ms 29532 KB Output is correct
82 Correct 47 ms 29532 KB Output is correct
83 Correct 55 ms 29352 KB Output is correct
84 Correct 48 ms 29532 KB Output is correct
85 Correct 46 ms 29508 KB Output is correct
86 Correct 48 ms 29528 KB Output is correct
87 Correct 48 ms 29532 KB Output is correct
88 Correct 48 ms 29640 KB Output is correct
89 Correct 48 ms 29508 KB Output is correct
90 Correct 47 ms 29528 KB Output is correct
91 Correct 76 ms 30292 KB Output is correct
92 Correct 77 ms 30300 KB Output is correct
93 Correct 66 ms 30340 KB Output is correct
94 Correct 67 ms 30292 KB Output is correct
95 Correct 68 ms 30292 KB Output is correct
96 Correct 72 ms 30292 KB Output is correct
97 Correct 68 ms 30300 KB Output is correct
98 Correct 68 ms 30408 KB Output is correct
99 Correct 70 ms 30292 KB Output is correct
100 Correct 71 ms 30496 KB Output is correct
101 Correct 68 ms 30292 KB Output is correct
102 Correct 70 ms 30300 KB Output is correct
103 Correct 67 ms 30292 KB Output is correct
104 Correct 69 ms 30256 KB Output is correct
105 Correct 66 ms 30496 KB Output is correct
106 Correct 68 ms 30532 KB Output is correct
107 Correct 70 ms 30556 KB Output is correct
108 Correct 74 ms 30292 KB Output is correct
109 Correct 68 ms 30300 KB Output is correct
110 Correct 67 ms 30532 KB Output is correct
111 Correct 68 ms 30544 KB Output is correct
112 Correct 69 ms 30292 KB Output is correct
113 Correct 66 ms 30556 KB Output is correct
114 Correct 68 ms 30532 KB Output is correct
115 Correct 67 ms 30292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 28508 KB Output is correct
2 Correct 14 ms 28380 KB Output is correct
3 Correct 13 ms 28508 KB Output is correct
4 Correct 13 ms 28508 KB Output is correct
5 Correct 12 ms 28504 KB Output is correct
6 Correct 11 ms 28520 KB Output is correct
7 Correct 12 ms 28476 KB Output is correct
8 Correct 12 ms 28412 KB Output is correct
9 Correct 13 ms 28508 KB Output is correct
10 Correct 12 ms 28508 KB Output is correct
11 Correct 12 ms 28508 KB Output is correct
12 Correct 12 ms 28508 KB Output is correct
13 Correct 14 ms 28424 KB Output is correct
14 Correct 27 ms 28552 KB Output is correct
15 Correct 43 ms 29020 KB Output is correct
16 Correct 61 ms 29128 KB Output is correct
17 Correct 60 ms 29016 KB Output is correct
18 Correct 58 ms 29020 KB Output is correct
19 Correct 59 ms 29236 KB Output is correct
20 Correct 58 ms 29276 KB Output is correct
21 Correct 61 ms 29272 KB Output is correct
22 Correct 60 ms 29280 KB Output is correct
23 Correct 63 ms 29276 KB Output is correct
24 Correct 66 ms 29020 KB Output is correct
25 Correct 61 ms 29124 KB Output is correct
26 Correct 12 ms 28508 KB Output is correct
27 Correct 12 ms 28628 KB Output is correct
28 Correct 13 ms 28564 KB Output is correct
29 Correct 27 ms 28908 KB Output is correct
30 Correct 44 ms 29020 KB Output is correct
31 Correct 56 ms 29524 KB Output is correct
32 Correct 61 ms 29392 KB Output is correct
33 Correct 58 ms 29272 KB Output is correct
34 Correct 66 ms 29276 KB Output is correct
35 Correct 62 ms 29284 KB Output is correct
36 Correct 60 ms 29276 KB Output is correct
37 Correct 59 ms 29272 KB Output is correct
38 Correct 59 ms 29272 KB Output is correct
39 Correct 63 ms 29264 KB Output is correct
40 Correct 59 ms 29276 KB Output is correct
41 Correct 12 ms 28508 KB Output is correct
42 Correct 13 ms 28628 KB Output is correct
43 Correct 12 ms 28508 KB Output is correct
44 Correct 14 ms 28508 KB Output is correct
45 Correct 13 ms 28664 KB Output is correct
46 Correct 14 ms 28508 KB Output is correct
47 Correct 20 ms 28820 KB Output is correct
48 Correct 19 ms 28760 KB Output is correct
49 Correct 29 ms 28760 KB Output is correct
50 Correct 46 ms 29264 KB Output is correct
51 Correct 65 ms 29528 KB Output is correct
52 Correct 64 ms 29528 KB Output is correct
53 Correct 61 ms 29520 KB Output is correct
54 Correct 61 ms 29760 KB Output is correct
55 Correct 61 ms 29532 KB Output is correct
56 Correct 62 ms 29528 KB Output is correct
57 Correct 62 ms 29532 KB Output is correct
58 Correct 61 ms 29628 KB Output is correct
59 Correct 61 ms 29528 KB Output is correct
60 Correct 62 ms 29532 KB Output is correct
61 Correct 65 ms 29756 KB Output is correct
62 Correct 65 ms 29748 KB Output is correct
63 Correct 61 ms 29532 KB Output is correct
64 Correct 63 ms 29756 KB Output is correct
65 Correct 62 ms 29532 KB Output is correct
66 Correct 63 ms 29532 KB Output is correct
67 Correct 71 ms 29788 KB Output is correct
68 Correct 60 ms 29748 KB Output is correct
69 Correct 60 ms 29520 KB Output is correct
70 Correct 61 ms 29532 KB Output is correct
71 Correct 20 ms 28764 KB Output is correct
72 Correct 20 ms 28764 KB Output is correct
73 Correct 23 ms 28764 KB Output is correct
74 Correct 23 ms 28860 KB Output is correct
75 Correct 21 ms 28764 KB Output is correct
76 Correct 29 ms 29016 KB Output is correct
77 Correct 29 ms 29020 KB Output is correct
78 Correct 29 ms 28980 KB Output is correct
79 Correct 29 ms 29016 KB Output is correct
80 Correct 28 ms 29020 KB Output is correct
81 Correct 47 ms 29532 KB Output is correct
82 Correct 47 ms 29532 KB Output is correct
83 Correct 55 ms 29352 KB Output is correct
84 Correct 48 ms 29532 KB Output is correct
85 Correct 46 ms 29508 KB Output is correct
86 Correct 48 ms 29528 KB Output is correct
87 Correct 48 ms 29532 KB Output is correct
88 Correct 48 ms 29640 KB Output is correct
89 Correct 48 ms 29508 KB Output is correct
90 Correct 47 ms 29528 KB Output is correct
91 Correct 76 ms 30292 KB Output is correct
92 Correct 77 ms 30300 KB Output is correct
93 Correct 66 ms 30340 KB Output is correct
94 Correct 67 ms 30292 KB Output is correct
95 Correct 68 ms 30292 KB Output is correct
96 Correct 72 ms 30292 KB Output is correct
97 Correct 68 ms 30300 KB Output is correct
98 Correct 68 ms 30408 KB Output is correct
99 Correct 70 ms 30292 KB Output is correct
100 Correct 71 ms 30496 KB Output is correct
101 Correct 68 ms 30292 KB Output is correct
102 Correct 70 ms 30300 KB Output is correct
103 Correct 67 ms 30292 KB Output is correct
104 Correct 69 ms 30256 KB Output is correct
105 Correct 66 ms 30496 KB Output is correct
106 Correct 68 ms 30532 KB Output is correct
107 Correct 70 ms 30556 KB Output is correct
108 Correct 74 ms 30292 KB Output is correct
109 Correct 68 ms 30300 KB Output is correct
110 Correct 67 ms 30532 KB Output is correct
111 Correct 68 ms 30544 KB Output is correct
112 Correct 69 ms 30292 KB Output is correct
113 Correct 66 ms 30556 KB Output is correct
114 Correct 68 ms 30532 KB Output is correct
115 Correct 67 ms 30292 KB Output is correct
116 Incorrect 18 ms 29020 KB Output isn't correct
117 Halted 0 ms 0 KB -