Submission details
Task:Lucky prefixes
Sender:Cystem Administrators
Submission time:2025-11-08 16:58:10 +0200
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#20.82 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.28 sdetails
#50.44 sdetails
#60.30 sdetails
#70.32 sdetails
#80.38 sdetails
#90.43 sdetails
#10ACCEPTED0.00 sdetails
#11ACCEPTED0.28 sdetails
#120.44 sdetails
#130.31 sdetails
#140.32 sdetails
#150.38 sdetails
#160.44 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:70:44: warning: comparison of integer expressions of different signedness: 'ull' {aka 'long unsigned int'} and 'll' {aka 'long int'} [-Wsign-compare]
   70 |                     for(ull i=bindex*100; i<b; i++) {
      |                                           ~^~

Code

#include <bits/stdc++.h>

using namespace std;

typedef int64_t ll;
typedef uint64_t ull;

int main() {
    ull n; ull q;
    cin >> n >> q;

    vector<ll> arr (n);

    bool isFirst = true;
    ll curSmall;
    ll cur = 0;

    vector<pair<ll, ll>> cache (10000);

    for (ull i = 0; i < n; i++) {
        ll num;
        cin >> num;
        arr.at(i) = num;
        cur += num;
        if (isFirst) {
            curSmall = cur;
            isFirst = false;
        }
        if (cur < curSmall) {
            curSmall = cur;
        }

        if ((i+1)%100==0) {
            cache.at(i/100) = make_pair(cur, curSmall);
            isFirst = true;
            cur = 0;
        }
    }

    for (ull i = 0; i < q; i++) {
        int type; ull a; ll b;
        cin >> type >> a >> b;
        if (type == 2) {
            a = a-1;
            b = b-1;
            bool lucky = true;
            ll summa = 0;
            ull index = a/100+1;
            ull bindex = b/100;
            
            for(ull i=a; i<=min((ull)b, index*100-1); i++) {
                summa += arr.at(i);
                if (summa<0) {
                    lucky = false;
                    break;
                }
            }
            if (lucky) {
                for (ull i = index; i < bindex; i++) {
                    ll c = summa + get<1>(cache.at(i));
                    if (c < 0) {
                        lucky = false;
                        break;
                    }
                    else {
                        summa += get<0>(cache.at(i));
                    }
                }
                if (lucky && index <= bindex) {
                    for(ull i=bindex*100; i<b; i++) {
                        summa += arr.at(i);
                        if (summa<0) {
                            lucky = false;
                            break;
                        }
                    }
                }
            }
            cout << (lucky ? "YES" : "NO") << endl;
        } else {
            arr.at(a-1) = b;
            ll index = (a-1)/100;
            isFirst = true;
            cur = 0;
            for (ull i = 100*index; i < min(n, (ull)100*(index+1)); i++) {
                if (isFirst) {
                    curSmall = cur;
                    isFirst = false;
                }
                if (cur < curSmall) {
                    curSmall = cur;
                }
            }
            cache.at(index) = make_pair(cur, curSmall);
        }
    }

}

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:

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

Feedback: Incorrect character on line 2 col 1: expected "NO", got "YES"

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:

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 555 col 1: expected "NO", got "YES"

Test 6

Verdict:

input
1000 200000
629447384 -729045992 811583872...

correct output
NO
NO
NO
NO
NO
...

user output
NO
NO
NO
NO
NO
...

Feedback: Incorrect character on line 88 col 1: expected "YES", got "NO"

Test 7

Verdict:

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 100 col 1: expected "YES", got "NO"

Test 8

Verdict:

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 69 col 1: expected "NO", got "YES"

Test 9

Verdict:

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 555 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:

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 555 col 1: expected "NO", got "YES"

Test 13

Verdict:

input
1000 200000
629447384 -729045992 811583872...

correct output
NO
NO
NO
NO
NO
...

user output
NO
NO
NO
NO
NO
...

Feedback: Incorrect character on line 88 col 1: expected "YES", got "NO"

Test 14

Verdict:

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 100 col 1: expected "YES", got "NO"

Test 15

Verdict:

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 69 col 1: expected "NO", got "YES"

Test 16

Verdict:

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 555 col 1: expected "NO", got "YES"