답안 #497417

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
497417 2021-12-23T05:01:07 Z Ziel Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
13 / 100
1172 ms 62788 KB
/**
 * LES GREATEABLES BRO TEAM
**/

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
#define sz(x) (int)x.size()
const bool FLAG = false;
void setIO(const string &f = "");

const int N = 1e6 + 12456;
struct node {
	int mx1, mx2, mn, k;
} t[4 * N];
int a[N], n, q;

node unite(node a, node b) {
	node res;
	res.k = max(a.k, b.k);
	res.mn = min(a.mn, b.mn);

	if (a.mx1 > b.mx1) {
		res.mx1 = a.mx1;
		if (a.mx2 > b.mx1) {
			res.mx2 = a.mx2;
		} else {
			if (b.mx1 == a.mx1)
				res.mx2 = a.mx2;
			else
				res.mx2 = b.mx1;
		}
	} else {
		res.mx1 = b.mx1;
		if (b.mx2 > a.mx1) {
			res.mx2 = b.mx2;
		} else {
			if (a.mx1 == b.mx1)
				res.mx2 = b.mx2;
			else
				res.mx2 = a.mx1;
		}
	}

	if (a.mx1 <= b.mn)
		return res;
	if (a.mx1 > b.mx1) {
		res.k = max(res.k, a.mx1 + b.mx1);
		return res;
	} else {
		res.k = max(res.k, a.mx1 + b.mx2);
		return res;
	}
}
void build(int x = 0, int lx = 1, int rx = n) {
	if (lx == rx) {
		t[x].mx1 = a[lx];
		t[x].mx2 = 0;
		t[x].mn = a[lx];
		t[x].k = 0;
	} else {
		int mid = (lx + rx) / 2;
		build(2 * x + 1, lx, mid);
		build(2 * x + 2, mid + 1, rx);
		t[x] = unite(t[2 * x + 1], t[2 * x + 2]);
	}
}
node get(int l, int r, int x = 0, int lx = 1, int rx = n) {
	if (r < lx || rx < l) return {-1, -1, -1, -1};
	if (l <= lx && rx <= r) return t[x];
	int mid = (lx + rx) / 2;
	node res1 = get(l, r, 2 * x + 1, lx, mid);
	node res2 = get(l, r, 2 * x + 2, mid + 1, rx);
	if (res1.mx1 == -1 && res2.mx1 == -1)
		assert(false);
	if (res1.mx1 == -1)
		return res2;
	if (res2.mx1 == -1)
		return res1;
	return unite(res1, res2);
}

void solve() {
	cin >> n >> q;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	build();
	while (q--) {
		int l, r, k;
		cin >> l >> r >> k;
		node res = get(l, r);
		cout << bool(res.k <= k) << '\n';
	}
}

signed main() {
    setIO();
    
    int tt = 1;
    if (FLAG) {
    	cin >> tt;
    }
    while (tt--) {
    	solve();
    }
    
    return 0;
}

void setIO(const string &f) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen((f + ".in").c_str(), "r")) {
        freopen((f + ".in").c_str(), "r", stdin);
        freopen((f + ".out").c_str(), "w", stdout);
    }
}

Compilation message

sortbooks.cpp: In function 'void setIO(const string&)':
sortbooks.cpp:116:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |         freopen((f + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:117:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |         freopen((f + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1172 ms 39100 KB Output is correct
2 Correct 1154 ms 40236 KB Output is correct
3 Correct 1172 ms 40060 KB Output is correct
4 Correct 1148 ms 39964 KB Output is correct
5 Correct 1090 ms 62788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 79 ms 4960 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -