답안 #467040

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
467040 2021-08-21T11:52:27 Z hhhhaura Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1294 ms 135432 KB
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))

using namespace std;

#define INF 1000000000000000000
#define int long long int
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

#ifdef wiwihorz
#define print(a...) cerr << "Line " << __LINE__ << ": ", kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...);} 
#else
#define print(...) 0
#define vprint(...) 0
#endif
namespace bit {
	int n;
	vector<int> v;
	void init_(int _n) {
		n = _n;
		v.assign(n + 1, 0);
	}
	int lowbit(int x) {
		return x & (-x);
	}
	void modify(int x, int val) {
		for(int i = x; i <= n; i += lowbit(i)) {
			v[i] = max(v[i], val);
		}
	}
	int query(int x) {
		int ans = 0;
		for(int i = x; i > 0; i -= lowbit(i)) {
			ans = max(ans, v[i]);
		}
		return ans;
	}
};
namespace solver {
	int n, m;
	vector<int> a, ans, r, k;
	vector<vector<int>> q;
	vector<pii> p;
	void init_(int _n, int _m) {
		n = _n, m = _m;
		a.assign(n + 1, 0);
		ans.assign(m + 1, 0);
		r.assign(m + 1, 0);
		k.assign(m + 1, 0);
		q.assign(n + 1, vector<int>());
		p.clear();
		bit::init_(n);
	}
	void solve() {
		vector<int> s;
		rep(i, 1, n) {
			while(s.size() && a[s.back()] <= a[i]) s.pop_back();
			if(s.size()) p.push_back({s.back(), i});
			s.push_back(i);
		}
		sort(all(p));
		int ii = signed(p.size()) - 1;
		rrep(i, 1, n) {
			while(ii >= 0 && p[ii].first >= i) {
				int L = p[ii].first, R = p[ii].second;
				bit::modify(R, a[L] + a[R]);
				ii--;
			}
			for(auto j : q[i]) {
				ans[j] = bit::query(r[j]) <= k[j];
			}
		}
		rep(i, 1 ,m) cout << ans[i] << "\n"; 
	}
	
	

};
using namespace solver;
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n, m;
	cin >> n >> m;
	init_(n, m);
	rep(i, 1, n) cin >> a[i];
	rep(i, 1, m) {
		int l; cin >> l;
		cin >> r[i] >> k[i];
		q[l].push_back(i);
	}
	solve();
	return 0;
}  

Compilation message

