Submission #891166

# Submission time Handle Problem Language Result Execution time Memory
891166 2023-12-22T09:18:02 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1176 ms 125552 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//#pragma GCC optimization("g", on)
//#pragma GCC optimization("03")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("inline")
//#pragma GCC optimize("-fgcse,-fgcse-lm")
//#pragma GCC optimize("-ftree-pre,-ftree-vrp")
//#pragma GCC optimize("-ffast-math")
//#pragma GCC optimize("-fipa-sra")
//#pragma GCC optimize("-fpeephole2")
//#pragma GCC optimize("-fsched-spec")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
//#pragma GCC optimize("unroll-loops")

#define aboba ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define br break;
#define sp " "
#define en "\n"
#define pb push_back
#define sz size()
#define bg begin()
#define ed end()
#define in insert
#define ss second
#define ff first
#define setp(a) cout << fixed; cout << setprecision(a);
#define all(v) v.begin(), v.end()
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef double db;
typedef tree<
    long long,
    null_type,
    less_equal<long long>,
    rb_tree_tag,
    tree_order_statistics_node_update> orset;

void freopen(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); }
ll bp(ll x, ll y, ll z) { ll res = 1; while (y) { if (y & 1) { res = (res * x) % z; y--; } x = (x * x) % z; y >>= 1; } return res; }
// C(n, k) = ((fact[n] * bp(fact[k], mod - 2)) % mod * bp(fact[n - k], mod - 2)) % mod;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll lcm(ll a, ll b) { return (a / __gcd(a, b)) * b; }

const ll N = 1e6 + 11;
const ll inf = 1e9 + 7;
ll tt = 1;
ll a[N];
vector<pair<pll, ll>> g[N];
ll ans[N];
ll t[N * 4];

void upd(ll v, ll tl, ll tr, ll pos, ll x) {
	if (tl == tr) {
		t[v] = max(t[v], x);
		return;
	}
	ll tm = (tl + tr) / 2;
	if (pos <= tm) upd(v * 2, tl, tm, pos, x);
	else upd(v * 2 + 1, tm + 1, tr, pos, x);
	t[v] = max(t[v * 2], t[v * 2 + 1]);
}

ll get(ll v, ll tl, ll tr, ll l, ll r) {
	if (r < tl || tr < l) return 0;
	if (l <= tl && tr <= r) return t[v];
	ll tm = (tl + tr) / 2;
	return max(get(v * 2, tl, tm, l, r), get(v * 2 + 1, tm + 1, tr, l, r));
}

void solve() {
	ll n, m; cin >> n >> m;
	for (int i = 1;i <= n;i++) {
		cin >> a[i];
	}
	for (int i = 1;i <= m;i++) {
		ll l, r, x; cin >> l >> r >> x;
		g[r].pb({{l, x}, i});
	}
	stack<ll> st;
	for (int i = 1;i <= n;i++) {
		while (!st.empty() && a[st.top()] <= a[i]) st.pop();
		ll x = (st.empty() ? 0 : st.top());
		st.push(i);
		if (x) upd(1, 1, n, x, a[i] + a[x]);
		for (auto to : g[i]) {
			ll l = to.ff.ff, x = to.ff.ss;
			ans[to.ss] = (get(1, 1, n, l, i) <= x);
		}
	}
	for (int i = 1;i <= m;i++) {
		cout << ans[i] << en;
	}
}
   
int main() {      
    aboba    
//    freopen("cownomics");
//    precalc();
//    cin >> tt;
    for (int i = 1;i <= tt;i++) {
		solve();
    }
}

Compilation message

sortbooks.cpp: In function 'void freopen(std::string)':
sortbooks.cpp:47:33: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 | void freopen(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); }
      |                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:47:75: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 | void freopen(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); }
      |                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29020 KB Output is correct
2 Correct 6 ms 29116 KB Output is correct
3 Correct 6 ms 29020 KB Output is correct
4 Correct 6 ms 29024 KB Output is correct
5 Correct 6 ms 29136 KB Output is correct
6 Correct 7 ms 29020 KB Output is correct
7 Correct 6 ms 29204 KB Output is correct
8 Correct 6 ms 29020 KB Output is correct
9 Correct 6 ms 29132 KB Output is correct
10 Correct 6 ms 29020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29020 KB Output is correct
2 Correct 6 ms 29116 KB Output is correct
3 Correct 6 ms 29020 KB Output is correct
4 Correct 6 ms 29024 KB Output is correct
5 Correct 6 ms 29136 KB Output is correct
6 Correct 7 ms 29020 KB Output is correct
7 Correct 6 ms 29204 KB Output is correct
8 Correct 6 ms 29020 KB Output is correct
9 Correct 6 ms 29132 KB Output is correct
10 Correct 6 ms 29020 KB Output is correct
11 Correct 8 ms 29276 KB Output is correct
12 Correct 8 ms 29520 KB Output is correct
13 Correct 9 ms 29532 KB Output is correct
14 Correct 9 ms 29532 KB Output is correct
15 Correct 9 ms 29580 KB Output is correct
16 Correct 9 ms 29528 KB Output is correct
17 Correct 8 ms 29276 KB Output is correct
18 Correct 8 ms 29276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1176 ms 107356 KB Output is correct
2 Correct 1145 ms 107276 KB Output is correct
3 Correct 1149 ms 107368 KB Output is correct
4 Correct 1173 ms 107668 KB Output is correct
5 Correct 943 ms 90896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 35924 KB Output is correct
2 Correct 73 ms 36184 KB Output is correct
3 Correct 75 ms 33904 KB Output is correct
4 Correct 70 ms 34644 KB Output is correct
5 Correct 66 ms 34536 KB Output is correct
6 Correct 53 ms 34420 KB Output is correct
7 Correct 53 ms 34416 KB Output is correct
8 Correct 61 ms 34052 KB Output is correct
9 Correct 33 ms 33544 KB Output is correct
10 Correct 58 ms 34048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29020 KB Output is correct
2 Correct 6 ms 29116 KB Output is correct
3 Correct 6 ms 29020 KB Output is correct
4 Correct 6 ms 29024 KB Output is correct
5 Correct 6 ms 29136 KB Output is correct
6 Correct 7 ms 29020 KB Output is correct
7 Correct 6 ms 29204 KB Output is correct
8 Correct 6 ms 29020 KB Output is correct
9 Correct 6 ms 29132 KB Output is correct
10 Correct 6 ms 29020 KB Output is correct
11 Correct 8 ms 29276 KB Output is correct
12 Correct 8 ms 29520 KB Output is correct
13 Correct 9 ms 29532 KB Output is correct
14 Correct 9 ms 29532 KB Output is correct
15 Correct 9 ms 29580 KB Output is correct
16 Correct 9 ms 29528 KB Output is correct
17 Correct 8 ms 29276 KB Output is correct
18 Correct 8 ms 29276 KB Output is correct
19 Correct 185 ms 45760 KB Output is correct
20 Correct 170 ms 45748 KB Output is correct
21 Correct 154 ms 46276 KB Output is correct
22 Correct 151 ms 46452 KB Output is correct
23 Correct 151 ms 46164 KB Output is correct
24 Correct 150 ms 42068 KB Output is correct
25 Correct 121 ms 45136 KB Output is correct
26 Correct 140 ms 44884 KB Output is correct
27 Correct 136 ms 44804 KB Output is correct
28 Correct 145 ms 44884 KB Output is correct
29 Correct 151 ms 44536 KB Output is correct
30 Correct 155 ms 44628 KB Output is correct
31 Correct 150 ms 44628 KB Output is correct
32 Correct 160 ms 44616 KB Output is correct
33 Correct 145 ms 44628 KB Output is correct
34 Correct 114 ms 44384 KB Output is correct
35 Correct 113 ms 44372 KB Output is correct
36 Correct 114 ms 44192 KB Output is correct
37 Correct 114 ms 44324 KB Output is correct
38 Correct 112 ms 44540 KB Output is correct
39 Correct 137 ms 44032 KB Output is correct
40 Correct 102 ms 39424 KB Output is correct
41 Correct 134 ms 43008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 29020 KB Output is correct
2 Correct 6 ms 29116 KB Output is correct
3 Correct 6 ms 29020 KB Output is correct
4 Correct 6 ms 29024 KB Output is correct
5 Correct 6 ms 29136 KB Output is correct
6 Correct 7 ms 29020 KB Output is correct
7 Correct 6 ms 29204 KB Output is correct
8 Correct 6 ms 29020 KB Output is correct
9 Correct 6 ms 29132 KB Output is correct
10 Correct 6 ms 29020 KB Output is correct
11 Correct 8 ms 29276 KB Output is correct
12 Correct 8 ms 29520 KB Output is correct
13 Correct 9 ms 29532 KB Output is correct
14 Correct 9 ms 29532 KB Output is correct
15 Correct 9 ms 29580 KB Output is correct
16 Correct 9 ms 29528 KB Output is correct
17 Correct 8 ms 29276 KB Output is correct
18 Correct 8 ms 29276 KB Output is correct
19 Correct 1176 ms 107356 KB Output is correct
20 Correct 1145 ms 107276 KB Output is correct
21 Correct 1149 ms 107368 KB Output is correct
22 Correct 1173 ms 107668 KB Output is correct
23 Correct 943 ms 90896 KB Output is correct
24 Correct 76 ms 35924 KB Output is correct
25 Correct 73 ms 36184 KB Output is correct
26 Correct 75 ms 33904 KB Output is correct
27 Correct 70 ms 34644 KB Output is correct
28 Correct 66 ms 34536 KB Output is correct
29 Correct 53 ms 34420 KB Output is correct
30 Correct 53 ms 34416 KB Output is correct
31 Correct 61 ms 34052 KB Output is correct
32 Correct 33 ms 33544 KB Output is correct
33 Correct 58 ms 34048 KB Output is correct
34 Correct 185 ms 45760 KB Output is correct
35 Correct 170 ms 45748 KB Output is correct
36 Correct 154 ms 46276 KB Output is correct
37 Correct 151 ms 46452 KB Output is correct
38 Correct 151 ms 46164 KB Output is correct
39 Correct 150 ms 42068 KB Output is correct
40 Correct 121 ms 45136 KB Output is correct
41 Correct 140 ms 44884 KB Output is correct
42 Correct 136 ms 44804 KB Output is correct
43 Correct 145 ms 44884 KB Output is correct
44 Correct 151 ms 44536 KB Output is correct
45 Correct 155 ms 44628 KB Output is correct
46 Correct 150 ms 44628 KB Output is correct
47 Correct 160 ms 44616 KB Output is correct
48 Correct 145 ms 44628 KB Output is correct
49 Correct 114 ms 44384 KB Output is correct
50 Correct 113 ms 44372 KB Output is correct
51 Correct 114 ms 44192 KB Output is correct
52 Correct 114 ms 44324 KB Output is correct
53 Correct 112 ms 44540 KB Output is correct
54 Correct 137 ms 44032 KB Output is correct
55 Correct 102 ms 39424 KB Output is correct
56 Correct 134 ms 43008 KB Output is correct
57 Correct 1107 ms 124408 KB Output is correct
58 Correct 1113 ms 124380 KB Output is correct
59 Correct 1058 ms 125368 KB Output is correct
60 Correct 1170 ms 125540 KB Output is correct
61 Correct 1065 ms 125260 KB Output is correct
62 Correct 1069 ms 125552 KB Output is correct
63 Correct 606 ms 108952 KB Output is correct
64 Correct 634 ms 109196 KB Output is correct
65 Correct 865 ms 109164 KB Output is correct
66 Correct 947 ms 108652 KB Output is correct
67 Correct 896 ms 108880 KB Output is correct
68 Correct 916 ms 107956 KB Output is correct
69 Correct 968 ms 107972 KB Output is correct
70 Correct 928 ms 108180 KB Output is correct
71 Correct 949 ms 108320 KB Output is correct
72 Correct 944 ms 108208 KB Output is correct
73 Correct 572 ms 106928 KB Output is correct
74 Correct 563 ms 107892 KB Output is correct
75 Correct 580 ms 106688 KB Output is correct
76 Correct 560 ms 107344 KB Output is correct
77 Correct 572 ms 106880 KB Output is correct
78 Correct 783 ms 105300 KB Output is correct
79 Correct 616 ms 89660 KB Output is correct
80 Correct 785 ms 97516 KB Output is correct