2 条题解

  • 0
    @ 2026-2-8 11:01:52
    #include<bits/stdc++.h>
    using namespace std;
    const int N = 1e5 + 10;
    long long a[N];
    long long feiqilai[N]; 
    int main() {
        int n, m;
        cin >> n >> m;
        for(int i = 1; i <= n; i++){
            cin >> a[i];
        }
        int l, r, c;
        while(m--){
            cin >> l >> r >> c;
            feiqilai[l] += c; 
            feiqilai[r+1] -= c; 
        }
        for(int i = 1; i <= n; i++){
            feiqilai[i] = feiqilai[i-1] + feiqilai[i];
            cout << a[i] + feiqilai[i] << " ";
        }
        return 0;
    }
    
    • 0
      @ 2026-2-8 10:57:08

      #include<bits/stdc++.h> using namespace std; const int N = 1e5 + 10; long long a[N]; long long feiqilai[N]; int main() { int n, m; cin >> n >> m; for(int i = 1; i <= n; i++){ cin >> a[i]; } int l, r, c; while(m--){ cin >> l >> r >> c; feiqilai[l] += c; feiqilai[r+1] -= c; } for(int i = 1; i <= n; i++){ feiqilai[i] = feiqilai[i-1] + feiqilai[i]; cout << a[i] + feiqilai[i] << " "; } return 0; }

      • 1

      信息

      ID
      318
      时间
      1000ms
      内存
      256MiB
      难度
      4
      标签
      递交数
      66
      已通过
      31
      上传者