sortbooks.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      | 
sortbooks.cpp:20:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   20 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |             ^~~~
sortbooks.cpp:20:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   20 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |                     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 588 KB Output is correct
12 Correct 3 ms 844 KB Output is correct
13 Correct 4 ms 972 KB Output is correct
14 Correct 5 ms 1100 KB Output is correct
15 Correct 5 ms 1100 KB Output is correct
16 Correct 4 ms 844 KB Output is correct
17 Correct 5 ms 688 KB Output is correct
18 Correct 4 ms 844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1237 ms 132440 KB Output is correct
2 Correct 1212 ms 133516 KB Output is correct
3 Correct 1233 ms 133428 KB Output is correct
4 Correct 1208 ms 133416 KB Output is correct
5 Correct 1069 ms 117700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 94 ms 12764 KB Output is correct
2 Correct 74 ms 12172 KB Output is correct
3 Correct 67 ms 10636 KB Output is correct
4 Correct 80 ms 10820 KB Output is correct
5 Correct 73 ms 10812 KB Output is correct
6 Correct 59 ms 9992 KB Output is correct
7 Correct 57 ms 10048 KB Output is correct
8 Correct 66 ms 11904 KB Output is correct
9 Correct 42 ms 5196 KB Output is correct
10 Correct 72 ms 10932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 588 KB Output is correct
12 Correct 3 ms 844 KB Output is correct
13 Correct 4 ms 972 KB Output is correct
14 Correct 5 ms 1100 KB Output is correct
15 Correct 5 ms 1100 KB Output is correct
16 Correct 4 ms 844 KB Output is correct
17 Correct 5 ms 688 KB Output is correct
18 Correct 4 ms 844 KB Output is correct
19 Correct 215 ms 27916 KB Output is correct
20 Correct 218 ms 27836 KB Output is correct
21 Correct 175 ms 26248 KB Output is correct
22 Correct 172 ms 26292 KB Output is correct
23 Correct 191 ms 26256 KB Output is correct
24 Correct 145 ms 22380 KB Output is correct
25 Correct 142 ms 22280 KB Output is correct
26 Correct 209 ms 23040 KB Output is correct
27 Correct 161 ms 23036 KB Output is correct
28 Correct 181 ms 23240 KB Output is correct
29 Correct 198 ms 23984 KB Output is correct
30 Correct 180 ms 23992 KB Output is correct
31 Correct 205 ms 23976 KB Output is correct
32 Correct 178 ms 24012 KB Output is correct
33 Correct 193 ms 24004 KB Output is correct
34 Correct 135 ms 21700 KB Output is correct
35 Correct 140 ms 21800 KB Output is correct
36 Correct 127 ms 21432 KB Output is correct
37 Correct 132 ms 21396 KB Output is correct
38 Correct 137 ms 21656 KB Output is correct
39 Correct 183 ms 23324 KB Output is correct
40 Correct 128 ms 18740 KB Output is correct
41 Correct 161 ms 22884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 588 KB Output is correct
12 Correct 3 ms 844 KB Output is correct
13 Correct 4 ms 972 KB Output is correct
14 Correct 5 ms 1100 KB Output is correct
15 Correct 5 ms 1100 KB Output is correct
16 Correct 4 ms 844 KB Output is correct
17 Correct 5 ms 688 KB Output is correct
18 Correct 4 ms 844 KB Output is correct
19 Correct 1237 ms 132440 KB Output is correct
20 Correct 1212 ms 133516 KB Output is correct
21 Correct 1233 ms 133428 KB Output is correct
22 Correct 1208 ms 133416 KB Output is correct
23 Correct 1069 ms 117700 KB Output is correct
24 Correct 94 ms 12764 KB Output is correct
25 Correct 74 ms 12172 KB Output is correct
26 Correct 67 ms 10636 KB Output is correct
27 Correct 80 ms 10820 KB Output is correct
28 Correct 73 ms 10812 KB Output is correct
29 Correct 59 ms 9992 KB Output is correct
30 Correct 57 ms 10048 KB Output is correct
31 Correct 66 ms 11904 KB Output is correct
32 Correct 42 ms 5196 KB Output is correct
33 Correct 72 ms 10932 KB Output is correct
34 Correct 215 ms 27916 KB Output is correct
35 Correct 218 ms 27836 KB Output is correct
36 Correct 175 ms 26248 KB Output is correct
37 Correct 172 ms 26292 KB Output is correct
38 Correct 191 ms 26256 KB Output is correct
39 Correct 145 ms 22380 KB Output is correct
40 Correct 142 ms 22280 KB Output is correct
41 Correct 209 ms 23040 KB Output is correct
42 Correct 161 ms 23036 KB Output is correct
43 Correct 181 ms 23240 KB Output is correct
44 Correct 198 ms 23984 KB Output is correct
45 Correct 180 ms 23992 KB Output is correct
46 Correct 205 ms 23976 KB Output is correct
47 Correct 178 ms 24012 KB Output is correct
48 Correct 193 ms 24004 KB Output is correct
49 Correct 135 ms 21700 KB Output is correct
50 Correct 140 ms 21800 KB Output is correct
51 Correct 127 ms 21432 KB Output is correct
52 Correct 132 ms 21396 KB Output is correct
53 Correct 137 ms 21656 KB Output is correct
54 Correct 183 ms 23324 KB Output is correct
55 Correct 128 ms 18740 KB Output is correct
56 Correct 161 ms 22884 KB Output is correct
57 Correct 1286 ms 135432 KB Output is correct
58 Correct 1294 ms 135420 KB Output is correct
59 Correct 1260 ms 131884 KB Output is correct
60 Correct 1292 ms 131808 KB Output is correct
61 Correct 1219 ms 131824 KB Output is correct
62 Correct 1206 ms 131896 KB Output is correct
63 Correct 784 ms 107756 KB Output is correct
64 Correct 804 ms 107816 KB Output is correct
65 Correct 1129 ms 115748 KB Output is correct
66 Correct 1075 ms 115716 KB Output is correct
67 Correct 1103 ms 116036 KB Output is correct
68 Correct 1135 ms 119824 KB Output is correct
69 Correct 1144 ms 119644 KB Output is correct
70 Correct 1131 ms 118960 KB Output is correct
71 Correct 1144 ms 119096 KB Output is correct
72 Correct 1114 ms 119076 KB Output is correct
73 Correct 744 ms 105892 KB Output is correct
74 Correct 775 ms 106744 KB Output is correct
75 Correct 724 ms 105692 KB Output is correct
76 Correct 740 ms 105808 KB Output is correct
77 Correct 738 ms 106024 KB Output is correct
78 Correct 974 ms 114180 KB Output is correct
79 Correct 755 ms 86408 KB Output is correct
80 Correct 961 ms 119584 KB Output is correct