Submission #1318463

#TimeUsernameProblemLanguageResultExecution timeMemory
1318463m.zeeshanrashidSimple (info1cup19_simple)C++20
30 / 100
250 ms36748 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 mi,ma,mi1,ma1; int lz; int li,ri; node* ch[2]; node(){ lz=0; mi=mi1=3e17; ma=ma1=-3e17; ch[0]=ch[1]=NULL; } void init(int l,int r){ li=l; ri=r; } void lazy(int v){ if(v%2){ swap(mi,mi1); swap(ma,ma1); } mi+=v; ma+=v; mi1+=v; ma1+=v; lz+=v; } 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){ lazy(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; for(int i=0;i<2;i++){ if(ch[i]==NULL) continue; mi=min(mi,(*ch[i]).mi); ma=max(ma,(*ch[i]).ma); mi1=min(mi1,(*ch[i]).mi1); ma1=max(ma1,(*ch[i]).ma1); } } pii qu(int l,int r){ if(lz!=0 and li!=ri){ if(ch[0]!=NULL) ch[0]->lazy(lz); if(ch[1]!=NULL) ch[1]->lazy(lz); } lz=0; if(li!=ri){ mi=mi1=3e17; ma=ma1=-3e17; for(int i=0;i<2;i++){ if(ch[i]==NULL) continue; mi=min(mi,(*ch[i]).mi); ma=max(ma,(*ch[i]).ma); mi1=min(mi1,(*ch[i]).mi1); ma1=max(ma1,(*ch[i]).ma1); } } if(l<=li and ri<=r){ return pai(mi,ma1); } pii a=pai(3e17,-3e17); 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); } return a; } }; node root; int iter=1,itera=1; void solve(){ int n; cin>>n; vec<int>a(n); inp(a); root.init(1,n); 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; 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; } // cout<<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...