Submission details
Task:Kyselyt
Sender:Yytsi
Submission time:2025-12-21 12:05:48 +0200
Language:C++ (C++20)
Status:READY
Result:58
Feedback
groupverdictscore
#1ACCEPTED16
#2ACCEPTED42
#30
Test results
testverdicttimegroup
#1ACCEPTED0.10 s1, 2, 3details
#2ACCEPTED0.61 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[101][202020];
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: ACCEPTED

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
97730
98017
97642
98714
98684
...

Test 2

Group: 2, 3

Verdict: ACCEPTED

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
98585
98296
97821
97536
97126
...

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
...