답안 #654263

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
654263 2022-10-30T17:54:46 Z thiago_bastos Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
614 ms 54944 KB
#include "bits/stdc++.h"

using namespace std;

#define INF 1000000000
#define INFLL 1000000000000000000ll
#define EPS 1e-9
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
#define fi first
#define sc second
 
using i64 = long long;
using u64 = unsigned long long;
using ld = long double;
using ii = pair<int, int>;	

void solve() {
	int n, m;
	vector<ii> in, out;

	cin >> n >> m;

	vector<int> w(n);
	vector<bool> can(m, false);

	for(int& v : w) cin >> v;

	vector<tuple<int, int, int, int>> query(m);

	for(int i = 0; i < m; ++i) {
		int l, r, k;
		cin >> l >> r >> k;
		--l, --r;
		query[i] = {r, l, k, i};
	}

	sort(all(query));

	for(int i = 0, j = 0; i < n; ++i) {
		vector<ii> tmp;

		while(!in.empty() && in.back().sc <= w[i]) {
			tmp.pb(in.back());
			in.pop_back();
		}

		reverse(all(tmp));

		for(int j = 0; j < (int)tmp.size() - 1; ++j) {
			tmp[j].sc += tmp[j + 1].sc;
			while(!out.empty() && out.back().sc <= tmp[j].sc) out.pop_back();
			out.pb(tmp[j]);
		}

		in.pb({i, w[i]});

		while(j < m && get<0>(query[j]) == i) {
			auto [r, l, k, pos] = query[j++];

			auto i = lower_bound(all(in), ii(l, -1));

			int mood = 0;

			if(in.end() - i >= 2) mood = i->sc + next(i)->sc;
			
			i = lower_bound(all(out), ii(l, -1));

			if(i != out.end()) mood = max(mood, i->sc);

			can[pos] = mood <= k;
		}
	}

	for(bool x : can) cout << x << '\n';
}	

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
 //	cin >> t;
	while(t--) solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Incorrect 1 ms 320 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Incorrect 1 ms 320 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 603 ms 21988 KB Output is correct
2 Incorrect 614 ms 54944 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 49 ms 2424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Incorrect 1 ms 320 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Incorrect 1 ms 320 KB Output isn't correct
6 Halted 0 ms 0 KB -