답안 #497891

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
497891 2021-12-24T04:25:49 Z Ierus Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
1528 ms 129716 KB
#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
using namespace std;
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
#define F first
#define S second
#define sz(x) (int)x.size()
#define int long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define NFS ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
const int E = 1e6+777;
const long long inf = 1e18+777;
const int N = 1e5+777;
const int MOD = 1e9+7;
const bool I = 1;
int n, que, a[E], t[E<<2], ans[E];
void update(int pos, int val, int v, int tl, int tr){
	if(tl == tr){
		t[v] = max(pos, t[v]);
		return;
	}
	int tm = (tl + tr) / 2;
	if(pos <= tm) update(pos, val, v<<1, tl, tm);
	else update(pos, val, v<<1|1, tm+1, tr);
	t[v] = max(t[v<<1], t[v<<1|1]);
}
int get(int l, int r, int v, int tl, int tr){
	if(l <= tl && tr <= r) return t[v];
	if(tl > r || tr < l) return -LLONG_MAX;
	int tm = (tl + tr) / 2;
	return max(get(l, r, v<<1, tl, tm), get(l, r, v<<1|1, tm+1, tr));
}
struct D{
	int l, x, i;
};
vector<D> g[N];
signed main(){
	cin >> n >> que;
	for(int i = 1; i <= n; ++i){
		cin >> a[i];
	}
	for(int l, r, x, i = 1; i <= que; ++i){
		cin >> l >> r >> x;
		g[r].pb({l, x, i});
	}
	deque<pair<int,int>> st;
	for(int i = 1; i <= n; ++i){
		while(!st.empty() && st.back().F < a[i]) st.pop_back();
//		cerr << i << ": " << a[i];
		if(!st.empty()){	
//			cerr << " it: " << st.back().F << '\n';
			update(st.back().S, st.back().F + a[i], 1, 1, n);
		}
//		else cerr << "it: " << "-1\n";
		for(auto to : g[i]){
			int cur = get(to.l, i, 1, 1, n);
			ans[to.i] = (cur <= to.x);
		}
		st.push_back({a[i], i});
	}
	for(int i = 1; i <= que; ++i){
		cout << ans[i] << '\n';
	}
}











# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Incorrect 3 ms 2636 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Incorrect 3 ms 2636 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1528 ms 129716 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 170 ms 9668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Incorrect 3 ms 2636 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2636 KB Output is correct
3 Incorrect 3 ms 2636 KB Output isn't correct
4 Halted 0 ms 0 KB -