답안 #1094874

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1094874 2024-09-30T17:40:51 Z Kerim Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
562 ms 179848 KB
#include "bits/stdc++.h"

using namespace std;
const int N = 1e6+6;
int arr[N], d[N], ans[N];
vector<int> queries[N];
int l[N], r[N], k[N], s[N<<2];
void upd(int p, int v, int nd, int x, int y){
	if (x == y){
		s[nd] = max(s[nd], v);
		return;
	}
	int mid = (x+y) >> 1;
	if (p <= mid)
		upd(p, v, nd<<1, x, mid);
	else
		upd(p, v, nd<<1|1, mid+1, y);
	s[nd] = max(s[nd<<1], s[nd<<1|1]);
}
int tap(int l, int r, int nd, int x, int y){
	if (l > y or x > r)
		return 0;
	if (l <= x and y <= r)
		return s[nd];
	int mid = (x+y) >> 1;
	return max(tap(l, r, nd<<1, x, mid), tap(l, r, nd<<1|1, mid+1, y));
}
int main(){
	// freopen("file.in", "r", stdin);
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", arr+i);
	stack<int> st;
	for (int i = 1; i <= n; i++){
		while (!st.empty() and arr[st.top()] <= arr[i])
			st.pop();
		if (st.empty())
			d[i] = -1;
		else
			d[i] = st.top();
		st.push(i);
	}
	int q;
	scanf("%d", &q);
	for (int i = 1; i <= q; i++){
		scanf("%d%d%d", l+i, r+i, k+i);
		queries[r[i]].push_back(i);
	}
	for (int j = 1; j <= n; j++){
		int i = d[j];
		if (~i){
			s[i] = max(s[i], arr[i]+arr[j]);
			// upd(i, arr[i]+arr[j], 1, 1, n);
		}
		for (auto ind: queries[j]){
			int mx = 0;
			for (int h = l[ind]; h <= r[ind]; h++)
				mx = max(mx, s[h]);
			ans[ind] = mx <= k[ind];
			// ans[ind] = tap(l[ind], r[ind], 1, 1, n) <= k[ind];
		}
	}
	for (int i = 1; i <= q; i++)
		printf("%d\n", ans[i]);
	return 0;
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
sortbooks.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   scanf("%d", arr+i);
      |   ~~~~~^~~~~~~~~~~~~
sortbooks.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
sortbooks.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |   scanf("%d%d%d", l+i, r+i, k+i);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 33116 KB Output is correct
2 Incorrect 4 ms 29020 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 33116 KB Output is correct
2 Incorrect 4 ms 29020 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 562 ms 179848 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 34136 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 33116 KB Output is correct
2 Incorrect 4 ms 29020 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 33116 KB Output is correct
2 Incorrect 4 ms 29020 KB Output isn't correct
3 Halted 0 ms 0 KB -