Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define OO 1e9
- using namespace std;
- const int N = 1e6 + 500;
- int a[N] ,Seg[N*5] ,Lazy[N*6] ,n ,m;
- void build(int p=1 , int L=0 ,int R=n-1){
- if( L == R ){
- Seg[p] = a[L];
- return;
- }
- int Mid = (L + R) >> 1;
- build(p*2 , L , Mid);
- build(p*2+1 , Mid+1 , R);
- Seg[p] = min( Seg[p*2] , Seg[p*2+1] );
- }
- void pushLazy(int p){
- if(!Lazy[p]) return;
- Seg[p] += Lazy[p];
- Lazy[p*2] += Lazy[p];
- Lazy[p*2+1] += Lazy[p];
- Lazy[p] = 0;
- }
- void lazyUpdate(int i , int j ,int val , int L=0 , int R=n-1 , int p=1){
- pushLazy(p);
- if( R < i || L > j ) return;
- if( R <= j && L >= i){
- Lazy[p] += val;
- pushLazy(p);
- return;
- }
- int Mid = (L + R) >> 1;
- lazyUpdate(i,j,val,L,Mid,p*2);
- lazyUpdate(i,j,val,Mid+1,R,p*2+1);
- }
- int rmq(int i , int j , int L=0 , int R=n-1 ,int p=1){
- pushLazy(p);
- if( R < i || L > j ) return +OO;
- if( L >= i && R <= j) return Seg[p];
- int Mid = (L + R) >> 1;
- int c1 = rmq(i ,j ,L ,Mid ,p*2);
- int c2 = rmq(i ,j ,Mid+1 ,R ,p*2+1);
- return min(c1,c2);
- }
- int main()
- {
- fstream f;
- cin >> n;
- for(int i=0 ; i<n ; i++) cin >> a[i];
- build();
- cin >> m;
- f.open("in.txt" , ios::out);
- while(m--){
- int c=0;
- char ch[100] = "";
- fflush(stdin);gets(ch);
- for(int i=0 ; i<strlen(ch) ; i++)
- if(ch[i] == ' ') c++;
- f << c << ' ' <<ch << "\n";
- }f.close();
- f.open("in.txt" , ios::in);
- int c;
- while(f >> c){
- int l1 ,l2 ,r1 ,r2 ,x;
- if(c == 1){
- f >> l1 >> r1;
- if(l1 < r1){
- cout << rmq(l1,r1) << endl;
- }else{
- l2 = 0;
- r2 = n-1;
- cout << min( rmq(l2 ,r1) , rmq(l1 ,r2) )<< endl;
- }
- }else if(c == 2){
- f >> l1 >> r1 >> x;
- if(l1 < r1){
- lazyUpdate(l1,r1,x);
- }else{
- l2 = 0;
- r2 = n-1;
- lazyUpdate(l2,r1,x);
- lazyUpdate(l1,r2,x);
- }
- }
- }f.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement