Submission #868450

# Submission time Handle Problem Language Result Execution time Memory
868450 2023-10-31T13:40:30 Z KiaRez Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1706 ms 150052 KB
/*
    IN THE NAME OF GOD
*/
#include <bits/stdc++.h>

// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;

#define F                                      first
#define S                                      second
#define Mp                                     make_pair
#define pb                                     push_back
#define pf                                     push_front
#define size(x)                                ((ll)x.size())
#define all(x)                                 (x).begin(),(x).end()
#define kill(x)		                           cout << x << '\n', exit(0);
#define fuck(x)                                cout << "(" << #x << " , " << x << ")" << endl
#define endl                                   '\n'

const int N = 1e6+23, lg = 20;
ll Mod = 1e9+7; //998244353;

inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
    ll ans = 1;
    a=MOD(a, mod);
    while (b) {
        if (b & 1) ans = MOD(ans*a, mod);
        b >>= 1;
        a = MOD(a*a, mod);
    }
    return ans;
}

int n, m, a[N], ans[N], ptr=1;
vector<vector<int>> q[N];
int seg[4*N], lazy[4*N];

inline void pushdown(int ind) {
	if(lazy[ind] == 0) return;
	seg[ind] += lazy[ind];
	if(ind < (1<<lg)) {
		lazy[2*ind] += lazy[ind];
		lazy[2*ind+1] += lazy[ind];
	}
	lazy[ind] = 0;
}

void update(int l, int r, int val, int ind=1, int lc=1, int rc=(1<<lg)+1) {
	if(lc>=l && rc<=r) {
		lazy[ind] += val;
		pushdown(ind);
		return;
	}
	pushdown(ind);
	if(lc>=r || l>=rc) {
		return;
	}
	int mid = (lc+rc)/2;
	update(l, r, val, 2*ind, lc, mid);
	update(l, r, val, 2*ind+1, mid, rc);
	seg[ind] = max(seg[2*ind], seg[2*ind+1]);
}

int query(int l, int r, int ind=1, int lc=1, int rc=(1<<lg)+1) {
	pushdown(ind);
	if(lc>=l && rc<=r) {
		return seg[ind];
	}
	if(lc>=r || l>=rc) {
		return 0;
	}
	int mid = (lc+rc)/2;
	return max(query(l, r, 2*ind, lc, mid), query(l, r, 2*ind+1, mid, rc));
}

