Submission #646625

#TimeUsernameProblemLanguageResultExecution timeMemory
646625VanillaSum Zero (RMI20_sumzero)C++17
0 / 100
14 ms340 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int64; const int maxn = 5e3 + 2; int64 a [maxn]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++){ cin >> a[i]; } vector <pair <int, int> > sv; int last = 1; for (int i = 1; i <= n; i++){ int64 sum = 0; for (int j = i; j >= last; j--){ sum+=a[j]; if (!sum) { sv.push_back({j, i}); last = i + 1; } } } int q; cin >> q; while (q--) { int l,r, rs = 0; cin >> l >> r; for (auto i: sv){ if (i.first >= l && i.second <= r) rs++; } cout << rs << "\n"; } // for (auto i: sv){ // cout << i.first << " " << i.second << "\n"; // } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...