Submission #1318501

#TimeUsernameProblemLanguageResultExecution timeMemory
1318501m.zeeshanrashidSimple (info1cup19_simple)C++20
30 / 100
277 ms36676 KiB
// #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 li,ri;
	int mi,ma,mi1,ma1;
	int lz;
	node* ch[2];
	node(){
		mi=mi1=1e18;
		ma=ma1=-1e18;
		lz=0;
		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)>>1;
		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 lazy(int x){
		lz+=x;
		mi+=x;
		ma+=x;
		mi1+=x;
		ma1+=x;
		if(x%2){
			swap(mi,mi1);
			swap(ma,ma1);
		}
	}
	void upd(int l,int r,int v){
		if(l<=li and ri<=r){
			lazy(v);
			return;
		}
		int m=(li+ri)>>1;
		if(l<=m) ch[0]->upd(l,r,v);
		if(r>m) ch[1]->upd(l,r,v);
		mi=mi1=1e18;
		ma=ma1=-1e18;
		for(auto &i:ch){
			if(i==NULL) continue;
			node a=*i;
			mi=min(a.mi,mi);
			mi1=min(mi1,a.mi1);
			ma=max(ma,a.ma);
			ma1=max(ma1,a.ma1);
		}
	}
	pii qu(int l,int r){
		if(l<=li and ri<=r) return pai(mi,ma1);
		for(auto i:ch) if(i!=NULL) i->lazy(lz);
		lz=0;
		pii a=pai(1e18,-1e18);
		int m=(li+ri)>>1;
		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);
		}
		return a;
	}
};

int iter=1,itera=1;
void solve(){
	int n;
	cin>>n;
	vec<int>a(n);
	inp(a);
	node seg;
	seg.init(1,n);
	for(int i=0;i<n;i++) seg.set(i+1,a[i]);
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		int t,l,r,v;
		cin>>t>>l>>r;
		if(t==0){
			cin>>v;
			seg.upd(l,r,v);
		}
		else{
			pii a=seg.qu(l,r);
			if(a.fi>=1e17) cout<<"-1 ";
			else cout<<a.fi<<' ';
			if(a.se<=-1e17) cout<<"-1\n";
			else cout<<a.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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...