This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |