hjk20120612 @ 2024-12-15 10:41:38
现在的代码
#include<bits/stdc++.h>
using namespace std;
long long n,p,a[5000100],b[5000100],x,y,z,minn=500000001;
int main(){
cin>>n>>p;
for(long long i=0;i<n;i++){
cin>>a[i];
}
for(long long i=0;i<p;i++){
cin>>x>>y>>z;
b[x-1]+=z;
b[y]-=z;
}
for(long long i=0;i<n;i++){
b[i]+=b[i-1];
a[i]+=b[i];
if(minn>a[i]){
minn=a[i];
}
}
cout<<minn;
return 0;
}
之前的
#include<bits/stdc++.h>
using namespace std;
long long n,p,a[5000100],x,y,z,minn=500000001;
int main(){
cin>>n>>p;
for(long long i=0;i<n;i++){
cin>>a[i];
}
for(long long i=0;i<p;i++){
cin>>x>>y>>z;
a[x-1]+=z;
a[y]-=z;
}
for(long long i=0;i<n;i++){
a[i]+=b[i-1];
if(minn>a[i]){
minn=a[i];
}
}
cout<<minn;
return 0;
}
by lan_chance @ 2024-12-15 10:56:12
第一:你一开始的代码未定义
b[i-1]
同时你这个应该是用的前缀和差分:就是