| Task: | Kyselyt |
| Sender: | Kuha |
| Submission time: | 2025-12-20 16:02:40 +0200 |
| Language: | C++ (C++17) |
| Status: | READY |
| Result: | 58 |
| group | verdict | score |
|---|---|---|
| #1 | ACCEPTED | 16 |
| #2 | ACCEPTED | 42 |
| #3 | RUNTIME ERROR | 0 |
| test | verdict | time | group | |
|---|---|---|---|---|
| #1 | ACCEPTED | 0.09 s | 1, 2, 3 | details |
| #2 | ACCEPTED | 0.53 s | 2, 3 | details |
| #3 | RUNTIME ERROR | 0.02 s | 3 | details |
| #4 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
Code
#include <bits/stdc++.h>
#define ll long long
#define M 1000000007
using namespace std;
int x[222222];
int sx[222222][111];
int cnts[111];
bool u[222222];
int main() {
cin.sync_with_stdio(false);
cin.tie(0);
int n, q;
cin>>n>>q;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 100; j++) {
sx[i][j] = sx[i - 1][j];
}
cin>>x[i];
sx[i][x[i]]++;
}
while (q --> 0) {
int a, b;
cin>>a>>b;
int ans = 0;
for (int i = 1; i <= 100; i++) {
cnts[i] = sx[b][i] - sx[a - 1][i];
}
int i = 50;
for (int j = 100; j >= 2; j--) {
while (cnts[j] && i) {
while (i >= 1 && (2 * i > j || cnts[i] == 0)) {
i--;
}
if (!i) break;
int c = min(cnts[i], cnts[j]);
ans += c;
cnts[i] -= c;
cnts[j] -= c;
}
}
cout<<ans<<endl;
}
}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 ... |
