제출 #572105

#제출 시각아이디문제언어결과실행 시간메모리
572105vovamrHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
64 / 100
3056 ms250408 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#define fi first
#define se second
#define ll long long
#define ld long double
#define sz(x) ((int)(x).size())
#define all(x) 	(x).begin(), (x).end()
#define pb push_back
#define mpp make_pair
#define ve vector
using namespace std;
using namespace __gnu_pbds;
template<class T> using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const ll inf = 1e18; const int iinf = 1e9;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T> inline bool chmin(T& a, T b) { return (a > b ? a = b, 1 : 0); }
template <typename T> inline bool chmax(T& a, T b) { return (a < b ? a = b, 1 : 0); }

const int N = 1e6 + 100;

ve<int> t[4 * N];
int mx[4 * N], a[N], answer[4 * N];

inline void build(int v, int vl, int vr) {
	if (vl == vr) {
		mx[v] = a[vl];
		t[v] = ve<int>(1, a[vl]);
		answer[v] = 0;
		return;
	}
	int m = vl + vr >> 1;
	build(2 * v + 1, vl, m);
	build(2 * v + 2, m + 1, vr);
	mx[v] = max(mx[2 * v + 1], mx[2 * v + 2]);
	answer[v] = max(answer[2 * v + 1], answer[2 * v + 2]);
	merge(all(t[2 * v + 1]), all(t[2 * v + 2]), back_inserter(t[v]));
	int ps = lower_bound(all(t[2 * v + 2]), mx[2 * v + 1]) - t[2 * v + 2].begin();
	if (ps != 0) { --ps; chmax(answer[v], mx[2 * v + 1] + t[2 * v + 2][ps]); }
}

inline void get(int v, int vl, int vr, int l, int r, ve<int> &pos) {
	if (l > r) return;
	else if (vl == l && vr == r) return void(pos.pb(v));
	int m = vl + vr >> 1;
	get(2 * v + 1, vl, m, l, min(r, m), pos);
	get(2 * v + 2, m + 1, vr, max(l, m + 1), r, pos);
}

inline void solve() {
	int n, q;
	cin >> n >> q;
	for (int i = 0; i < n; ++i) cin >> a[i];

	build(0, 0, n - 1);

	while (q--) {
		int l, r, k;
		cin >> l >> r >> k, --l, --r;

		ve<int> pos;
		get(0, 0, n - 1, l, r, pos);

		int amx = mx[pos[0]], res = answer[pos[0]];

		for (int i = 1; i < sz(pos); ++i) {
			int v = pos[i];
			int hui = lower_bound(all(t[v]), amx) - t[v].begin();

			if (hui != 0) chmax(res, amx + t[v][hui - 1]);
			chmax(res, answer[v]);
			chmax(amx, mx[v]);
		}
		cout << (k >= res ? 1 : 0) << '\n';
	}
}

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int q = 1; // cin >> q;
	while (q--) solve();
	cerr << fixed << setprecision(3) << "Time execution: " << (double)clock() / CLOCKS_PER_SEC << endl;
}

컴파일 시 표준 에러 (stderr) 메시지

sortbooks.cpp: In function 'void build(int, int, int)':
sortbooks.cpp:38:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |  int m = vl + vr >> 1;
      |          ~~~^~~~
sortbooks.cpp: In function 'void get(int, int, int, int, int, std::vector<int>&)':
sortbooks.cpp:51:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |  int m = vl + vr >> 1;
      |          ~~~^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...