// #ifdef __AVX2__
// #pragma GCC target "avx2"
// #endif
// #pragma GCC optimize "O3"
// #pragma GCC optimize "unroll-loops"
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define int long long
#define elif else if
#define all(l) begin(l),end(l)
#define rall(l) rbegin(l),rend(l)
#define append push_back
#define print(l) for(auto i:l) cout<<i<<' '; cout<<endl;
#define pprint(a,b) cout<<a<<' '<<b<<endl;
#define inp(l) for(auto &i:l) cin>>i;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pai make_pair
#define endl "\n"
#define pii pair<int,int>
#define fi first
#define se second
#define vec vector
// const int mod=998244353;
const int mod1=998244353;
const int mod=1e9+7;
const int N=2e5+5;
struct node{
int mi,ma,mi1,ma1;
int lz,par;
int li,ri;
node* ch[2];
node(){
lz=par=0;
mi=mi1=3e17;
ma=ma1=-3e17;
ch[0]=ch[1]=NULL;
}
void init(int l,int r){
li=l;
ri=r;
}
void set(int i,int v){
if(v%2){
mi1=min(mi1,v);
ma1=max(ma1,v);
}
else{
mi=min(mi,v);
ma=max(ma,v);
}
if(li==ri) return;
int m=(li+ri)/2;
if(i<=m){
if(ch[0]==NULL){
ch[0]=new node;
ch[0]->init(li,m);
}
ch[0]->set(i,v);
}
else{
if(ch[1]==NULL){
ch[1]=new node;
ch[1]->init(m+1,ri);
}
ch[1]->set(i,v);
}
}
void upd(int l,int r,int v){
if(l<=li and ri<=r){
lz+=v;
return;
}
int m=(li+ri)/2;
if(l<=m) ch[0]->upd(l,r,v);
if(r>m) ch[1]->upd(l,r,v);
mi=mi1=3e17;
ma=ma1=-3e17;
if(ch[0]!=NULL){
int g=(*ch[0]).lz;
if((g%2)==0){
mi=min(mi,(*ch[0]).mi+g);
ma=max(ma,(*ch[0]).ma+g);
mi1=min(mi1,(*ch[0]).mi1+g);
ma1=max(ma1,(*ch[0]).ma1+g);
}
else{
mi=min(mi,(*ch[0]).mi1+g);
ma=max(ma,(*ch[0]).ma1+g);
mi1=min(mi1,(*ch[0]).mi+g);
ma1=max(ma1,(*ch[0]).ma+g);
}
}
if(ch[1]!=NULL){
int g=(*ch[1]).lz;
if((g%2)==0){
mi=min(mi,(*ch[1]).mi+g);
ma=max(ma,(*ch[1]).ma+g);
mi1=min(mi1,(*ch[1]).mi1+g);
ma1=max(ma1,(*ch[1]).ma1+g);
}
else{
mi=min(mi,(*ch[1]).mi1+g);
ma=max(ma,(*ch[1]).ma1+g);
mi1=min(mi1,(*ch[1]).mi+g);
ma1=max(ma1,(*ch[1]).ma+g);
}
}
}
pii qu(int l,int r){
par=lz%2;
if(l<=li and ri<=r){
if(par==1) return pai(mi1+lz,ma+lz);
else return pai(mi+lz,ma1+lz);
}
pii a=pai(3e17,-3e17);
if(lz>0 and li!=ri){
if(ch[0]==NULL) ch[0]=new node;
if(ch[1]==NULL) ch[1]=new node;
(*ch[0]).lz+=lz;
(*ch[1]).lz+=lz;
}
lz=0;
int m=(li+ri)/2;
if(l<=m){
pii b=ch[0]->qu(l,r);
a.fi=min(a.fi,b.fi);
a.se=max(a.se,b.se);
}
if(r>m){
pii b=ch[1]->qu(l,r);
a.fi=min(a.fi,b.fi);
a.se=max(a.se,b.se);
}
if(ch[0]!=NULL){
int g=(*ch[0]).lz;
if((g%2)==0){
mi=min(mi,(*ch[0]).mi+g);
ma=max(ma,(*ch[0]).ma+g);
mi1=min(mi1,(*ch[0]).mi1+g);
ma1=max(ma1,(*ch[0]).ma1+g);
}
else{
mi=min(mi,(*ch[0]).mi1+g);
ma=max(ma,(*ch[0]).ma1+g);
mi1=min(mi1,(*ch[0]).mi+g);
ma1=max(ma1,(*ch[0]).ma+g);
}
}
return a;
}
};
node root;
int iter=1,itera=1;
void solve(){
int n;
cin>>n;
vec<int>a(n);
inp(a);
root.init(0,n+2);
for(int i=0;i<n;i++){
root.set(i+1,a[i]);
}
int q;
cin>>q;
for(int i=0;i<q;i++){
int t;
cin>>t;
int l,r;
cin>>l>>r;
// cout<<t<<' '<<l<<' '<<r<<endl;
if(t==0){
int v;
cin>>v;
root.upd(l,r,v);
}
else{
pii b=root.qu(l,r);
if(b.fi>=1e17) cout<<"-1 ";
else cout<<b.fi<<' ';
if(b.se<=-1e17) cout<<"-1\n";
else cout<<b.se<<endl;
}
}
}
signed main(){
// freopen("","r",stdin);
// freopen("","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout<<fixed<<setprecision(20);
// cin>>itera;
for(iter=1;iter<=itera;iter++) solve();
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |