| Task: | Lucky prefixes |
| Sender: | "Selvästi nähdään" |
| Submission time: | 2025-11-08 16:55:43 +0200 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | WRONG ANSWER |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.01 s | details |
| #2 | ACCEPTED | 0.22 s | details |
| #3 | ACCEPTED | 0.01 s | details |
| #4 | ACCEPTED | 0.08 s | details |
| #5 | WRONG ANSWER | 0.21 s | details |
| #6 | ACCEPTED | 0.13 s | details |
| #7 | WRONG ANSWER | 0.15 s | details |
| #8 | WRONG ANSWER | 0.18 s | details |
| #9 | WRONG ANSWER | 0.21 s | details |
| #10 | ACCEPTED | 0.01 s | details |
| #11 | ACCEPTED | 0.08 s | details |
| #12 | WRONG ANSWER | 0.21 s | details |
| #13 | ACCEPTED | 0.14 s | details |
| #14 | WRONG ANSWER | 0.15 s | details |
| #15 | WRONG ANSWER | 0.18 s | details |
| #16 | WRONG ANSWER | 0.21 s | details |
Compiler report
input/code.cpp: In function 'll best_prefix(int, int)':
input/code.cpp:42:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int i = 1; i < all_chunks.size(); i++) {
| ~~^~~~~~~~~~~~~~~~~~~Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = (1 << 18);
pair<ll, ll> seg[2*N];
ll vals[N];
const ll LINF = (1LL<<56LL);
pair<ll, ll> combine(pair<ll, ll> left, pair<ll, ll> right) {
ll totsum = left.first + right.first;
if (totsum < -LINF) totsum = -LINF;
ll max_prefix = max((ll)left.second, (ll)((ll)left.first + (ll)right.second));
if (max_prefix < -LINF) max_prefix = -LINF;
return make_pair(totsum, max_prefix);
}
ll best_prefix(int a, int b) {
a += N;
b += N;
vector<pair<ll, ll>> left_chunks;
vector<pair<ll, ll>> right_chunks;
while (a <= b) {
if (a % 2 == 1) left_chunks.push_back(seg[a++]);
if (b % 2 == 0) right_chunks.push_back(seg[b--]);
a /= 2;
b /= 2;
}
reverse(right_chunks.begin(), right_chunks.end());
vector<pair<ll, ll>> all_chunks;
for (auto v : left_chunks) all_chunks.push_back(v);
for (auto v : right_chunks) all_chunks.push_back(v);
pair<ll, ll> result = all_chunks[0];
for (int i = 1; i < all_chunks.size(); i++) {
result = combine(result, all_chunks[i]);
}
return result.second;
}
void build_segtree(int n) {
for (int i = 0; i < n; i++) {
seg[i + N] = make_pair(vals[i], vals[i]);
}
for (int i = N + n; i < 2*N; i++) {
seg[i] = make_pair(-LINF, -LINF);
}
for (int i = N - 1; i >= 1; i--) {
seg[i] = combine(seg[2*i], seg[2*i+1]);
}
}
void upd(int pos, ll x) {
pos += N;
vals[pos] = x;
// cout << "vals["<<pos<<"] = "<<x<<"\n";
seg[pos] = make_pair(x, x);
// cout << "seg pos done too\n";
for (pos /= 2; pos >= 1; pos /= 2) {
seg[pos] = combine(seg[pos*2], seg[pos*2+1]);
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, m;
cin>>n>>m;
// cout << "I have "<<n<<" "<<m<<"\n";
for (int i = 0; i < n; i++) {
ll x; cin>>x;
vals[i] = -x;
}
// cout << "printing arr:\n";
for (int i = 0; i < n; i++) {
// cout << vals[i]<<" ";
}
build_segtree(n);
for (int qi = 0; qi < m; qi++) {
// cout << "hi? here m is "<<m<<" and qi is "<<qi<<"\n";
int qt = 0;
cin>>qt;
if (qt == 2) {
int a = 0;
int b = 0;
cin>>a>>b;
a = max(a, 1);
b = min(b, n);
// query
ll res = -best_prefix(a-1, b-1);
// cout << "minimum of "<<x-1<<" "<<y-1<<" interval is "<<res<<"\n";
if (res < 0LL) cout << "NO\n";
else cout << "YES\n";
} else {
int pos = 0;
ll v = 0;
cin>>pos>>v;
// cout << "setting "<<x-1<<" to value"<<-y<<" and a was "<<a<<"\n";
upd(pos-1, -v);
// cout << "set it?\n";
}
// cout << "will continue because "<<qi<<" "<<m<<"\n";
}
}Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 6 4 3 -2 1 5 6 1 2 1 3 2 2 3 1 3 -2 ... |
| correct output |
|---|
| YES NO NO |
| user output |
|---|
| YES NO NO |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 200000 200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ... |
| correct output |
|---|
| NO NO NO NO NO ... |
| user output |
|---|
| NO NO NO NO NO ... |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 10 10 629447384 -729045992 811583872... |
| correct output |
|---|
| YES NO NO NO NO ... |
| user output |
|---|
| YES NO NO NO NO ... |
Test 4
Verdict: ACCEPTED
| input |
|---|
| 1 200000 629447384 1 1 670017180 1 1 826751744 1 1 -804919168 ... |
| correct output |
|---|
| NO NO NO YES YES ... |
| user output |
|---|
| NO NO NO YES YES ... |
Test 5
Verdict: WRONG ANSWER
| input |
|---|
| 200000 200000 629447384 -729045992 811583872... |
| correct output |
|---|
| NO NO NO NO NO ... |
| user output |
|---|
| NO NO NO NO NO ... |
Feedback: Incorrect character on line 2054 col 1: expected "NO", got "YES"
Test 6
Verdict: ACCEPTED
| input |
|---|
| 1000 200000 629447384 -729045992 811583872... |
| correct output |
|---|
| NO NO NO NO NO ... |
| user output |
|---|
| NO NO NO NO NO ... |
Test 7
Verdict: WRONG ANSWER
| input |
|---|
| 10000 200000 629447384 -729045992 811583872... |
| correct output |
|---|
| NO NO NO NO NO ... |
| user output |
|---|
| NO NO NO NO NO ... |
Feedback: Incorrect character on line 868 col 1: expected "NO", got "YES"
Test 8
Verdict: WRONG ANSWER
| input |
|---|
| 100000 200000 629447384 -729045992 811583872... |
| correct output |
|---|
| NO NO NO NO NO ... |
| user output |
|---|
| NO NO NO NO NO ... |
Feedback: Incorrect character on line 1727 col 1: expected "YES", got "NO"
Test 9
Verdict: WRONG ANSWER
| input |
|---|
| 200000 200000 629447384 -729045992 811583872... |
| correct output |
|---|
| NO NO NO NO NO ... |
| user output |
|---|
| NO NO NO NO NO ... |
Feedback: Incorrect character on line 2054 col 1: expected "NO", got "YES"
Test 10
Verdict: ACCEPTED
| input |
|---|
| 10 10 629447384 -729045992 811583872... |
| correct output |
|---|
| YES NO NO NO NO ... |
| user output |
|---|
| YES NO NO NO NO ... |
Test 11
Verdict: ACCEPTED
| input |
|---|
| 1 200000 629447384 1 1 670017180 1 1 826751744 1 1 -804919168 ... |
| correct output |
|---|
| NO NO NO YES YES ... |
| user output |
|---|
| NO NO NO YES YES ... |
Test 12
Verdict: WRONG ANSWER
| input |
|---|
| 200000 200000 629447384 -729045992 811583872... |
| correct output |
|---|
| NO NO NO NO NO ... |
| user output |
|---|
| NO NO NO NO NO ... |
Feedback: Incorrect character on line 2054 col 1: expected "NO", got "YES"
Test 13
Verdict: ACCEPTED
| input |
|---|
| 1000 200000 629447384 -729045992 811583872... |
| correct output |
|---|
| NO NO NO NO NO ... |
| user output |
|---|
| NO NO NO NO NO ... |
Test 14
Verdict: WRONG ANSWER
| input |
|---|
| 10000 200000 629447384 -729045992 811583872... |
| correct output |
|---|
| NO NO NO NO NO ... |
| user output |
|---|
| NO NO NO NO NO ... |
Feedback: Incorrect character on line 868 col 1: expected "NO", got "YES"
Test 15
Verdict: WRONG ANSWER
| input |
|---|
| 100000 200000 629447384 -729045992 811583872... |
| correct output |
|---|
| NO NO NO NO NO ... |
| user output |
|---|
| NO NO NO NO NO ... |
Feedback: Incorrect character on line 1727 col 1: expected "YES", got "NO"
Test 16
Verdict: WRONG ANSWER
| input |
|---|
| 200000 200000 629447384 -729045992 811583872... |
| correct output |
|---|
| NO NO NO NO NO ... |
| user output |
|---|
| NO NO NO NO NO ... |
Feedback: Incorrect character on line 2054 col 1: expected "NO", got "YES"
