Submission details
Task:Kyselyt
Sender:Yytsi
Submission time:2025-12-20 17:23:17 +0200
Language:C++ (C++20)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.04 s1, 2, 3details
#20.59 s2, 3details
#30.00 s3details
#4ACCEPTED0.01 s1, 2, 3details

Code

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

int n, q;

int countOfXUpto[202020][101];
int cnt[101];

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  cin>>n>>q;

  for (int i = 1; i <= n; i++) {
    int x; cin>>x;
    countOfXUpto[x][i]++;
    for (int j = 1; j <= 100; j++) {
      countOfXUpto[j][i] += countOfXUpto[j][i-1];
    }
  }
  
  for (int qi = 0; qi < q; qi++) {
    int a, b; cin>>a>>b;

    for (int j = 1; j <= 100; j++) {
      cnt[j] = countOfXUpto[j][b] - countOfXUpto[j][a-1];
    }

    int res = 0;
    for (int j = 100; j >= 1; j--) {
      for (int bottom = j / 2; bottom >= 1; bottom--) {
        int bcnt = cnt[bottom];
        int topcnt = cnt[j];
        int m = min(bcnt, topcnt);
        cnt[bottom] -= m;
        cnt[j] -= m;
        res += m;
        if (cnt[j] == 0) break;
      }
    }

    cout << res << "\n";
  }
}

Test details

Test 1

Group: 1, 2, 3

Verdict:

input
200000 1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
97730
98017
97642
98714
98684
...

user output
-1271113078
1895716891
528747092
1575056398
-1033485973
...

Feedback: Incorrect character on line 1 col 1: expected "97730", got "-1271113078"

Test 2

Group: 2, 3

Verdict:

input
200000 200000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

correct output
98585
98296
97821
97536
97126
...

user output
-1658624254
2012646009
1638123055
1693519774
-134199484
...

Feedback: Incorrect character on line 1 col 1: expected "98585", got "-1658624254"

Test 3

Group: 3

Verdict:

input
200000 200000
1682 5103 11595 22085 22347 26...

correct output
98161
98619
98358
98614
98192
...

user output
(empty)

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

input
44 990
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

correct output
0
1
1
2
2
...

user output
0
1
1
2
2
...