답안 #497404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
497404 2021-12-23T04:43:29 Z Ziel Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
1552 ms 30756 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, k;
} t[4 * N];
int a[N], n, q;

node unite(node a, node b) {
	node res;
	res.k = max(a.k, b.k);
	if (a.mx1 > b.mx1) {
		res.mx1 = a.mx1;
		res.mx2 = max(a.mx2, b.mx1);
		res.k = max(res.k, a.mx1 + b.mx1);
	} else {
		res.mx1 = b.mx1;
		res.mx2 = max(a.mx1, b.mx2);
		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].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};
	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:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         freopen((f + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen((f + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 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 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1552 ms 30756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 104 ms 3956 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 332 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 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -