#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("O1")
#pragma GCC optimize("O1")
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,mmx,abm")
using namespace std;
namespace std {
// #include<Love>
using ll=long long;
using str=string;
using int128=__int128_t;
using ld=long double;
typedef unsigned int ui;
typedef unsigned long long ull;
#define Love<3 HerLoveForMeJustaDream
}
#define Lovesper_ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pb push_back
#define all(c) c.begin(),c.end()
#define fi first
#define se second
#define debug cout<<"I Love You\n";
#define fu(i,a,b) for(ll i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define fa(i,s) for(auto&i:s)
#define Bitc(x,i) (((x)>>(i))&1)
#define _log(_x) 63-__builtin_clzll(_x)
#define LoveTime chrono::steady_clock::now().time_since_epoch().count()
const pll dxy4[]={{-1,0},{0,-1},{0,1},{1,0}};
const pll dxy8[]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
constexpr ll Mod=1e9+7;
constexpr ll mxn=1e6+7,mxm=3e3+7;
constexpr long long inf=(1ll<<31);
constexpr ll lnf=(1ll<<60);
struct __TS {
~__TS() {
// cerr<<"Time elapsed: "<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
}__ts;
mt19937 rng(LoveTime);
#define setup ((1<<3)-1>>1)
void OpenLove(const str&name){
// I'm So Lonely. I am Trying To Get Out This Lonely With Her Love
Lovesper_
if(fopen((name+".inp").c_str(),"r")){
// freopen((name+".test").c_str(),"r",stdin);
freopen((name+".inp").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
}
}
template<class X,class Y>bool maximize(X&x,const Y&y){X eps=1e-18;if(x+eps<y){x=y;return 1;}return 0;}
template<class X,class Y>bool minimize(X&x,const Y&y){X eps=1e-18;if(x>y+eps){x=y;return 1;}return 0;}
template <class Fun>class y_combinator_result {
Fun fun_;
public:
template<class T>explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
template<class ...Args>decltype(auto) operator()(Args &&...args) {return fun_(std::ref(*this), std::forward<Args>(args)...);}
};
template<class Fun>decltype(auto) y_combinator(Fun &&fun) {return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));}
ostream&operator<<( std::ostream& dest, __int128_t value){
ostream::sentry s(dest);__uint128_t tmp=value<0?-value:value;
char buffer[128];char*d=end(buffer);
do{d--;*d="0123456789"[tmp%10];tmp/=10;}while(tmp);
if(value<0)d--,*d='-';ll len=end(buffer)-d;
if(dest.rdbuf()->sputn(d,len)!=len)dest.setstate(ios_base::badbit);
return dest;
}
struct custom_hash{
size_t operator()(uint64_t x)const{
static const uint64_t HashRand=LoveTime;
x^=HashRand;return x^(x>>16);
}};
int64_t add(ll&a,ll b){a+=b;if(a>=Mod)a%=Mod;while(a<0)a+=Mod;return a;}
int64_t mul(ll&a,ll b,ll mod){a=1ll*a*b%mod;return a;}
int64_t mpow(ll a,ll b,ll mod){ll ans=1;for(;b;b>>=1,a=mul(a,a,mod))if(b&1)ans=mul(ans,a,mod);return ans;}
ll n,q,g[mxn];
vector<pll>graph[mxn];
void Lovesper(const ll&TestCase){
cin>>n>>q;
fu(i,1,n)cin>>g[i];
struct Love1{
function<void()>DreamyLove=[&](){
for(;q--;q){
ll l,r,x;cin>>l>>r>>x;
fu(j,l,r)g[j]+=x;
vll f(n+7,0);
fu(i,1,n){
ll mn=lnf,mx=-lnf;
fd(j,i,1){
minimize(mn,g[j]);
maximize(mx,g[j]);
maximize(f[i],f[j-1]+mx-mn);
}
}
cout<<f[n]<<'\n';
}
};
};
(new Love1())->DreamyLove();
}
signed main(int argc, char const *argv[]){
OpenLove("lovesper");
int tt=1;
// cin>>tt;
for(ll i=1;i<=tt;i++){
Lovesper(i);
if(i<tt)cout<<'\n';
}
return false;
}
Compilation message
Main.cpp:60:13: warning: ISO C++11 requires whitespace after the macro name
60 | #define Love<3 HerLoveForMeJustaDream
| ^~~~
Main.cpp: In function 'std::ostream& operator<<(std::ostream&, __int128)':
Main.cpp:121:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
121 | if(value<0)d--,*d='-';ll len=end(buffer)-d;
| ^~
Main.cpp:121:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
121 | if(value<0)d--,*d='-';ll len=end(buffer)-d;
| ^~
Main.cpp: In lambda function:
Main.cpp:143:22: warning: for increment expression has no effect [-Wunused-value]
143 | for(;q--;q){
| ^
Main.cpp: In function 'void OpenLove(const str&)':
Main.cpp:102:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
102 | freopen((name+".inp").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:103:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
103 | freopen((name+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
25168 KB |
Output is correct |
2 |
Correct |
39 ms |
25268 KB |
Output is correct |
3 |
Correct |
36 ms |
25168 KB |
Output is correct |
4 |
Correct |
35 ms |
25168 KB |
Output is correct |
5 |
Correct |
36 ms |
25276 KB |
Output is correct |
6 |
Correct |
36 ms |
25168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
25168 KB |
Output is correct |
2 |
Correct |
39 ms |
25268 KB |
Output is correct |
3 |
Correct |
36 ms |
25168 KB |
Output is correct |
4 |
Correct |
35 ms |
25168 KB |
Output is correct |
5 |
Correct |
36 ms |
25276 KB |
Output is correct |
6 |
Correct |
36 ms |
25168 KB |
Output is correct |
7 |
Execution timed out |
2060 ms |
25168 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
25168 KB |
Output is correct |
2 |
Correct |
39 ms |
25268 KB |
Output is correct |
3 |
Correct |
36 ms |
25168 KB |
Output is correct |
4 |
Correct |
35 ms |
25168 KB |
Output is correct |
5 |
Correct |
36 ms |
25276 KB |
Output is correct |
6 |
Correct |
36 ms |
25168 KB |
Output is correct |
7 |
Execution timed out |
2060 ms |
25168 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |