답안 #879588

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879588 2023-11-27T16:41:11 Z Elvin_Fritl Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
1202 ms 161908 KB
#include <bits/stdc++.h>
using namespace std;
 
#define io                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);

 
typedef long long ll;
 
ll bp(ll n,ll m){
    if(m == 0){
        return 1;
    }
    if(m == 1){
        return n;
    }
    if(m%2==0){
        return bp(n*n,m/2);
    }
    return n*bp(n,m-1);
}

 
const int N =  1e6 + 545, M = 33, inf = 1e9 + 99;
const ll inff = 1e12;

struct segtree {

	ll tree[N * 4];
	ll get(int v,int l, int r, int ml , int mr) {
		if(l > mr || r < ml || l > r) {
			return 0;
		}
		if(ml <= l && r <= mr) {
			return tree[v];
		}
		int mid = (l + r)/2;
		return max(get(v*2 , l, mid , ml, mr), get(v*2 + 1 , mid + 1, r , ml, mr));
	}
	void update(int v,int l,int r,int pos ,ll val) {
		if(l > r) {
			return;
		}
		if(l == r) {
			tree[v] = max(val , tree[v]);
			return;
		}
		int mid = (l + r)/2;
		if(pos <= mid) {
			update(v*2 , l , mid , pos , mid);
		}
		else {
			update(v*2 + 1, mid + 1 , r , pos , mid);
		}
		tree[v] = max(tree[v * 2], tree[v * 2 + 1]);
	}
};

segtree S;

int main() {
	int n, q;
    cin >> n >> q;
    vector<pair<pair<ll , ll > , ll>> qu[n + 1]; 
	ll a[n + 1];
	vector<ll> ans(q + 1 , 0);
    for(int i=1;i<=n;i++) {
        cin >> a[i];
    }
    for(int i=1;i<=q;i++) {
        ll l, r, k; 
        cin >> l >> r >> k;
        qu[r].push_back({{l, k}, i});
    }
    vector<ll> v;
	for(ll r=1;r<=n;r++) {
		while(! v.size() > 0 && a[v.back()] <= a[r])  {
			v.pop_back();
		}
		if( v.size() > 0 ) {
			S.update(1 ,1 , N , v.back(), a[r] + a[v.back()]); 
		}
		for(auto &i : qu[r]) {
			ll l = i.first.first, k = i.first.second, ind = i.second;
			ll tmp = S.get(1 , 1 , N  , l, r);
			if(tmp <= k){ 
				ans[ind] = 1;
			}
		}
		v.push_back(r);
	}
	for(int i=1;i<=q;i++) {
		cout << ans[i] << endl;
	}
    
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:79:20: warning: logical not is only applied to the left hand side of comparison [-Wlogical-not-parentheses]
   79 |   while(! v.size() > 0 && a[v.back()] <= a[r])  {
      |                    ^
sortbooks.cpp:79:9: note: add parentheses around left hand side expression to silence this warning
   79 |   while(! v.size() > 0 && a[v.back()] <= a[r])  {
      |         ^~~~~~~~~~
      |         (         )
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1202 ms 161908 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 84 ms 16224 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -