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;
// #define int long long
#define pint pair < int , int >
#define ll long long
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(NULL); cin.tie(NULL)
const int inf = 1e9 + 9;
const int mxn = 2e5 + 2;
const int mod = 1e9 + 7;
int a[mxn];
int main() {
int n;
cin >> n;
set < pint > s , L , R;
s.insert({0 , 0});
int sum = 0 , id = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
auto it = s.lower_bound({sum , 0});
if (it == s.end() || (*it).ff != sum) s.insert({sum , i});
else if ((*it).ff == sum) {
L.insert({(*it).ss + 1 , id});
R.insert({-i , id});
id++;
s.clear();
sum = 0;
s.insert({0 , i});
}
}
int q;
cin >> q;
while (q--) {
int l , r;
cin >> l >> r;
auto it1 = L.lower_bound({l , 0});
auto it2 = R.lower_bound({-r , 0});
if (it1 == L.end() || it2 == R.end()) {
cout << 0 << '\n';
continue;
}
int id1 = (*it1).ss;
int id2 = (*it2).ss;
if (id2 < id1) cout << 0 << '\n';
else cout << id2 - id1 + 1 << '\n';
}
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... |