Fkxxx @ 2023-07-10 09:55:12
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n , q , a[500005] , d[5000005] , ans = 1e18 ;
signed main(){
cin >> n >> q ;
for( int i = 1 ; i <= n ; i ++ ){
cin >> a[i] ;
d[i] = a[i] - a[i - 1] ;
}
for( int i = 1 ; i <= q ; i ++ ){
int x , y , z ;
cin >> x >> y >> z ;
d[x] += z ;
d[y + 1] -= z ;
}
for( int i = 1 ; i <= n ; i ++ ){
d[i] += d[i - 1] ;
ans = min( ans , d[i] ) ;
}
cout << ans ;
return 0 ;
}
by endswitch @ 2023-07-10 09:57:27
@Soil 不要用同一个差分数组
by Fkxxx @ 2023-07-10 09:57:59
呼叫大佬@Daniel_yao @ollo @Cubic
by Fkxxx @ 2023-07-10 09:58:30
@XCY_OIER 可以把
by Fkxxx @ 2023-07-10 10:01:07
@XCY_OIER
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n , q , a[500005] , d[5000005] , ans = 1e18 ;
signed main(){
cin >> n >> q ;
for( int i = 1 ; i <= n ; i ++ ){
cin >> a[i] ;
d[i] = a[i] - a[i - 1] ;
}
for( int i = 1 ; i <= q ; 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] ;
ans = min( ans , a[i] ) ;
}
cout << ans ;
return 0 ;
}
依然趋势
by Fkxxx @ 2023-07-10 10:02:48
@XCY_OIER 事数组开小了
by Fkxxx @ 2023-07-10 10:03:11
https://www.luogu.com.cn/record/114655010
此贴趋势
by Cubic @ 2023-07-10 10:04:39
数组开小难蚌。
by jacy1949 @ 2023-07-10 10:12:23
@Soil
你数组开小了
把第4行的
int n , q , a[500005] , d[5000005] , ans = 1e18 ;
改成int n , q , a[5000005] , d[5000005] , ans = 1e18 ;
就可以了
by Fkxxx @ 2023-07-10 10:25:16
@Cubic @jacy
xxdl
by ollo @ 2023-07-10 10:43:30
?