vector<int> st;
int main () {
	ios_base::sync_with_stdio(false), cin.tie(0);

	cin>>n>>m;
	for(int i=1; i<=n; i++) {
		cin>>a[i];
	}
	for(int l,r,k,i=1; i<=m; i++) {
		cin>>l>>r>>k;
		q[l].pb({r, k, i});
	}

	a[n+1] = (int)2e9;
	st.pb(n+1);
	for(int i=n; i>=1; i--) {
		//update(i, i+1, a[i]);
		while(size(st)>0 && a[i] > a[st.back()]) {
			int tmp = st.back();
			st.pop_back();
			update(tmp, tmp+1, a[i]+a[tmp]);
			update(tmp+1, st.back(), a[i]-a[tmp]);
		}
		st.pb(i);

		for(auto it : q[i]) {
			if(query(i, it[0]+1) <= it[1]) {
				ans[it[2]] = 1;
			}
		}
	}

	for(int i=1; i<=m; i++) cout<<ans[i]<<'\n';

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33116 KB Output is correct
2 Correct 6 ms 26972 KB Output is correct
3 Correct 7 ms 33112 KB Output is correct
4 Correct 7 ms 33116 KB Output is correct
5 Correct 7 ms 33116 KB Output is correct
6 Correct 8 ms 33372 KB Output is correct
7 Correct 7 ms 33372 KB Output is correct
8 Correct 7 ms 27100 KB Output is correct
9 Correct 7 ms 27224 KB Output is correct
10 Correct 7 ms 27228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33116 KB Output is correct
2 Correct 6 ms 26972 KB Output is correct
3 Correct 7 ms 33112 KB Output is correct
4 Correct 7 ms 33116 KB Output is correct
5 Correct 7 ms 33116 KB Output is correct
6 Correct 8 ms 33372 KB Output is correct
7 Correct 7 ms 33372 KB Output is correct
8 Correct 7 ms 27100 KB Output is correct
9 Correct 7 ms 27224 KB Output is correct
10 Correct 7 ms 27228 KB Output is correct
11 Correct 10 ms 33372 KB Output is correct
12 Correct 11 ms 33568 KB Output is correct
13 Correct 12 ms 33628 KB Output is correct
14 Correct 13 ms 33628 KB Output is correct
15 Correct 13 ms 33832 KB Output is correct
16 Correct 9 ms 27736 KB Output is correct
17 Correct 9 ms 27492 KB Output is correct
18 Correct 11 ms 27484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1686 ms 116328 KB Output is correct
2 Correct 1667 ms 115740 KB Output is correct
3 Correct 1690 ms 148692 KB Output is correct
4 Correct 1706 ms 148992 KB Output is correct
5 Correct 1202 ms 134684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 38936 KB Output is correct
2 Correct 115 ms 42584 KB Output is correct
3 Correct 81 ms 36048 KB Output is correct
4 Correct 88 ms 36056 KB Output is correct
5 Correct 84 ms 36072 KB Output is correct
6 Correct 73 ms 41940 KB Output is correct
7 Correct 75 ms 41932 KB Output is correct
8 Correct 117 ms 36548 KB Output is correct
9 Correct 51 ms 34504 KB Output is correct
10 Correct 109 ms 36104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33116 KB Output is correct
2 Correct 6 ms 26972 KB Output is correct
3 Correct 7 ms 33112 KB Output is correct
4 Correct 7 ms 33116 KB Output is correct
5 Correct 7 ms 33116 KB Output is correct
6 Correct 8 ms 33372 KB Output is correct
7 Correct 7 ms 33372 KB Output is correct
8 Correct 7 ms 27100 KB Output is correct
9 Correct 7 ms 27224 KB Output is correct
10 Correct 7 ms 27228 KB Output is correct
11 Correct 10 ms 33372 KB Output is correct
12 Correct 11 ms 33568 KB Output is correct
13 Correct 12 ms 33628 KB Output is correct
14 Correct 13 ms 33628 KB Output is correct
15 Correct 13 ms 33832 KB Output is correct
16 Correct 9 ms 27736 KB Output is correct
17 Correct 9 ms 27492 KB Output is correct
18 Correct 11 ms 27484 KB Output is correct
19 Correct 336 ms 53368 KB Output is correct
20 Correct 314 ms 53148 KB Output is correct
21 Correct 285 ms 54844 KB Output is correct
22 Correct 284 ms 54876 KB Output is correct
23 Correct 283 ms 54892 KB Output is correct
24 Correct 190 ms 48128 KB Output is correct
25 Correct 227 ms 47988 KB Output is correct
26 Correct 194 ms 47816 KB Output is correct
27 Correct 201 ms 47708 KB Output is correct
28 Correct 244 ms 47796 KB Output is correct
29 Correct 196 ms 47768 KB Output is correct
30 Correct 213 ms 47568 KB Output is correct
31 Correct 212 ms 47764 KB Output is correct
32 Correct 218 ms 47612 KB Output is correct
33 Correct 200 ms 47544 KB Output is correct
34 Correct 155 ms 53048 KB Output is correct
35 Correct 169 ms 53072 KB Output is correct
36 Correct 163 ms 52952 KB Output is correct
37 Correct 151 ms 52856 KB Output is correct
38 Correct 172 ms 53040 KB Output is correct
39 Correct 205 ms 47504 KB Output is correct
40 Correct 151 ms 45232 KB Output is correct
41 Correct 205 ms 46984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33116 KB Output is correct
2 Correct 6 ms 26972 KB Output is correct
3 Correct 7 ms 33112 KB Output is correct
4 Correct 7 ms 33116 KB Output is correct
5 Correct 7 ms 33116 KB Output is correct
6 Correct 8 ms 33372 KB Output is correct
7 Correct 7 ms 33372 KB Output is correct
8 Correct 7 ms 27100 KB Output is correct
9 Correct 7 ms 27224 KB Output is correct
10 Correct 7 ms 27228 KB Output is correct
11 Correct 10 ms 33372 KB Output is correct
12 Correct 11 ms 33568 KB Output is correct
13 Correct 12 ms 33628 KB Output is correct
14 Correct 13 ms 33628 KB Output is correct
15 Correct 13 ms 33832 KB Output is correct
16 Correct 9 ms 27736 KB Output is correct
17 Correct 9 ms 27492 KB Output is correct
18 Correct 11 ms 27484 KB Output is correct
19 Correct 1686 ms 116328 KB Output is correct
20 Correct 1667 ms 115740 KB Output is correct
21 Correct 1690 ms 148692 KB Output is correct
22 Correct 1706 ms 148992 KB Output is correct
23 Correct 1202 ms 134684 KB Output is correct
24 Correct 126 ms 38936 KB Output is correct
25 Correct 115 ms 42584 KB Output is correct
26 Correct 81 ms 36048 KB Output is correct
27 Correct 88 ms 36056 KB Output is correct
28 Correct 84 ms 36072 KB Output is correct
29 Correct 73 ms 41940 KB Output is correct
30 Correct 75 ms 41932 KB Output is correct
31 Correct 117 ms 36548 KB Output is correct
32 Correct 51 ms 34504 KB Output is correct
33 Correct 109 ms 36104 KB Output is correct
34 Correct 336 ms 53368 KB Output is correct
35 Correct 314 ms 53148 KB Output is correct
36 Correct 285 ms 54844 KB Output is correct
37 Correct 284 ms 54876 KB Output is correct
38 Correct 283 ms 54892 KB Output is correct
39 Correct 190 ms 48128 KB Output is correct
40 Correct 227 ms 47988 KB Output is correct
41 Correct 194 ms 47816 KB Output is correct
42 Correct 201 ms 47708 KB Output is correct
43 Correct 244 ms 47796 KB Output is correct
44 Correct 196 ms 47768 KB Output is correct
45 Correct 213 ms 47568 KB Output is correct
46 Correct 212 ms 47764 KB Output is correct
47 Correct 218 ms 47612 KB Output is correct
48 Correct 200 ms 47544 KB Output is correct
49 Correct 155 ms 53048 KB Output is correct
50 Correct 169 ms 53072 KB Output is correct
51 Correct 163 ms 52952 KB Output is correct
52 Correct 151 ms 52856 KB Output is correct
53 Correct 172 ms 53040 KB Output is correct
54 Correct 205 ms 47504 KB Output is correct
55 Correct 151 ms 45232 KB Output is correct
56 Correct 205 ms 46984 KB Output is correct
57 Correct 1668 ms 148368 KB Output is correct
58 Correct 1696 ms 148024 KB Output is correct
59 Correct 1643 ms 149748 KB Output is correct
60 Correct 1657 ms 149584 KB Output is correct
61 Correct 1615 ms 150052 KB Output is correct
62 Correct 1610 ms 149984 KB Output is correct
63 Correct 1034 ms 131752 KB Output is correct
64 Correct 977 ms 132468 KB Output is correct
65 Correct 1248 ms 135780 KB Output is correct
66 Correct 1170 ms 135848 KB Output is correct
67 Correct 1232 ms 135896 KB Output is correct
68 Correct 1217 ms 135428 KB Output is correct
69 Correct 1246 ms 135072 KB Output is correct
70 Correct 1220 ms 135372 KB Output is correct
71 Correct 1207 ms 135212 KB Output is correct
72 Correct 1243 ms 135256 KB Output is correct
73 Correct 887 ms 135884 KB Output is correct
74 Correct 881 ms 136460 KB Output is correct
75 Correct 948 ms 135424 KB Output is correct
76 Correct 976 ms 135320 KB Output is correct
77 Correct 1018 ms 135916 KB Output is correct
78 Correct 1289 ms 135124 KB Output is correct
79 Correct 787 ms 120300 KB Output is correct
80 Correct 1262 ms 134380 KB Output is correct