Submission details
Task:Muutokset
Sender:jubidubi
Submission time:2025-11-09 17:13:57 +0200
Language:C++ (C++11)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3details
#20.00 s1, 2, 3details
#30.00 s1, 2, 3details
#40.01 s1, 2, 3details
#50.00 s1, 2, 3details
#60.01 s2, 3details
#70.01 s2, 3details
#80.01 s2, 3details
#90.01 s2, 3details
#100.01 s3details
#110.02 s3details
#120.01 s3details
#130.03 s3details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:76:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |   for (int i = 0; i < v.size(); ++i) {
      |                   ~~^~~~~~~~~~

Code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int N = 202020;
int bf[N];
int af[N];

int bsum(int a, int b) {
  a += N;
  b += N;
  int s = 0;
  while (a <= b) {
    if (a % 2 == 1) s += bf[a++];
    if (b % 2 == 0) s += bf[b--];
    a /= 2;
    b /= 2;
  }
  return s;
}
int asum(int a, int b) {
  a += N;
  b += N;
  int s = 0;
  while (a <= b) {
    if (a % 2 == 1) s += af[a++];
    if (b % 2 == 0) s += af[b--];
    a /= 2;
    b /= 2;
  }
  return s;
}

void badd(int k, int x) {
  k += N;
  bf[k] += x;
  for (k /= 2; k >= 1; k /= 2) {
    bf[k] = bf[2 * k] + bf[2 * k + 1];
  }
}

void aadd(int k, int x) {
  k += N;
  af[k] += x;
  for (k /= 2; k >= 1; k /= 2) {
    af[k] = af[2 * k] + af[2 * k + 1];
  }
}

int afnum[N];
int bfnum[N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;

  vector<int> inp(m);
  for (int i = 0; i < m; ++i) {
    int x;
    cin >> x;
    ++afnum[x];
    inp[i] = x;
  }
  vector<pair<int, int>> v;
  for (int i = 1; i <= n; ++i) {
    if (afnum[i] > 0) v.push_back({-afnum[i], i});
    aadd(afnum[i], 1);
  };

  sort(v.begin(), v.end());

  int afsum = 0;
  for (int i = 0; i < v.size(); ++i) {
    auto p = v[i];
    afsum += -p.first * (i + 1);
  }

  int bfsum = 0;

  for (int i = 0; i < m - 1; ++i) {
    int x = inp[i];

    afsum -= asum(afnum[x], n);
    aadd(afnum[x], -1);
    aadd(afnum[x] - 1, 1);
    afnum[x]--;

    badd(bfnum[x], -1);
    badd(bfnum[x] + 1, 1);
    bfnum[x] += 1;
    bfsum += bsum(bfnum[x], n);

    cout << afsum + bfsum << " ";
  }
  cout << endl;
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
1 1
1

correct output
(empty)

user output
(empty)

Test 2

Group: 1, 2, 3

Verdict:

input
100 1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
1000 1000 1000 1000 1000 1000 ...

user output
1001 1002 1003 1004 1005 1006 ...

Feedback: Incorrect character on line 1 col 4: expected "1000", got "1001"

Test 3

Group: 1, 2, 3

Verdict:

input
100 1000
1 2 2 2 1 1 1 1 1 1 1 1 1 2 1 ...

correct output
1488 1488 1487 1486 1487 1488 ...

user output
1489 1491 1492 1493 1495 1497 ...

Feedback: Incorrect character on line 1 col 4: expected "1488", got "1489"

Test 4

Group: 1, 2, 3

Verdict:

input
100 1000
7 8 2 4 8 3 3 10 9 7 7 6 8 7 2...

correct output
5107 5107 5103 5099 5098 5102 ...

user output
5110 5112 5111 5110 5111 5116 ...

Feedback: Incorrect character on line 1 col 3: expected "5107", got "5110"

Test 5

Group: 1, 2, 3

Verdict:

input
100 1000
23 85 3 99 63 79 38 37 67 28 7...

correct output
41676 41672 41621 41587 41589 ...

user output
41676 41672 41621 41587 41589 ...

Feedback: Incorrect character on line 1 col 35: expected "41578", got "41579"

Test 6

Group: 2, 3

Verdict:

input
100000 1000
2 1 2 1 1 2 2 2 1 2 2 2 2 2 2 ...

correct output
1484 1485 1484 1485 1485 1485 ...

user output
(empty)

Test 7

Group: 2, 3

Verdict:

input
100000 1000
10 8 4 4 3 8 4 7 5 9 7 1 5 3 4...

correct output
5279 5275 5277 5276 5272 5268 ...

user output
(empty)

Test 8

Group: 2, 3

Verdict:

input
100000 1000
82 63 63 58 57 46 58 40 23 47 ...

correct output
41444 41381 41301 41284 41279 ...

user output
(empty)

Test 9

Group: 2, 3

Verdict:

input
100000 1000
50231 31135 38003 12048 55578 ...

correct output
498503 497507 496513 495521 49...

user output
(empty)

Test 10

Group: 3

Verdict:

input
100000 100000
1 2 1 2 1 1 2 1 1 1 1 2 1 1 2 ...

correct output
149988 149988 149988 149988 14...

user output
(empty)

Test 11

Group: 3

Verdict:

input
100000 100000
4 2 6 2 2 2 2 5 9 5 3 5 1 9 1 ...

correct output
547169 547164 547157 547151 54...

user output
(empty)

Test 12

Group: 3

Verdict:

input
100000 100000
15 9 37 82 72 45 42 96 67 99 6...

correct output
4959855 4959845 4959773 495975...

user output
(empty)

Test 13

Group: 3

Verdict:

input
100000 100000
30941 71402 45742 82863 71830 ...

correct output
2378217706 2378191367 23781909...

user output
(empty)