Cod sursa(job #3194473)

Utilizator poparobertpoparobert poparobert Data 18 ianuarie 2024 09:54:01
Problema Arbori de intervale Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 6.88 kb
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <cmath>
#include <string>
#include <deque>
#include <cstring>
#include <ctime>
#include <random>
#include <chrono>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
//#include <windows.h>
#include <complex>
#pragma GCC optimize("fast-math")
using namespace std;
using namespace __gnu_pbds;
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define lsb(x) ((x) & (-x))
#define msb(x) ((x) == 0 ? 0 : (1 << (64 - __builtin_clzll(x) - 1)))
#define DX return cout<<ans[0],void();
#define XD return cout<<ans[1],void();
#define bleacs(x) return cout<<x<<'\n',void();
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
mt19937_64 rng(chrono :: steady_clock :: now().time_since_epoch().count());

const size_t fixed_random = rng();

clock_t start_time = clock(), end_time;

ll random_seed(ll modulo) {
    return rng() % modulo;
}

template <typename T>inline void hash_combine(size_t& seed, const T& value) {
    seed ^= hash<T>{}(value) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}

struct pair_hash {
    template <typename T1, typename T2>
    size_t operator () (const pair<T1, T2>& p) const {
        size_t seed = fixed_random;

        hash_combine(seed, p.first);
        hash_combine(seed, p.second);

        return seed;
    }
};

struct normal_hash {
    template <typename T>
    size_t operator () (const T& p) const {
        size_t seed = fixed_random;

        hash_combine(seed, p);

        return seed;
    };
};
template<typename T,typename V>istream& operator>>(istream&in,pair<T,V>&a){in>>a.first>>a.second;return in;}
template<typename T,typename V>ostream& operator<<(ostream&out,const pair<T,V>&a){out<<a.first<<' '<<a.second;return out;}
template<typename T>istream& operator>>(istream&in,vector<T> &a){for(typename vector<T>::iterator i=a.begin();i!=a.end();i++)cin>>*i;return in;}
template<typename T>ostream& operator<<(ostream&out,const vector<T>&a){for(T x:a)out<<x<<' ';return out;}
template<typename T,typename V,typename X,typename Z> pair<T,V>operator+(const pair<T,V> &a,const pair<X,Z>&b){return {a.first+b.first,a.second+b.second};}
template<typename T,typename V,typename X,typename Z> pair<T,V>operator-(const pair<T,V> &a,const pair<X,Z>&b){return {a.first-b.first,a.second-b.second};}
template<typename T,typename V> vector<T> operator+(const vector<T>&a,const vector<V> &b){vector<T> rez;if(a.size()!=b.size())return rez;for(ll i=0;i<a.size();i++)rez.pb(a[i]+b[i]);return rez;}
template<typename T,typename V> T operator+=(T &a,const V &b){return a=a+b;}
ll gcd(ll a,ll b){ll r;while(b)r=a%b,a=b,b=r;return a;}
ll mod=1e9+7;
ll inf=3*1e18;
class AIB{
    vector<ll> v;
public:
    AIB(ll n){v.resize(n+1);}
    void add(ll p,ll val=1){for(;p<v.size();p+=lsb(p))v[p]+=val;}
    ll ask(ll p){ll rez=0;for(;p;p-=lsb(p))rez+=v[p];return rez;}
};
ll fastexp(ll b,ll e,ll mod=mod){
    ll rez=1;
    while(e)
    {
        if(e&1)rez=rez*b%mod;
        b=b*b%mod;
        e>>=1;
    }
    return rez;
}
string pi="3141592653589793238462643383279502884197169399375105820974944";
class AINTaddminmax
{
    ll n;
    vector<ll>mn,mx,lazy;
    void build(vector<ll>&a,ll st,ll dr,ll p)
    {
        lazy[p]=0;
        if(st==dr){return mn[p]=mx[p]=a[st],void();}
        ll mid=(st+dr)/2;build(a,st,mid,p<<1);build(a,mid+1,dr,p<<1|1);mn[p]=min(mn[p<<1],mn[p<<1|1]);mx[p]=max(mx[p<<1],mx[p<<1|1]);
    }
    void push(ll p){mn[p]+=lazy[p],mx[p]+=lazy[p],lazy[p<<1]+=lazy[p],lazy[p<<1|1]+=lazy[p],lazy[p]=0;}
    ll getvalmn(ll p){return mn[p]+lazy[p];}
    ll getvalmx(ll p){return mx[p]+lazy[p];}
    void add(ll st,ll dr,ll p,ll l,ll r,ll val)
    {
        if(l<=st&&dr<=r){return lazy[p]+=val,void();}
        ll mid=(st+dr)/2;push(p);
        if(l<=mid)add(st,mid,p<<1,l,r,val);
        if(r>mid)add(mid+1,dr,p<<1|1,l,r,val);
        mx[p]=max(getvalmx(p<<1),getvalmx(p<<1|1));
        mn[p]=min(getvalmn(p<<1),getvalmn(p<<1|1));
    }
    pll ask(ll st,ll dr,ll p,ll l,ll r)
    {
        //first mn second mx
        if(l<=st&&dr<=r){return {getvalmn(p),getvalmx(p)};}
        ll mid=(st+dr)/2;
        push(p);pll a={0,0},b={0,0};
        if(l<=mid)a=ask(st,mid,p<<1,l,r);
        if(r>mid)b=ask(mid+1,dr,p<<1|1,l,r);
        return {min(a.first,b.first),max(a.second,b.second)};
    }
public:
    AINTaddminmax(ll x=0){n=x,mn.resize(4*x+5),mx.resize(4*x+5),lazy.resize(4*x+5);}
    void build(vector<ll>&a){build(a,1,n,1);}
    void add(ll l,ll r,ll val){if(l<=r)add(1,n,1,l,r,val);}
    ll askmn(ll l,ll r){if(l>r)return 1e15;return ask(1,n,1,l,r).first;}
    ll askmx(ll l,ll r){if(l>r)return -1e15;return ask(1,n,1,l,r).second;}
};
void addmod(ll &x,ll y,ll modu=mod)
{
    x+=y;
    if(x>=mod)x-=modu;
    if(x<0)x+=modu;
}
void multmod(ll &x,ll y,ll modu=mod)
{
    x=x*y%modu;
}
string ans[]={"NO\n","YES\n"};
ll maxitaxi;
vector<vector<ll>>divs;
vector<ll>fact,inv,primi;
void eratostene(bool doarprime=0){
    ll i,j;
    divs.resize(maxitaxi+1);
    for(i=1;i<=maxitaxi;i++)
    {
        if(doarprime&&divs[i].size()>1)continue;
        if(divs[i].size()==1)primi.pb(i);
        for(j=i;j<=maxitaxi;j+=i)divs[j].pb(i);
    }
}
void precalcfact(){
    ll i,j;
    fact.resize(maxitaxi+1);
    inv.resize(maxitaxi+1);
    fact[0]=inv[0]=1;
    for(i=1;i<=maxitaxi;i++)
    {
        fact[i]=fact[i-1]*i%mod;
        inv[i]=fastexp(fact[i],mod-2,mod);
    }
}
ll comb(ll n,ll k){
    if(k<0||k>n)
        return 0ll;
    return fact[n]*inv[k]%mod*inv[n-k]%mod;
}
ll catalan(ll n){
    return comb(2*n,n)*fastexp(n+1,mod-2)%mod;
}
void constsetup()
{
    maxitaxi=2e5;
    mod=998244353;
    eratostene();
    precalcfact();
}
void setup()
{

}
void solve(ll T)
{
    ll n,m,i,j,k,l,x,y,z,t,q;
    cin>>n>>q;
    vector<ll>a(n+1);
    AINTaddminmax alex(n);
    for(i=1;i<=n;i++)
        cin>>a[i];
    alex.build(a);
    while(q--)
    {
        cin>>x>>y>>z;
        switch(x)
        {
        case 0:
            cout<<alex.askmx(y,z)<<'\n';
            break;
        case 1:
            alex.add(y,y,z-a[y]);
            a[y]=z;
            break;
        }
    }
}
int main()
{
    freopen("arbint.in","r",stdin);
    freopen("arbint.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll c=0;
    //constsetup();
    setup();
    //ll t;cin>>t;while(t--)
		solve(++c);
    return 0;
}