感觉 106 也不是很大啊,为什么这份代码不关同步流 88:
#include <iostream>
#include <cmath>
using namespace std;
int n, q, l, r, k, a[1000001], s[1000001];
int main()
{
ios::sync_with_stdio(false);//加上注释88
cin >> n >> q;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
s[i] = s[i - 1] + a[i];
}
while (q--)
{
cin >> l >> r >> k;
if (l == r)
{
if (k == 0) cout << "0\n";
else cout << "-1\n";
continue;
}
if (r - l + 1 < k + 1) cout << "-1\n";
else
{
int tot = s[r] - s[l - 1];
if (r - l + 1 == k - 1) cout << (r - l + 1) - tot << '\n';
else
{
if (r - l + 1 == k + 1 && tot == r - l + 1) cout << "0\n";
else cout << abs(k - tot) << '\n';
}
}
}
return 0;
}