reasa @ 2024-07-06 07:55:14
rt,样例是能过的,感觉写的差分没啥问题,但是全TLE
#include <bits/stdc++.h>
using namespace std;
inline int read(){
int x = 0,f = 1;
char c = getchar();
while (!isdigit(c)){
if (c == '-'){
f = -1;
c = getchar();
}
}
while (isdigit(c)){
x = x*10+c-'0';
c = getchar();
}
return x*f;
}
int a[100100],d[100100];
signed main(){
int ans = 101111;
int n = read(),p = read();
for (int i=1;i<=n;i++){
a[i] = read();
}
for (int i=1;i<=n;i++){
d[i] = a[i]-a[i-1];
}
for (int i=0;i<p;i++){
int x = read(),y = read(),z = read();
d[x]+=z;
d[y+1]-=z;
}
for (int i=1;i<=n;i++){
a[i] = a[i-1]+d[i];
if (ans>a[i]){
ans = a[i];
}
}
cout<<ans<<endl;
return 0;
}
by jcf666 @ 2024-07-06 22:31:13
叮~您的代码已改好,请注意签收!
AC代码:
#include <bits/stdc++.h>
using namespace std;
int a[10000100],d[10000100];
signed main(){
int ans = 101111;
int n,p;
cin>>n>>p;
for (int i=1;i<=n;i++){
cin>>a[i];
}
for (int i=1;i<=n;i++){
d[i] = a[i]-a[i-1];
}
for (int i=0;i<p;i++){
int x,y,z;
cin>>x>>y>>z;
d[x]+=z;
d[y+1]-=z;
}
for (int i=1;i<=n;i++){
a[i] = a[i-1]+d[i];
if (ans>a[i]){
ans = a[i];
}
}
cout<<ans<<endl;
return 0;
}
1.你的快读不知道出了什么问题,反正我将快读换成用cin输入后就不会超时了
2.你的代码中a和d数组大小都开小了,将数组大小更改后就解决了RE的问题
总的来说,你的代码没有太大的问题,就是有些细节要注意。祝你在OI路上一路顺风,RP++!
by reasa @ 2024-07-07 05:07:59
@jcf666 谢谢