Submission #1133389

#TimeUsernameProblemLanguageResultExecution timeMemory
1133389jpfr12Simple (info1cup19_simple)C++20
30 / 100
284 ms30416 KiB
#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long int ull;
using namespace std;
const ll MOD = (ll)1e9+7;
int MAXN = 1e6;

//classes
class SegTree{
public:
  int left, right;
  ll num;
  ll lazy = 0;
  ll mx_odd = -1e18;
  ll mn_even = 1e18;
  SegTree* leftChild = NULL;
  SegTree* rightChild = NULL;

  SegTree(vector<ll>& vec, int l, int r){
    left = l;
    right = r;
    if(l == r){
      num = vec[l];
      if(num%2 == 1) mx_odd = num;
      else mn_even = num;
      return;
    }
    int mid = l+(r-l)/2;
    leftChild = new SegTree(vec, l, mid);
    rightChild = new SegTree(vec, mid+1, r);
    num = leftChild->num + rightChild->num;
    mx_odd = max(leftChild->mx_odd, rightChild->mx_odd);
    mn_even = min(leftChild->mn_even, rightChild->mn_even);
  }


  void update(int l, int r, ll val){
    if(left > r || right < l) return;
    if(left >= l && right <= r){
      num = num + (right-left+1)* val;
      lazy = val;
      return;
    }
    leftChild->update(l, r, val);
    rightChild->update(l, r, val);
    num = leftChild->num + rightChild->num;
  }


  ll getMxOdd(int l, int r){
    if(left > r || right < l) return -1e18;
    if(left >= l && right <= r) return mx_odd;
    return max(leftChild->getMxOdd(l, r), rightChild->getMxOdd(l, r));
  }

  ll getMnEven(int l, int r){
    if(left > r || right < l) return 1e18;
    if(left >= l && right <= r) return mn_even;
    return min(leftChild->getMnEven(l, r), rightChild->getMnEven(l, r));
  }

};

//global
int N;
vector<ll> vec;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  //ifstream fin("hps.in");
  //ofstream fout("hps.out");
  //stop
  cin >> N;
  vec.assign(N, 0);
  for(ll& i: vec){
    cin >> i;
  }
  SegTree* st = new SegTree(vec, 0 , N-1);
  int T;
  cin >> T;
  while(T--){
    int ty;
    cin >> ty;
    if(ty == 0){
      int l, r, val;
      cin >> l >> r >> val;
    }
    else{
      int left, right;
      cin >> left >> right;
      ll even = st->getMnEven(left-1, right-1);
      ll odd = st->getMxOdd(left-1, right-1);
      cout << (even == 1e18 ? -1:even ) << " " << (odd == -1e18 ? -1: odd) << '\n';
    }

  }
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...