蓝桥OJ1276小明的彩灯

 蓝桥OJ1276小明的彩灯_第1张图片

#include
using namespace std;
const int N = 1e6 + 3;
using ll = long long;
ll a[N],diff[N];

int main()
{
  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  int n,q;cin >> n >> q;
  for (int i = 1; i <= n ;i++) cin >> a[i];
  for (int i = 1; i <= n ;i++) diff[i] = a[i] - a[i-1];
  for (int i = 1; i <= q; i++)
  {
    int l, r, x;cin >> l >> r >> x;
    diff[l] += x;
    diff[r+1] -= x;
  }
  for (int i = 1; i <= n; i++) 
  {
  a[i] = diff[i] + a[i-1];
  cout << (a[i] > 0? a[i] : 0) << " \n"[i == n];
//max(0ll,a[i])
  }
  return 0;
}

注意:使用[i==n]时,前面使用双引号“”,中间是有空格加上\n

你可能感兴趣的:(蓝桥杯备赛练习,算法,c++)