Submission #837075

# Submission time Handle Problem Language Result Execution time Memory
837075 2023-08-24T21:25:14 Z MODDI Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
93 ms 16428 KB
    #include <bits/stdc++.h>
    using namespace std;
    #define pb push_back
    #define mp make_pair
    typedef long long ll;
    typedef pair<long long, long long> pll;
    typedef pair<int,int> pii;
    typedef vector<long long> vl;
    typedef vector<int> vi;
    int n, m;
    vi arr;
    struct Node{
    	int pref_max;
    	int val;
    	// maximize pref_max + val;
    } tree[4 * 100100];
    Node combine(Node a, Node b){
    	Node ret = a;
    	if(a.pref_max + b.val >= ret.pref_max + ret.val && a.pref_max > b.val){
    		ret.pref_max = a.pref_max;
    		ret.val = b.val;
    	}
    	if(b.pref_max + b.val >= ret.pref_max + ret.val)
    		ret = b;
    	if(a.val + b.val >= ret.pref_max + ret.val && a.val > b.val){
    		ret.pref_max = a.val;
    		ret.val = b.val;
    	}
    	if(ret.pref_max == 0){
			ret.val = max(a.val, b.val);
		}
    	return ret;
    }
    void build(int node, int l, int r){
    	if(l == r){
    		Node s;
    		s.pref_max = 0;
    		s.val = arr[l];
    		tree[node] = s;
    	}
    	else{
    		int mid = (l + r) / 2;
    		build(node*2, l, mid);
    		build(node*2+1, mid+1, r);
    		tree[node] = combine(tree[node*2], tree[node*2+1]);
    	}
    }
    Node query(int node, int l, int r, int L, int R){
    	if(r < L || l > R){
    		Node empty;
    		empty.pref_max = empty.val = -1;
    		return empty;
    	}
    	if(L <= l && r <= R){
    		return tree[node];
    	}
    	int mid = (l + r) / 2;
    	Node left = query(node*2, l, mid, L, R);
    	Node right = query(node*2+1, mid+1, r, L, R);
    	if(left.val == -1)	return right;
    	if(right.val == -1)	return left;
    	Node tog = combine(left, right);
    	//cout<<left.pref_max<<" "<<left.val<<" "<<right.pref_max<<" "<<right.val<<" "<<tog.pref_max<<" "<<tog.val<<endl;
    	return tog;
    }
    int main(){
    	ios_base::sync_with_stdio(false);
    	cin.tie(0);
    	cin>>n>>m;
    	for(int i = 0; i < n; i++){
    		int a;
    		cin>>a;
    		arr.pb(a);
    	}
    	vi pregrada;
    	for(int i = 0; i < n; i++){
    		int j =i;
    		pregrada.pb(i);
    		while(j + 1 < n && arr[j] <= arr[j+1]){
    			j++;
    		}
    		if(j == n-1)	pregrada.pb(n);
    		i = j;
    	}
    	build(1, 0, n-1);
    	while(m--){
    		int l, r, k;
    		cin>>l>>r>>k;
    		l--;r--;
    		int left_border = -1, right_border = -1;
    		int levo = 0, desno = pregrada.size()-1;
    		while(levo <= desno){
    			int mid = (levo + desno) / 2;
    			if(pregrada[mid] <= l){
    				left_border = mid;
    				levo = mid + 1;
    			}
    			else
    				desno = mid - 1;
    		}
    		levo = 0; desno = pregrada.size()-1;
    		while(levo <= desno){
    			int mid = (levo + desno) / 2;
    			if(pregrada[mid] > r){
    				right_border = mid;
    				desno = mid - 1;
    			}
    			else
    				levo = mid + 1;
    		}
    		
    		if(abs(left_border - right_border) == 1)
    			cout<<1<<"\n";
    		else{
    			Node here = query(1, 0, n-1, l, r);
				//cout<<l<<" "<<r<<" "<<here.pref_max<<" "<<here.val<<endl;
    			if(here.pref_max + here.val > k)	cout<<0<<"\n";
    			else cout<<1<<"\n";
    		}
    	}
    	return 0;
    }
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 87 ms 16428 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 93 ms 3368 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -