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)->sync_with_stdio(false);
long long n,d;
int q;
cin >> n >> d;
vector<int>c(n+5);
vector<int>ans(n+1,0);
for (int i = 1; i <= n; i++)
{
cin >> c[i];
ans[i] = ans[i-1] + (c[i] == 0 && c[i-1]==1);
}
cin >> q;
while(q--)
{
int l,r;
cin >> l >> r;
if(ans[r]-ans[l-1]==0)
{
cout << 0 << '\n';
}
else if(d==1)
{
cout << ans[r]-ans[l-1] << '\n';
}
else
{
cout << -1 << '\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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |