Submission #1191003

#TimeUsernameProblemLanguageResultExecution timeMemory
1191003lovrotHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
100 / 100
776 ms61496 KiB
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>

#define PB push_back
#define deb(...) //fprintf(stderr, __VA_ARGS__)
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int LOG = 20;
const int N = 1 << LOG;

int n, w[N];

bool ans[N];
vector<int> h;
vector<pair<pii, int>> q[N];

int t[2 * N];

void update(int x, int w) { 
	x += N;
	t[x] = w;

	for(x >>= 1; x; x >>= 1) { t[x] = max(t[2 * x], t[2 * x + 1]); }
}

int query(int l, int r, int u = 1, int lo = 0, int hi = N) { 
	if(r <= lo || hi <= l) return 0; 
	if(l <= lo && hi <= r) return t[u]; 
	int mi = (lo + hi) / 2;
	return max(query(l, r, 2 * u, lo, mi), query(l, r, 2 * u + 1, mi, hi));
}

int main() { 
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) { scanf("%d", w + i); }

	for(int i = 0; i < m; ++i) {
		int l, r, k;
		scanf("%d%d%d", &l, &r, &k);
		q[r].PB({{l, k}, i});
	}

	for(int i = 1; i <= n; ++i) { 
		for(; !h.empty() && w[h.back()] <= w[i]; h.pop_back());
		if(!h.empty()) { update(h.back(), w[h.back()] + w[i]); }
		h.PB(i);

		for(auto j : q[i]) { ans[j.Y] = query(j.X.X, i + 1) <= j.X.Y; }
	}

	for(int i = 0; i < m; ++i) printf("%d\n", ans[i]); 
	return 0;
}

Compilation message (stderr)

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         scanf("%d%d", &n, &m);
      |         ~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:45:44: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         for(int i = 1; i <= n; ++i) { scanf("%d", w + i); }
      |                                       ~~~~~^~~~~~~~~~~~~
sortbooks.cpp:49:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |                 scanf("%d%d%d", &l, &r, &k);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...