/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 324.0 KiB
#3 Accepted 615ms 4.809 MiB
#4 Accepted 441ms 4.312 MiB
#5 Accepted 396ms 4.348 MiB
#6 Accepted 390ms 4.344 MiB
#7 Accepted 1ms 320.0 KiB
#8 Accepted 1ms 532.0 KiB
#9 Accepted 611ms 4.559 MiB
#10 Accepted 496ms 4.273 MiB

Code

// Segment Tree 

#include<bits/stdc++.h>
#define ll long long
using namespace std;
 
const int mx = 2e5+20;

int tree[mx * 4] , arr[mx], a[mx];

void build(int node, int b, int e){
	if (b == e){
		tree[node] = arr[b];
		return;
	}
	int left = node * 2;
	int right = node * 2 + 1;
	int mid = (b + e) >> 1;

	build(left, b, mid);
	build(right, mid + 1, e);
	//int 
	tree[node] = min(tree[left], tree[right]);
}

int query(int node, int b, int e, int i, int j){
	if (b >= i && e <= j){
		return tree[node];
	}
	if (e < i || b > j){
		return 1;
	}
	int left = node << 1;
	int right = (node << 1)+1;
	int mid = (b + e) >> 1;
	
	int leftMax = query(left, b, mid, i , j);
	int rightMax = query(right, mid + 1, e, i, j);
	
	return min(leftMax, rightMax);
}

void update(int node, int b, int e, int index, int value){
	if (b >= index && e <= index){
		tree[node] = value;
		return;
	}
	if(b > index || e < index){
		return;
	}
	int left = node * 2;
	int right = node * 2 + 1;
	int mid = (b + e) >> 1;

	update(left, b, mid, index, value);
	update(right, mid + 1, e , index , value);

	tree[node] = min(tree[left], tree[right]);
}

int main(){
  int n, q, m;
  cin>>n;a[n+1]=1e9;
  for (int i = 0; i <= n+1; i++) arr[i] = 1;
  for(int i = 1; i <= n; i++){
   	cin>>a[i];
   	if (a[i] < a[i - 1]) arr[i] = 0;
  }
  build(1, 1, n);
  cin >> q;
  while (q--){
    cin >> m;
    if (m == 1){
      int idx, x;
      cin >> idx >> x;
      
      if (x >= a[idx-1]){
        update(1,1,n,idx,1);
        //if (idx<n){
          if(x<=a[idx+1])update(1,1,n,idx+1,1);
          else update(1,1,n,idx+1,0);
       // }
      } else {
        if (x<=a[idx+1]) update(1,1,n,idx+1,1);
        update(1,1,n,idx,0);
      }
      a[idx] = x;
    } else {
      int L, R; 
      cin >> L >> R;
      if (L == R || (L+1==R && a[L]<=a[R])){
        cout << "YES" << endl;
        continue;
      }
      if(a[L]>a[L+1]){
        cout<<"NO"<<endl;
        continue;
      }
      int ok = query(1, 1, n, L+1, R);
      if (ok == 1) cout << "YES" << endl;
      else cout << "NO" << endl;
    }
  }
  /*cout<< query(1, 1, n, 2, 5)<<endl;
  update(1, 1, n, 4, 2);
  cout<<query(1,1,n,3,3);*/
}

Information

Submit By
Type
Submission
Problem
P1085 Sorted or !Sorted
Contest
Bangladesh 2.0
Language
C++17 (G++ 13.2.0)
Submit At
2024-08-16 17:35:49
Judged At
2024-11-11 03:11:16
Judged By
Score
100
Total Time
615ms
Peak Memory
4.809 MiB