#include<bits/stdc++.h>
using namespace std;
const int mxN = 5005;
struct T{
int l, r;
bool operator<(T &other){
return r < other.r;
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int>v(n + 1);
vector<long long>pref(n + 1);
vector<T>I;
for(int i = 1;i <= n;++i){
cin >> v[i];
pref[i] = pref[i - 1] + v[i];
}
for(int i = 1;i <= n;++i){
for(int j = i;j <= n;++j){
if(pref[j] - pref[i - 1] == 0){
I.push_back({i, j});
break;
}
}
}
sort(I.begin(), I.end());
int q;
cin >> q;
while(q--){
int l, r;
cin >> l >> r;
vector<T>temp;
for(auto t : I){
if(l <= t.l && t.r <= r){
temp.push_back(t);
}
}
int mx = 0, last = -1;
if(!temp.empty()){
mx = 1;
last = 0;
for(int i = 1;i < (int)temp.size();++i){
if(temp[last].r < temp[i].l){
mx++;
last = i;
}
}
}
cout << mx << '\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... |