Submission #880968

# Submission time Handle Problem Language Result Execution time Memory
880968 2023-11-30T09:35:09 Z dubabuba Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
13 / 100
2847 ms 64192 KB
#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
const int mxn = 1e6 + 10;
vi a(mxn);
int n, m;

struct node {
	int mx, mn;
	bool flag;
} st[mxn * 4];

void build(int id, int tl, int tr) {
	if(tl == tr) {
		st[id].mn = a[tl];
		st[id].mx = a[tr];
		st[id].flag = 1;
		return;
	}

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

	st[id].mx = max(st[id * 2 + 1].mx, st[id * 2 + 2].mx);
	st[id].mn = min(st[id * 2 + 1].mn, st[id * 2 + 2].mn);
	st[id].flag = 1;

	if(!st[id * 2 + 1].flag) st[id].flag = 0;
	if(!st[id * 2 + 2].flag) st[id].flag = 0;
	if(st[id * 2 + 1].mx > st[id * 2 + 2].mn)
		st[id].flag = 0;
}

node query(int id, int tl, int tr, int l, int r) {
	if(tl == l && r == tr) return st[id];
	int tm = (tl + tr) / 2;
	if(r <= tm) return query(id * 2 + 1, tl, tm, l, r);
	if(tm < l) return query(id * 2 + 2, tm + 1, tr, l, r);

	node L_qr = query(id * 2 + 1, tl, tm, l, tm);
	node R_qr = query(id * 2 + 2, tm + 1, tr, tm + 1, r);
	node ret; ret.flag = 1;

	ret.mx = max(L_qr.mx, R_qr.mx);
	ret.mn = min(L_qr.mn, R_qr.mn);
	if(!L_qr.flag) ret.flag = 0;
	if(!R_qr.flag) ret.flag = 0;
	if(L_qr.mx > R_qr.mn) ret.flag = 0;
	return ret;
}

int main() {
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		cin >> a[i];

	build(0, 1, n);

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

		cout << query(0, 1, n, l, r).flag << '\n';
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2724 ms 31084 KB Output is correct
2 Correct 2787 ms 64136 KB Output is correct
3 Correct 2774 ms 63876 KB Output is correct
4 Correct 2847 ms 64192 KB Output is correct
5 Correct 2809 ms 63960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 229 ms 8812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4188 KB Output isn't correct
2 Halted 0 ms 0 KB -