제출 #401837

#제출 시각아이디문제언어결과실행 시간메모리
401837NintsiChkhaidzeSjeckanje (COCI21_sjeckanje)C++14
0 / 110
1 ms332 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...