fork download
  1. /*
  2.   Author: Nguyen Nhut Truong
  3.   From Chuyen Tien Giang High School For The Gifed
  4. */
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7.  
  8. //#define int long long
  9. #define start signed main
  10. #define fi first
  11. #define se second
  12. #define pb push_back
  13. #define eb emplace_back
  14. #define il pair<int,ll>
  15. #define ii pair<int,int>
  16. #define len(s) (int)s.size()
  17. #define all(s) (s).begin(),(s).end()
  18. #define OpenFile(Name) if (fopen(Name".inp","r")) freopen(Name".inp","r",stdin),freopen(Name".out","w",stdout);
  19.  
  20. #define MASK(x) ((1LL)<<(x))
  21. #define Bit(x,i) (((x)>>(i))&1)
  22. #define Countbit(x) __builtin_popcountll(x)
  23.  
  24. typedef long long ll;
  25. typedef long double ld;
  26.  
  27. int dx[]={1,-1,0,0,-1,1,1,-1};
  28. int dy[]={0,0,1,-1,-1,-1,1,1};
  29.  
  30. template <class C> bool Minimize(C &a, C b) { if (a>b) { a=b; return true; } return false;}
  31. template <class C> bool Maximize(C &a, C b) { if (a<b) { a=b; return true; } return false;}
  32.  
  33. inline ll add(ll a,ll b,ll c) { return (a+b)%c; };
  34. inline ll sub(ll a,ll b,ll c) { return (a-b+c)%c; };
  35. inline ll mul(ll a,ll b,ll c) { return ((a%c)*(b%c))%c; };
  36.  
  37. mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
  38.  
  39. ll rand(ll l,ll r){
  40. assert(l<=r);
  41. return l+rd()%(r-l+1);
  42. }
  43.  
  44. void MakeInp() {
  45. ofstream cout("Task.inp");
  46.  
  47. cout.close();
  48. }
  49.  
  50. /// Constant Limit
  51.  
  52. const int N=500+5,M=500+5,INF=1e9,lim=1e6;
  53. const int block=448,base=31;
  54.  
  55. ll Mod=1e9+7,Mod_base=1777777777,LNF=1e18;
  56.  
  57. ///____________________________________________________________________________________________________________________________
  58.  
  59. int a[N],maxi[M][M],mini[M][M],dp[N];
  60. int n,q;
  61.  
  62. void init() {
  63. memset(maxi,-0x3f,sizeof maxi);
  64. memset(mini,0x3f,sizeof mini);
  65.  
  66. for (int i=1;i<=n;++i)
  67. for (int j=i;j<=n;++j) {
  68. maxi[i][j]=max(maxi[i][j-1],a[j]);
  69. mini[i][j]=min(mini[i][j-1],a[j]);
  70. }
  71. }
  72.  
  73. start() {
  74. ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  75. OpenFile("TASK");
  76.  
  77. cin>>n>>q;
  78. for (int i=1;i<=n;++i) cin>>a[i];
  79.  
  80. init();
  81. while (q--) {
  82. int op,l,r; cin>>op>>l>>r;
  83. if (op==1) {
  84. int x; cin>>x;
  85. for (int i=l;i<=r;++i) a[i]+=x;
  86. init();
  87. } else {
  88. memset(dp,0,sizeof dp);
  89.  
  90. for (int i=l;i<=r;++i) {
  91. dp[i]=dp[i-1];
  92. for (int j=l;j<=i;++j) Maximize(dp[i],maxi[j][i]-mini[j][i]+dp[j-1]);
  93. }
  94.  
  95. cout<<dp[r]<<'\n';
  96. }
  97. }
  98.  
  99.  
  100.  
  101.  
  102. //cerr<<"\nBien dich thanh cong\nTime: "<<(1.0*clock()/CLOCKS_PER_SEC)<<" s\n";
  103. return 0;
  104. }
  105.  
  106.  
Success #stdin #stdout 0.01s 5472KB
stdin
Standard input is empty
stdout
Standard output is empty