Submission #834824

#TimeUsernameProblemLanguageResultExecution timeMemory
834824LucaLucaMSum Zero (RMI20_sumzero)C++17
22 / 100
1082 ms5224 KiB
#include <bits/stdc++.h>
#warning That's the baby, that's not my baby

typedef long long ll;

using namespace std;

const int NMAX = 1e5;

ll sum[NMAX + 5];
int nxt[NMAX + 5];
int jump[17][NMAX + 5];

const int p2[18] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> sum[i];
        sum[i] += sum[i - 1];
    }

    map<int, int>pos;

    nxt[n + 1] = n + 1;

    for (int i = n; i > 0; i--) {
        pos[sum[i]] = i;
        if (!pos.count(sum[i - 1])) {
            nxt[i] = n + 1;
        } else {
            nxt[i] = pos[sum[i - 1]];
        }
        nxt[i] = min(nxt[i], nxt[i + 1]);
    }

//    cout << "! ";
//    for (int i = 1; i <= n; i++) {
//        cout << nxt[i] << " - " << sum[nxt[i]] << ' ' << sum[i - 1] << '\n';
//    }
//    cout << '\n';

    int q;
    cin >> q;

    while (q--) {
        int l, r;
        cin >> l >> r;
        int answer = 0;
        while (nxt[l] <= r) {
            l = nxt[l] + 1;
            answer++;
        }
        cout << answer << '\n';
    }

    return 0;
}

Compilation message (stderr)

sumzero.cpp:2:2: warning: #warning That's the baby, that's not my baby [-Wcpp]
    2 | #warning That's the baby, that's not my baby
      |  ^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...