Submission #538972

# Submission time Handle Problem Language Result Execution time Memory
538972 2022-03-18T06:25:09 Z akhan42 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
838 ms 262144 KB
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define F first
#define S second
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forbn(i, b, n) for(int i = b; i < n; ++i)
#define sz(v) (int)v.size()
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
typedef complex<double> cd; // !!! long double slow

template <class T> inline void mineq(T &a, T b) { a = min(a, b); }
template <class T> inline void maxeq(T &a, T b) { a = max(a, b); }


int n, q;
const int INF = 1000 * 1000 * 1000 + 10;


struct Seg {
	vi mx, t;
	vector<vi> sl;

	Seg(vi& a) {
		mx.assign(4 * n, -INF);
		t.assign(4 * n, -INF);
		sl.resize(4 * n);

		build(a);
	}

	void build(vi& a, int v = 1, int tl = 0, int tr = n - 1) {
		if(tl == tr) {
			mx[v] = a[tl];
			sl[v].pb(a[tl]);
			return;
		}
		int tm = (tl + tr) / 2;

		build(a, 2 * v, tl, tm);
		build(a, 2 * v + 1, tm + 1, tr);

		mx[v] = max(mx[2 * v], mx[2 * v + 1]);
		merge(all(sl[2 * v]), all(sl[2 * v + 1]), back_inserter(sl[v]));

		t[v] = max(t[2 * v], t[2 * v + 1]);
		int ind = lower_bound(all(sl[2 * v + 1]), mx[2 * v]) - sl[2 * v + 1].begin();
		if(ind != 0)
			maxeq(t[v], mx[2 * v] + sl[2 * v + 1][ind - 1]);
	}

	pair<bool, int> query(int l, int r, int k, int left_max, int v = 1, int tl = 0, int tr = n - 1) {
		if(l > r)
			return {true, -INF};
		if(tl == l && r == tr) {
			bool ans = t[v] <= k;
			int rp = left_max - 1, lp = k - left_max + 1;

			if(lp <= rp) {
				int indl = lower_bound(all(sl[v]), lp) - sl[v].begin();
				int indr = lower_bound(all(sl[v]), rp + 1) - sl[v].begin();

				ans = ans && indl == indr;
			}
			return {ans, mx[v]};
		}
		int tm = (tl + tr) / 2;

		auto q1 = query(l, min(r, tm), k, left_max, 2 * v, tl, tm);
		auto q2 = query(max(l, tm + 1), r, k, max(left_max, q1.S), 2 * v + 1, tm + 1, tr);

		return {q1.F && q2.F, max(q1.S, q2.S)};
	}
};



void solve() {
	cin >> n >> q;
	vi a(n);
	forn(i, n)
		cin >> a[i];

	Seg seg(a);

	forn(_, q) {
		int l, r, k;
		cin >> l >> r >> k;
		l--; r--;

		auto ans = seg.query(l, r, k, -INF);
		cout << ans.F << '\n';
	}

//	forn(k, 15) {
//		auto ans = seg.query(0, n - 1, k, (k + 1) / 2, (k - 1) / 2);
//		cout << k << ' ' << ans.F << '\n';
//	}
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

//	freopen("boards.in", "r", stdin);
//	freopen("boards.out", "w", stdout);

    int t = 1;
//  cin >> t;
    while(t--) {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 4 ms 724 KB Output is correct
12 Correct 7 ms 1620 KB Output is correct
13 Correct 7 ms 1620 KB Output is correct
14 Correct 10 ms 1748 KB Output is correct
15 Correct 10 ms 1748 KB Output is correct
16 Correct 8 ms 1708 KB Output is correct
17 Correct 5 ms 1364 KB Output is correct
18 Correct 5 ms 1700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 541 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 305 ms 26652 KB Output is correct
2 Correct 271 ms 26624 KB Output is correct
3 Correct 221 ms 26556 KB Output is correct
4 Correct 196 ms 28544 KB Output is correct
5 Correct 190 ms 28600 KB Output is correct
6 Correct 151 ms 28464 KB Output is correct
7 Correct 149 ms 28356 KB Output is correct
8 Correct 150 ms 28288 KB Output is correct
9 Correct 42 ms 2000 KB Output is correct
10 Correct 158 ms 28224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 4 ms 724 KB Output is correct
12 Correct 7 ms 1620 KB Output is correct
13 Correct 7 ms 1620 KB Output is correct
14 Correct 10 ms 1748 KB Output is correct
15 Correct 10 ms 1748 KB Output is correct
16 Correct 8 ms 1708 KB Output is correct
17 Correct 5 ms 1364 KB Output is correct
18 Correct 5 ms 1700 KB Output is correct
19 Correct 838 ms 60264 KB Output is correct
20 Correct 777 ms 60340 KB Output is correct
21 Correct 625 ms 60104 KB Output is correct
22 Correct 613 ms 60180 KB Output is correct
23 Correct 617 ms 60160 KB Output is correct
24 Correct 436 ms 60068 KB Output is correct
25 Correct 367 ms 59968 KB Output is correct
26 Correct 515 ms 60276 KB Output is correct
27 Correct 425 ms 60216 KB Output is correct
28 Correct 510 ms 60256 KB Output is correct
29 Correct 568 ms 60296 KB Output is correct
30 Correct 596 ms 60328 KB Output is correct
31 Correct 512 ms 60308 KB Output is correct
32 Correct 522 ms 60352 KB Output is correct
33 Correct 522 ms 60296 KB Output is correct
34 Correct 399 ms 59956 KB Output is correct
35 Correct 333 ms 59968 KB Output is correct
36 Correct 329 ms 59836 KB Output is correct
37 Correct 345 ms 59772 KB Output is correct
38 Correct 337 ms 59956 KB Output is correct
39 Correct 435 ms 58864 KB Output is correct
40 Correct 176 ms 37804 KB Output is correct
41 Correct 387 ms 58420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 4 ms 724 KB Output is correct
12 Correct 7 ms 1620 KB Output is correct
13 Correct 7 ms 1620 KB Output is correct
14 Correct 10 ms 1748 KB Output is correct
15 Correct 10 ms 1748 KB Output is correct
16 Correct 8 ms 1708 KB Output is correct
17 Correct 5 ms 1364 KB Output is correct
18 Correct 5 ms 1700 KB Output is correct
19 Runtime error 541 ms 262144 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -