답안 #1021484

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1021484 2024-07-12T18:47:49 Z aykhn Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
212 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

#define inf 0x3F3F3F3F3F3F3F3F
#define int long long

const int MXN = 1e6 + 5;

int n, q;
int a[MXN];
vector<int> st[MXN << 2];
int mx[MXN << 2];

void build(int l, int r, int x)
{
	mx[x] = 0;
	if (l == r)
	{
		st[x].push_back(a[l]);
		return;
	}
	int mid = (l + r) >> 1;
	build(l, mid, 2*x), build(mid + 1, r, 2*x + 1);
	st[x].resize(st[2*x].size() + st[2*x + 1].size());
	int i = 0, j = 0;
	while (i < st[2*x].size() && j < st[2*x + 1].size())
	{
		if (st[2*x][i] < st[2*x + 1][j]) st[x].push_back(st[2*x][i++]);
		else st[x].push_back(st[2*x + 1][j++]);
	}
	while (i < st[2*x].size()) st[x].push_back(st[2*x][i++]);
	while (j < st[2*x + 1].size()) st[x].push_back(st[2*x + 1][j++]);
	if (st[2*x].back() > st[2*x + 1][0]) mx[x] = st[2*x].back() + *--lower_bound(st[2*x + 1].begin(), st[2*x + 1].end(), st[2*x].back());
	mx[x] = max({mx[x], mx[2*x], mx[2*x + 1]});
}

vector<int> res;
int get(int l, int r, int x, int lx, int rx)
{
	if (l > rx || r < lx) return -inf;
	if (l >= lx && r <= rx) 
	{
		res.push_back(x);
		return mx[x];
	}
	int mid = (l + r) >> 1;
	return max(get(l, mid, 2*x, lx, rx), get(mid + 1, r, 2*x + 1, lx, rx));
}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> q;
	for (int i = 1; i <= n; i++) cin >> a[i];
	build(1, n, 1);
	while (q--)
	{
		res.clear();
		int l, r, x;
		cin >> l >> r >> x;
		int ans = get(1, n, 1, l, r), curmx = -inf;
		for (int i = 0; i + 1 < res.size(); i++)
		{
			int l = res[i], r = res[i + 1];
			curmx = max(curmx, st[l].back());
			if (curmx > st[r][0]) ans = max(ans, curmx + *--lower_bound(st[r].begin(), st[r].end(), curmx));
		}
		cout << (ans <= x) << '\n';
	}
}

Compilation message

sortbooks.cpp: In function 'void build(long long int, long long int, long long int)':
sortbooks.cpp:27:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |  while (i < st[2*x].size() && j < st[2*x + 1].size())
      |         ~~^~~~~~~~~~~~~~~~
sortbooks.cpp:27:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |  while (i < st[2*x].size() && j < st[2*x + 1].size())
      |                               ~~^~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:32:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  while (i < st[2*x].size()) st[x].push_back(st[2*x][i++]);
      |         ~~^~~~~~~~~~~~~~~~
sortbooks.cpp:33:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |  while (j < st[2*x + 1].size()) st[x].push_back(st[2*x + 1][j++]);
      |         ~~^~~~~~~~~~~~~~~~~~~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:64:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |   for (int i = 0; i + 1 < res.size(); i++)
      |                   ~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 94292 KB Output is correct
2 Correct 45 ms 94304 KB Output is correct
3 Incorrect 48 ms 94804 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 94292 KB Output is correct
2 Correct 45 ms 94304 KB Output is correct
3 Incorrect 48 ms 94804 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 212 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 146 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 94292 KB Output is correct
2 Correct 45 ms 94304 KB Output is correct
3 Incorrect 48 ms 94804 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 94292 KB Output is correct
2 Correct 45 ms 94304 KB Output is correct
3 Incorrect 48 ms 94804 KB Output isn't correct
4 Halted 0 ms 0 KB -