4 条题解

  • 1
    @ 2025-10-29 11:26:52

    简单差分模版

    # include <bits/stdc++.h>
    using namespace std;
    const int N = 5e6 + 10;
    int a[N], d[N];
    int main() {
        int n, p;
        scanf("%d%d", &n, &p);
        a[0] = 0;
        for (int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
            d[i] = a[i] - a[i - 1];
        }
        while (p--) {
            int x, y, z;
            scanf("%d%d%d", &x, &y, &z);
            d[x] += z;
            d[y + 1] -= z;
        }
        int mi = INT_MAX;
        for (int i = 1; i <= n; i++) {
            a[i] = a[i - 1] + d[i];
            mi = min(mi, a[i]);
        }
        printf("%d", mi);
        return 0;
    }
    
    • 0
      @ 2025-7-26 10:53:35

      #include<bits/stdc++.h> using namespace std; int n,p,a[5000010],q[5000010],x,z,y,lj=0,da=101; int main(){ cin>>n>>p; for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=1;i<=p;i++){ cin>>x>>y>>z; q[y]+=z; q[x-1]-=z; } for(int i=n;i>=1;i--){ lj+=q[i]; a[i]+=lj; da=min(da,a[i]); } cout<<da; return 0; }

      • 0
        @ 2025-7-26 10:53:10

        #include<bits/stdc++.h> using namespace std; int n,p,a[5000010],q[5000010],x,z,y,lj=0,da=101; int main(){ cin>>n>>p; for(int i=1;i<=n;i++){ cin>>a[i]; } for(int i=1;i<=p;i++){ cin>>x>>y>>z; q[y]+=z; q[x-1]-=z; } for(int i=n;i>=1;i--){ lj+=q[i]; a[i]+=lj; da=min(da,a[i]); } cout<<da; return 0; }

        • 0
          @ 2025-7-26 10:51:24
          #include<bits/stdc++.h>
          using namespace std;
          int n,p,l=0,a[5000005],sum[5000005],x,y,z,ans=1e9;
          int main(){
          	cin>>n>>p;
          	for(int i=1;i<=n;i++) {
          		cin>>a[i];
          	}
          	for(int i=1;i<=p;i++) {
          		cin>>x>>y>>z;
          		sum[y]+=z;
          		sum[x-1]-=z;
          	}
          	for(int i=n;i>=1;i--) {
          		l+=sum[i];
          		a[i]+=l;
          		ans=min(ans,a[i]);
          	}
          	cout<<ans;
          	return 0;
          }
          
          
          • @ 2025-7-26 10:51:59
            #include<bits/stdc++.h>
            using namespace std;
            int n,p,l=0,a[5000005],sum[5000005],x,y,z,ans=1e9;
            int main(){
            	cin>>n>>p;
            	for(int i=1;i<=n;i++) {
            		cin>>a[i];
            	}
            	for(int i=1;i<=p;i++) {
            		cin>>x>>y>>z;
            		sum[y]+=z;
            		sum[x-1]-=z;
            	}
            	for(int i=n;i>=1;i--) {
            		l+=sum[i];
            		a[i]+=l;
            		ans=min(ans,a[i]);
            	}
            	cout<<ans;
            	return 0;
            }
            
            
        • 1

        信息

        ID
        6406
        时间
        1000ms
        内存
        125MiB
        难度
        3
        标签
        递交数
        93
        已通过
        25
        上传者