关于基础赛T2
  • 板块学术版
  • 楼主__galaxy_1202__
  • 当前回复11
  • 已保存回复11
  • 发布时间2024/11/10 18:17
  • 上次更新2024/11/10 20:50:10
查看原帖
关于基础赛T2
1020835
__galaxy_1202__楼主2024/11/10 18:17

感觉 10610^6 也不是很大啊,为什么这份代码不关同步流 8888

#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;
}
2024/11/10 18:17
加载中...