80分,求改,有关

P2367 语文成绩

lce11451410086 @ 2024-11-16 07:49:42

#include<bits/stdc++.h>
using namespace std;
int a[1000010];
int s[1000010];
int y[1000010];
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        s[i]=a[i]-a[i-1];
    }
    while(m--){
        int l,r,x;
        scanf("%d%d%d",&l,&r,&x);
        s[l]+=x;
        s[r+1]-=x;
    }
    for(int i=1;i<=n;i++){
        y[i]=y[i-1]+s[i];
    }
    int mn=INT_MAX;
    for(int i=1;i<=n;i++){
        mn=min(mn,y[i]);
    }
    printf("%d",mn);
    return 0;
}

by jyhDora2011 @ 2024-11-16 15:27:12

数据范围啊 n<=5*10^6

int a[1000010];

int s[1000010];

int y[1000010];

这三行改成

int a[5000010];
int s[5000010];
int y[5000010];

by RAY130830 @ 2024-12-05 21:13:30

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

by RAY130830 @ 2024-12-05 21:14:13

@lce11451410086


by lce11451410086 @ 2024-12-05 21:18:23

@jyhDora2011@RAY130830 感谢


|