| Task: | Kyselyt |
| Sender: | sharph2 |
| Submission time: | 2025-12-20 17:11:22 +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.03 s | 1, 2, 3 | details |
| #2 | ACCEPTED | 0.99 s | 2, 3 | details |
| #3 | RUNTIME ERROR | 0.70 s | 3 | details |
| #4 | ACCEPTED | 0.00 s | 1, 2, 3 | details |
Code
#include <algorithm>
#include <array>
#include <iostream>
#include <climits>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
using namespace std;
constexpr int C = 101;
int main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<int> T(n);
for(int& val : T) {
cin >> val;
}
vector<int> eka;
for(int i = 0; i < n; ++i) {
int val = T[i];
while((int)eka.size() <= val) {
eka.push_back(i);
}
}
eka.push_back(n);
vector<int> cnt(eka.size() - 1);
for(int qi = 0; qi < q; ++qi) {
int a, b;
cin >> a >> b;
--a;
for(int i = 0; i < (int)cnt.size(); ++i) {
int x = std::clamp(eka[i], a, b);
int y = std::clamp(eka[i + 1], a, b);
cnt[i] = y - x;
}
int A = 0;
int B = (b - a) / 2;
while(A != B) {
int M = (A + B + 1) / 2;
bool ok = true;
int av = 0;
int ac = cnt[av];
int bv = (int)cnt.size() - 1;
int i = M;
int bc = 0;
while(i > 0) {
if(i == cnt[bv]) {
bc = cnt[bv];
i = 0;
} else if(i < cnt[bv]) {
bc = i;
i = 0;
} else {
i -= cnt[bv];
--bv;
}
}
if(i != 0) {
throw 5;
}
while(i < M) {
while(ac == 0) {
++av;
ac = cnt[av];
}
while(bc == 0) {
++bv;
bc = cnt[bv];
}
if(bv < 2 * av) {
ok = false;
break;
}
int c = min(ac, bc);
i += c;
ac -= c;
bc -= c;
}
if(ok) {
A = M;
} else {
B = M - 1;
}
}
cout << A << "\n";
}
return 0;
}
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 ... |
