답안 #880534

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880534 2023-11-29T15:39:22 Z dubabuba Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
8 ms 2416 KB
#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
vi t;

struct con {
	int ans, max;
	vi &range = t;
	con() {
		ans = max = 0;
	}
};

void ono_max(int &MAX, int CMP) { if(CMP > MAX) MAX = CMP;}
void ono_min(int &MIN, int CMP) { if(CMP < MIN) MIN = CMP;}

const int mxl = 15;
const int mxn = 5050;
vector<vi> sus(mxl, vi (mxn));
vector<vi> tmp(mxl, vi (mxn));
con str[mxn * 4];
int a[mxn], n, m;

int merge(
	vi &edit, const int &st, const int &en,
	const vi &L, const int &L_st, const int &L_en,
	const vi &R, const int &R_st, const int &R_en) {
	int ret = 0;

	int cur_L = L_st, cur_R = R_st;
	for(int i = st; i <= en; i++) {
		if(cur_L == L_en + 1) {
			edit[i] = R[cur_R];
			cur_R++;
			continue;
		}

		if(cur_R == R_en + 1) {
			edit[i] = L[cur_L];
			cur_L++;
			continue;
		}

		if(L[cur_L] <= R[cur_R]) {
			edit[i] = L[cur_L];
			cur_L++;
		}
		else {
			edit[i] = R[cur_R];
			ono_max(ret, R[cur_R]);
			cur_R++;
		}
	}
	return ret;
}

void build(int idx, int lvl, int tl, int tr) {
	str[idx].range = sus[lvl];
	if(tl == tr) {
		// cout << tl << ": " << a[tl] << '\n';
		sus[lvl][tl] = a[tl];
		str[idx].max = a[tl];
		str[idx].ans = 0;
		return;
	}

	int tm = (tl + tr) / 2;
	build(idx * 2 + 1, lvl + 1, tl, tm);
	build(idx * 2 + 2, lvl + 1, tm + 1, tr);

	ono_max(str[idx].max, str[idx * 2 + 1].max);
	ono_max(str[idx].max, str[idx * 2 + 2].max);

	ono_max(str[idx].ans, str[idx * 2 + 1].ans);
	ono_max(str[idx].ans, str[idx * 2 + 2].ans);

	int t = merge(
			sus[lvl], tl, tr,
			sus[lvl + 1], tl, tm,
			sus[lvl + 1], tm + 1, tr
		);
	if(t != 0)
		ono_max(str[idx].ans, str[idx * 2 + 1].max + t);
}

con query(int idx, int lvl, int tl, int tr, int l, int r) {
	if(tl == l && r == tr) return str[idx];
	int tm = (tl + tr) / 2;
	if(r <= tm) return query(idx * 2 + 1, lvl + 1, tl, tm, l, r);
	if(tm < l) return query(idx * 2 + 2, lvl + 1, tm + 1, tr, l, r);

	con L_qr = query(idx * 2 + 1, lvl + 1, tl, tm, l, tm);
	con R_qr = query(idx * 2 + 2, lvl + 1, tm + 1, tr, tm + 1, r);
	con ret; ret.range = tmp[lvl];

	ono_max(ret.max, L_qr.max);
	ono_max(ret.max, R_qr.max);
	ono_max(ret.ans, L_qr.ans);
	ono_max(ret.ans, R_qr.ans);

	int t = merge(
			ret.range, l, r,
			L_qr.range, l, tm,
			R_qr.range, tm + 1, r
		);
	if(t != 0)
		ono_max(ret.ans, L_qr.max + t);
	return ret;
}

int main() {
	cin.tie(0)-> sync_with_stdio(0);
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		cin >> a[i];

	build(0, 0, 1, n);
	// for(int i = 1; i <= n; i++)
	// 	cout << sus[0][i] << ' ';

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

		con t = query(0, 0, 1, n, l, r);
		// cout << l << ' ' << r << ": " << t.ans << '\n';
		cout << (t.ans <= k) << '\n';
	}

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Incorrect 2 ms 1372 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Incorrect 2 ms 1372 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 2396 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 2416 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Incorrect 2 ms 1372 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Incorrect 2 ms 1372 KB Output isn't correct
4 Halted 0 ms 0 KB -