| Task: | Kyselyt |
| Sender: | Yytsi |
| Submission time: | 2025-12-21 12:05:48 +0200 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | 58 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 16 |
| #2 | ACCEPTED | 42 |
| #3 | RUNTIME ERROR | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.10 s | 1, 2, 3 | details |
| #2 | ACCEPTED | 0.61 s | 2, 3 | details |
| #3 | RUNTIME ERROR | 0.00 s | 3 | details |
| #4 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
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: RUNTIME ERROR
| 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 ... |
