Submission #465110

# Submission time Handle Problem Language Result Execution time Memory
465110 2021-08-15T08:00:00 Z Nihal_9936 Sjeckanje (COCI21_sjeckanje) C++17
110 / 110
514 ms 29648 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds; 

template <typename num_t>
using ordered_set = tree<num_t, null_type, less<num_t>, rb_tree_tag, tree_order_statistics_node_update>;
 
#ifdef  pikachu
   #include  "welcome_to_python_is_slower_than_c++_club.h"
#else
    #include <bits/stdc++.h>
     using namespace std;
    #define debug(...) 69
#endif
 
 
template<typename T1, typename T2>istream& operator>>(istream& in, pair<T1, T2>& a) { return in >> a.first >> a.second; }
template<typename T1, typename T2>ostream& operator<<(ostream& out, pair<T1, T2> a) { return out << a.first << " " << a.second;}
template<typename T> void print(T t) { cout << t <<' '; }
template<typename T, typename... Args> void print(T t, Args... args) { print(t);print(args...); }
string operator*=(string& s, int cnt) { string t = s;for (size_t i = 1; i < cnt; i++)s += t;return s; }
string operator*(string s, int cnt) { return s *= cnt; }
 
 
#define int               long long 
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define allr(x)           (x).rbegin(),(x).rend()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define len(x)             (int)((x).size())
#define bk                back()
#define elif              else if
#define add               insert
#define append            push_back
// #define pop               pop_back 
#define str               string
#define in                :
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define vi                vector<int>
#define vii               vector<pii>
#define mi                map<int,int>
#define mii               map<pii,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define rrep(i,a,b)       for(int i=a;i>b;i--)
#define el                 '\n'
#define printl(arg) cout << arg << endl
// #define print(arg) cout << arg
#define inputa(arg) for (auto& e : arg) cin >> e
#define printa(arg) for (auto& e : arg) print(e);
#define printr(arg) { printl(arg);return; }
#define printd(arg) printf("%0.3lf\n", arg)
 
 
const int mod=1e9+7;
// const int INF=1e18;
const int MAX_N= 2e5+10;

 
int n,m,k,x,y,z,t,q,counter;


int s_tree[MAX_N*4][4],lazy[MAX_N*4];
int lazy_def=0;
vi a;
int ans;

void solve(int x,int y,int z,int f,int l,bool bol){
    s_tree[x][0]=0;
    bool diff=false;
    if((a[f]<0 and a[l]>=0) or (a[f]>=0 and a[l]<0)){
        diff=true;
    }
    if (diff){
        if(not bol)
        s_tree[x][0]=max({s_tree[y][0]+s_tree[z][2],s_tree[y][1]+max(s_tree[z][0],s_tree[z][2])});
        s_tree[x][1]=max(s_tree[y][0]+s_tree[z][3],s_tree[y][1]+max(s_tree[z][1],s_tree[z][3]));
        s_tree[x][2]=max(s_tree[y][2]+s_tree[z][2],s_tree[y][3]+max(s_tree[z][0],s_tree[z][2]));
        s_tree[x][3]=max(s_tree[y][2]+s_tree[z][3],s_tree[y][3]+max(s_tree[z][1],s_tree[z][3]));

    }else{
        s_tree[x][0]=max(s_tree[y][0],s_tree[y][1])+max(s_tree[z][0],s_tree[z][2]);
        s_tree[x][2]=max(s_tree[y][2],s_tree[y][3])+max(s_tree[z][0],s_tree[z][2]);
        s_tree[x][1]=max(s_tree[y][0],s_tree[y][1])+max(s_tree[z][1],s_tree[z][3]);
        s_tree[x][3]=max(s_tree[y][2],s_tree[y][3])+max(s_tree[z][1],s_tree[z][3]);
    }

}

void build_seg(int i_tree,int left,int right){
    if(left==right){
        s_tree[i_tree][0]=abs(a[left]);
    }else{
        int  mid=(left+right)/2;
        build_seg(i_tree*2,left,mid);
        build_seg(i_tree*2+1,mid+1,right);
        solve(i_tree,i_tree*2,i_tree*2+1,mid,mid+1,mid==left);
    }

}



void update(int i_tree,int left,int right,int l,int r){
    if(right<l or left>r) return;
    if(l<=left and right<=r){
        s_tree[i_tree][0]=abs(a[left]);
        return;
    }
    int mid=(left+right)/2;
    update(i_tree*2,left,mid,l,r);
    update(i_tree*2+1,mid+1,right,l,r);
    solve(i_tree,i_tree*2,i_tree*2+1,mid,mid+1,mid==left);
}





void code(){
            cin>>n>>m;
            vector<int>ck(n);
            inputa(ck);
            rep(i,1,n) a.append(ck[i]-ck[i-1]);

            build_seg(1,0,n-2);

            while(m--){
                cin>>x>>y>>z;
                x-=2;
                if(x>=0) {
                    a[x]+=z;
                    update(1,0,n-2,x,x);
                }
                y--;
                if(y<n-1){
                    a[y]-=z;
                    update(1,0,n-2,y,y);
                }
                // debug(a);
                // debug(s_tree ,10 , 4);
                cout<<max({s_tree[1][0],s_tree[1][1],s_tree[1][2],s_tree[1][3]})<<el;
            }

           



            


}


signed main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    // freopen("optmilk.in", "r", stdin);
    // freopen("optmilk.out", "w", stdout);

    int t = 1;
    // cin>>t;
    while(t--) code();
    return 0;
}

Compilation message

Main.cpp: In function 'std::string operator*=(std::string&, int)':
Main.cpp:24:75: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 | string operator*=(string& s, int cnt) { string t = s;for (size_t i = 1; i < cnt; i++)s += t;return s; }
      |                                                                         ~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 6 ms 796 KB Output is correct
8 Correct 5 ms 716 KB Output is correct
9 Correct 5 ms 716 KB Output is correct
10 Correct 5 ms 716 KB Output is correct
11 Correct 6 ms 716 KB Output is correct
12 Correct 4 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 6 ms 796 KB Output is correct
8 Correct 5 ms 716 KB Output is correct
9 Correct 5 ms 716 KB Output is correct
10 Correct 5 ms 716 KB Output is correct
11 Correct 6 ms 716 KB Output is correct
12 Correct 4 ms 716 KB Output is correct
13 Correct 472 ms 29124 KB Output is correct
14 Correct 476 ms 29060 KB Output is correct
15 Correct 505 ms 29020 KB Output is correct
16 Correct 485 ms 29064 KB Output is correct
17 Correct 505 ms 28892 KB Output is correct
18 Correct 514 ms 29648 KB Output is correct