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;
int main(){
cin.tie(0);ios::sync_with_stdio(0);
//1.
int n, q;
//2.
cin >> n;
int v[n], sp[n + 1];
sp[0] = 0;
//3.
for(int i = 0; i < n; i++){
cin >> v[i];
sp[i + 1] = sp[i] + v[i];
}
cin >> q;
for(int iii = 0; iii < q; iii++){
int l, r; cin >> l >> r;
map<int, int> mp;
int cnt = 0;
int lp = l - 1;
mp[ sp[lp] ]++;
for(int i = l; i <= r; i++){
//cout << "i = " << i << " cnt = ";
if(mp.find( sp[i] ) == mp.end()){
mp[ sp[i] ] = i;
}else{
if( mp[ sp[i] ] >= lp ){
//cout << "( facem cu " << mp[ sp[i] ] << " ) ";
lp = i;
cnt++;
}
mp[ sp[i] ] = i;
}
//cout << cnt << endl;
}
cout << cnt << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |