#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';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
66 ms |
8940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
65 ms |
7252 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |