답안 #539112

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
539112 2022-03-18T12:19:53 Z akhan42 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
945 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;
const int MX = 2 * 1000 * 1000;
int ol[MX];
bool res[MX];


bool cmp(int v1, int v2) {
	return ol[v1] < ol[v2];
}


struct Seg {
	int mx[MX], t[MX];
	vi sl[MX];
	vector<pair<ii, int>> rem[MX];

	Seg(vi& a) {
		forn(i, MX)
			res[i] = true;
		for(int p = n; p < 2 * n; p++) {
			mx[p] = a[p - n];
			sl[p].pb(a[p - n]);
			t[p] = -INF;
			ol[p] = p - n;
		}

		for(int p = n - 1; p > 0; p--) {
			ol[p] = min(ol[2 * p], ol[2 * p + 1]);
			mx[p] = max(mx[2 * p], mx[2 * p + 1]);
			t[p] = max(t[2 * p], t[2 * p + 1]);
			merge(all(sl[2 * p]), all(sl[2 * p + 1]), back_inserter(sl[p]));

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

	void query(int l, int r, int k, int left_max, int qid) {
		vi vert;
		for (l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
			if (l & 1) {
				vert.pb(l++);
			}
			if (r & 1) {
				vert.pb(--r);
			}
		}
		sort(all(vert), cmp);

		bool ans = true;
		for(int v: vert) {
			ans = ans && t[v] <= k;
			int rp = left_max - 1, lp = k - left_max + 1;

			if(lp <= rp) {
				rem[v].pb({{lp - 1, -1}, qid});
				rem[v].pb({{rp, 1}, qid});

//				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;
			}

			maxeq(left_max, mx[v]);
		}

		res[qid] = ans;
	}

	void process() {
		for(int v = 1; v < 2 * n; v++) {
			sort(all(rem[v]));
			set<int> act;
			int i = 0;

			for(auto p: rem[v]) {
				int qid = p.S;
				if(res[qid] == false)
					continue;
				int open = p.F.S;
				int en = p.F.F;

				if(i < sz(sl[v]) && sl[v][i] <= en) {
					for(int qid_act: act) {
						res[qid_act] = false;
					}
					act.clear();
				}
				while(i < sz(sl[v]) && sl[v][i] <= en)
					i += 1;

				if(open == -1) {
					act.insert(qid);
				}
				else {
					act.erase(qid);
				}
			}
		}
	}
};



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

	Seg seg(a);

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

		seg.query(l, r, k, -INF, qid);
	}

	seg.process();

	forn(qid, q) {
		cout << res[qid] << '\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();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 111812 KB Output is correct
2 Correct 64 ms 111832 KB Output is correct
3 Correct 68 ms 111824 KB Output is correct
4 Correct 66 ms 111812 KB Output is correct
5 Correct 66 ms 111832 KB Output is correct
6 Correct 66 ms 111908 KB Output is correct
7 Correct 67 ms 111876 KB Output is correct
8 Correct 66 ms 111960 KB Output is correct
9 Correct 65 ms 111896 KB Output is correct
10 Correct 65 ms 111956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 111812 KB Output is correct
2 Correct 64 ms 111832 KB Output is correct
3 Correct 68 ms 111824 KB Output is correct
4 Correct 66 ms 111812 KB Output is correct
5 Correct 66 ms 111832 KB Output is correct
6 Correct 66 ms 111908 KB Output is correct
7 Correct 67 ms 111876 KB Output is correct
8 Correct 66 ms 111960 KB Output is correct
9 Correct 65 ms 111896 KB Output is correct
10 Correct 65 ms 111956 KB Output is correct
11 Correct 72 ms 112652 KB Output is correct
12 Correct 74 ms 113112 KB Output is correct
13 Correct 74 ms 113284 KB Output is correct
14 Correct 82 ms 113788 KB Output is correct
15 Correct 78 ms 113808 KB Output is correct
16 Correct 75 ms 112940 KB Output is correct
17 Correct 70 ms 112220 KB Output is correct
18 Correct 76 ms 113244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 543 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 395 ms 154764 KB Output is correct
2 Correct 434 ms 158384 KB Output is correct
3 Correct 410 ms 146232 KB Output is correct
4 Correct 402 ms 145832 KB Output is correct
5 Correct 378 ms 144588 KB Output is correct
6 Correct 295 ms 142592 KB Output is correct
7 Correct 293 ms 142512 KB Output is correct
8 Correct 294 ms 142832 KB Output is correct
9 Correct 124 ms 112072 KB Output is correct
10 Correct 274 ms 140288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 111812 KB Output is correct
2 Correct 64 ms 111832 KB Output is correct
3 Correct 68 ms 111824 KB Output is correct
4 Correct 66 ms 111812 KB Output is correct
5 Correct 66 ms 111832 KB Output is correct
6 Correct 66 ms 111908 KB Output is correct
7 Correct 67 ms 111876 KB Output is correct
8 Correct 66 ms 111960 KB Output is correct
9 Correct 65 ms 111896 KB Output is correct
10 Correct 65 ms 111956 KB Output is correct
11 Correct 72 ms 112652 KB Output is correct
12 Correct 74 ms 113112 KB Output is correct
13 Correct 74 ms 113284 KB Output is correct
14 Correct 82 ms 113788 KB Output is correct
15 Correct 78 ms 113808 KB Output is correct
16 Correct 75 ms 112940 KB Output is correct
17 Correct 70 ms 112220 KB Output is correct
18 Correct 76 ms 113244 KB Output is correct
19 Correct 878 ms 205576 KB Output is correct
20 Correct 877 ms 205412 KB Output is correct
21 Correct 861 ms 211024 KB Output is correct
22 Correct 848 ms 211880 KB Output is correct
23 Correct 852 ms 211908 KB Output is correct
24 Correct 838 ms 180936 KB Output is correct
25 Correct 865 ms 180484 KB Output is correct
26 Correct 922 ms 185808 KB Output is correct
27 Correct 945 ms 185724 KB Output is correct
28 Correct 926 ms 186796 KB Output is correct
29 Correct 904 ms 184760 KB Output is correct
30 Correct 934 ms 184672 KB Output is correct
31 Correct 889 ms 186396 KB Output is correct
32 Correct 927 ms 186312 KB Output is correct
33 Correct 915 ms 186512 KB Output is correct
34 Correct 701 ms 180252 KB Output is correct
35 Correct 700 ms 180056 KB Output is correct
36 Correct 690 ms 180260 KB Output is correct
37 Correct 699 ms 180088 KB Output is correct
38 Correct 693 ms 180004 KB Output is correct
39 Correct 558 ms 170020 KB Output is correct
40 Correct 242 ms 129364 KB Output is correct
41 Correct 529 ms 171192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 111812 KB Output is correct
2 Correct 64 ms 111832 KB Output is correct
3 Correct 68 ms 111824 KB Output is correct
4 Correct 66 ms 111812 KB Output is correct
5 Correct 66 ms 111832 KB Output is correct
6 Correct 66 ms 111908 KB Output is correct
7 Correct 67 ms 111876 KB Output is correct
8 Correct 66 ms 111960 KB Output is correct
9 Correct 65 ms 111896 KB Output is correct
10 Correct 65 ms 111956 KB Output is correct
11 Correct 72 ms 112652 KB Output is correct
12 Correct 74 ms 113112 KB Output is correct
13 Correct 74 ms 113284 KB Output is correct
14 Correct 82 ms 113788 KB Output is correct
15 Correct 78 ms 113808 KB Output is correct
16 Correct 75 ms 112940 KB Output is correct
17 Correct 70 ms 112220 KB Output is correct
18 Correct 76 ms 113244 KB Output is correct
19 Runtime error 543 ms 262144 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -