답안 #631838

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
631838 2022-08-18T23:45:24 Z gromperen Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
13 / 100
1290 ms 96444 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int MAXN = 1e6+5;
int tree[4*MAXN];

void upd(int i, int v, int x, int lx, int rx) {
	if (lx == rx) {
		tree[x] = v;
		return;
	}

	int mid = (lx + rx) / 2;
	if (i <= mid) upd(i, v, 2*x, lx, mid);
	else upd(i, v, 2*x+1, mid+1, rx);
	tree[x] = max(tree[2*x], tree[2*x+1]);
}

int qry(int l, int r, int x, int lx, int rx) {
	if (l <= lx && rx <= r) return tree[x];
	if (r < lx || rx < l) return 0;
	int mid = (lx+rx) /2;
	return max(qry(l,r,2*x,lx,mid), qry(l,r,2*x+1,mid+1,rx));
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n, m; cin >> n >> m;
	vector<int> a(n+1);
	vector<vector<tuple<int,int,int>>> queries(n+1);
	vector<int> ans(n+1);
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	for (int i = 1; i <= m; ++i) {
		int l, r, k; cin >> l >> r >> k;
		queries[r].push_back({l, k, i});
	}

	//cout << "OK"<<endl;
	
	stack<int> st;
	for (int i = 1; i <= n; ++i) { // iterate from 1 to n over Rs in queries
		while(!st.empty() && a[st.top()] <= a[i]) st.pop();
		if (!st.empty()) { // Greedily include swap(st.top(), i) at st.top(), because all future Rs are >= than i
			upd(st.top(), a[st.top()] + a[i], 1, 1, n);
		} 		
		for (auto x : queries[i]) {
			int l = get<0>(x);
			int k = get<1>(x);
			int j = get<2>(x);
			if (qry(l, i, 1, 1, n) <= k) ans[j] = 1;
			else ans[j] = 0;
		}
		st.push(i);
	}
	for (int i = 1; i <= m; ++i) cout << ans[i] << "\n";


	return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 1 ms 464 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 1 ms 464 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1290 ms 95480 KB Output is correct
2 Correct 1288 ms 96444 KB Output is correct
3 Correct 1271 ms 96304 KB Output is correct
4 Correct 1282 ms 96424 KB Output is correct
5 Correct 1050 ms 88256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 8780 KB Output is correct
2 Correct 81 ms 8524 KB Output is correct
3 Correct 75 ms 7604 KB Output is correct
4 Correct 78 ms 7672 KB Output is correct
5 Correct 69 ms 7744 KB Output is correct
6 Correct 60 ms 7116 KB Output is correct
7 Correct 64 ms 7168 KB Output is correct
8 Correct 68 ms 7396 KB Output is correct
9 Runtime error 39 ms 5028 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 1 ms 464 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 1 ms 464 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -