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;
struct inter
{
int begin, end;
inter(int x, int y) {begin = x; end = y;}
bool operator<(inter outro)
{
if (end == outro.end) return begin > outro.begin;
return end < outro.end;
}
};
const int MAXN = 4e5 + 10;
int v[MAXN];
vector<inter> Intervalos;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
for (int i = 1; i <= N; i++) {cin >> v[i]; v[i] += v[i-1];}
for (int i = 1; i <= N; i++)
{
for (int j = i; j <= N; j++)
{
if (v[j] - v[i-1] == 0) Intervalos.emplace_back(i, j);
}
}
sort(Intervalos.begin(), Intervalos.end());
vector<inter> Usados; int L = -1;
for (inter atual : Intervalos)
{
if (atual.begin < L) continue;
Usados.push_back(atual);
}
int Q;
cin >> Q;
for (int q = 1; q <= Q; q++)
{
int X, Y;
cin >> X >> Y;
int resp = 0; int Comec = -1;
for (inter atual : Usados)
{
if (atual.begin < X || atual.begin < Comec) continue;
if (atual.end > Y) break;
resp++;
Comec = atual.end;
}
cout << resp << '\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... |