이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define ll long long
using namespace std;
const int N = 30005;
ll a[N];
main (){
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n,m;
cin>>n>>m;
for (int i=1;i<=n;i++)
cin>>a[i];
while(m--){
int l,r,k;
cin>>l>>r>>k;
for (int i=l;i<=r;i++)
a[i] += k;
ll mn = a[1],mx=a[1],ans=0;
bool asc = 0,d=0;
for (int i=2;i<=n;i++){
if (a[i] > a[i - 1]){
if (d) {
ans += mx - mn;
mn = a[i],mx = a[i];
}
else{
mn = min(mn,a[i]);
mx = max(mx,a[i]);
}
asc=1,d=0;
}
else if (a[i] < a[i - 1]){
if (asc){
ans += mx - mn;
mn = a[i],mx = a[i];
}
else{
mn = min(mn,a[i]);
mx = max(mx,a[i]);
}
asc=0,d=1;
}
else d=asc=0,ans += mx - mn,mn = mx = a[i];
// cout<<ans<<" "<<asc<< " "<<d<<" "<<i<<endl;
}
if (asc) ans+= mx-mn;
if (d) ans+=mx-mn;
cout<<ans<<"\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
7 | main (){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |