Submission #893868

# Submission time Handle Problem Language Result Execution time Memory
893868 2023-12-27T15:16:27 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1337 ms 109604 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
// #pragma GCC optimize("Ofast,unroll-loops,fast-math")
// #pragma GCC target("popcnt")


typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
 
#define sz size()
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define pb push_back

const int mod = ll(1e9)+7; //(b + (a%b)) % b (to mod -1%(10^9+7) correctly in c++ its -1 but its suppose to be 10^9+6
const ll MOD = 998244353;  // (a%mod)*(binpow(b,mod-2,mod) = (a/b)%mod
const int N = ll(1e6)+100;
const long long inf = 2e18;
const long double eps = 1e-15L;
 
ll lcm(ll a, ll b) { return (a / __gcd(a,b))*b; }

ll binpow(ll a, ll b, ll m) { ll res=1; a %= m; while(b>0){ if(b&1)res=(res * a) % m; a=(a * a) % m; b/=2; } return res%m;}


void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }

int n, m, a[N], ans[N], pos[N], t[N*4];
int ql[N], qr[N], qk[N];
vector<int> q[N];

void build(int v, int tl, int tr) {
	if(tl == tr) {
		t[v] = 0;
		return;
	}
	int tm = (tl + tr) / 2;
	build(v + v, tl, tm);
	build(v + v + 1, tm + 1, tr);
	t[v] = max(t[v + v], t[v + v + 1]);
}


void update(int v, int tl, int tr, int p, int x) {
	if(tl == tr) {
		t[v] = x;
		return;
	}
	int tm = (tl + tr) / 2;
	if(p <= tm) update(v + v, tl, tm, p, x);
	else update(v + v + 1, tm + 1, tr, p, x);
	t[v] = max(t[v + v], t[v + v + 1]);
}

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

void Baizho() {	
	cin>>n>>m;
	for(int i = 1; i <= n; i ++) {
		cin>>a[i];
	}
	build(1, 1, n);
	for(int i = 1; i <= m; i ++) {
		cin>>ql[i]>>qr[i]>>qk[i];
		q[qr[i]].pb(i);
	}
	vector<int> st;
	for(int i = 1; i <= n; i ++) {
		while(!st.empty() && a[st.back()] <= a[i]) st.pop_back();
		if(!st.empty()) pos[i] = st.back();
		st.pb(i);
	}
	for(int i = 1; i <= n; i ++) {
		if(pos[i]) {
			update(1, 1, n, pos[i], a[pos[i]] + a[i]);	
		}
		for(auto j : q[i]) {
			ans[j] = (get(1, 1, n, ql[j], qr[j]) <= qk[j]);
		}
	}
	for(int i = 1; i <= m; i ++) cout<<ans[i]<<"\n";
	
}
 
signed main() {		
 
    ios_base::sync_with_stdio(false);   
    cin.tie(0);cout.tie(0); 
//   	precalc();
   	
    int ttt = 1;
//    cin>>ttt;

    for(int i=1; i<=ttt; i++) { Baizho(); }
}

Compilation message

sortbooks.cpp: In function 'void Freopen(std::string)':
sortbooks.cpp:35:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
      |                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:35:76: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
      |                                                                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 37464 KB Output is correct
2 Correct 7 ms 35672 KB Output is correct
3 Correct 10 ms 37468 KB Output is correct
4 Correct 7 ms 37464 KB Output is correct
5 Correct 7 ms 37468 KB Output is correct
6 Correct 7 ms 37468 KB Output is correct
7 Correct 8 ms 37720 KB Output is correct
8 Correct 7 ms 37508 KB Output is correct
9 Correct 7 ms 37720 KB Output is correct
10 Correct 8 ms 37592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 37464 KB Output is correct
2 Correct 7 ms 35672 KB Output is correct
3 Correct 10 ms 37468 KB Output is correct
4 Correct 7 ms 37464 KB Output is correct
5 Correct 7 ms 37468 KB Output is correct
6 Correct 7 ms 37468 KB Output is correct
7 Correct 8 ms 37720 KB Output is correct
8 Correct 7 ms 37508 KB Output is correct
9 Correct 7 ms 37720 KB Output is correct
10 Correct 8 ms 37592 KB Output is correct
11 Correct 9 ms 37464 KB Output is correct
12 Correct 9 ms 37724 KB Output is correct
13 Correct 9 ms 37724 KB Output is correct
14 Correct 10 ms 37772 KB Output is correct
15 Correct 10 ms 37776 KB Output is correct
16 Correct 10 ms 37724 KB Output is correct
17 Correct 9 ms 37724 KB Output is correct
18 Correct 9 ms 37736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1282 ms 108372 KB Output is correct
2 Correct 1337 ms 109592 KB Output is correct
3 Correct 1245 ms 108912 KB Output is correct
4 Correct 1230 ms 109604 KB Output is correct
5 Correct 1104 ms 105068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 41300 KB Output is correct
2 Correct 78 ms 40496 KB Output is correct
3 Correct 66 ms 38876 KB Output is correct
4 Correct 69 ms 39248 KB Output is correct
5 Correct 69 ms 39252 KB Output is correct
6 Correct 59 ms 39964 KB Output is correct
7 Correct 65 ms 40024 KB Output is correct
8 Correct 63 ms 40740 KB Output is correct
9 Correct 34 ms 39388 KB Output is correct
10 Correct 61 ms 40732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 37464 KB Output is correct
2 Correct 7 ms 35672 KB Output is correct
3 Correct 10 ms 37468 KB Output is correct
4 Correct 7 ms 37464 KB Output is correct
5 Correct 7 ms 37468 KB Output is correct
6 Correct 7 ms 37468 KB Output is correct
7 Correct 8 ms 37720 KB Output is correct
8 Correct 7 ms 37508 KB Output is correct
9 Correct 7 ms 37720 KB Output is correct
10 Correct 8 ms 37592 KB Output is correct
11 Correct 9 ms 37464 KB Output is correct
12 Correct 9 ms 37724 KB Output is correct
13 Correct 9 ms 37724 KB Output is correct
14 Correct 10 ms 37772 KB Output is correct
15 Correct 10 ms 37776 KB Output is correct
16 Correct 10 ms 37724 KB Output is correct
17 Correct 9 ms 37724 KB Output is correct
18 Correct 9 ms 37736 KB Output is correct
19 Correct 186 ms 51216 KB Output is correct
20 Correct 191 ms 51284 KB Output is correct
21 Correct 152 ms 49560 KB Output is correct
22 Correct 158 ms 49492 KB Output is correct
23 Correct 166 ms 49488 KB Output is correct
24 Correct 129 ms 45072 KB Output is correct
25 Correct 126 ms 45136 KB Output is correct
26 Correct 170 ms 45952 KB Output is correct
27 Correct 146 ms 46036 KB Output is correct
28 Correct 160 ms 46416 KB Output is correct
29 Correct 171 ms 47348 KB Output is correct
30 Correct 151 ms 47184 KB Output is correct
31 Correct 165 ms 47144 KB Output is correct
32 Correct 168 ms 47192 KB Output is correct
33 Correct 151 ms 47136 KB Output is correct
34 Correct 122 ms 47052 KB Output is correct
35 Correct 126 ms 46908 KB Output is correct
36 Correct 125 ms 46652 KB Output is correct
37 Correct 127 ms 46780 KB Output is correct
38 Correct 134 ms 46908 KB Output is correct
39 Correct 159 ms 47852 KB Output is correct
40 Correct 111 ms 44788 KB Output is correct
41 Correct 128 ms 49556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 37464 KB Output is correct
2 Correct 7 ms 35672 KB Output is correct
3 Correct 10 ms 37468 KB Output is correct
4 Correct 7 ms 37464 KB Output is correct
5 Correct 7 ms 37468 KB Output is correct
6 Correct 7 ms 37468 KB Output is correct
7 Correct 8 ms 37720 KB Output is correct
8 Correct 7 ms 37508 KB Output is correct
9 Correct 7 ms 37720 KB Output is correct
10 Correct 8 ms 37592 KB Output is correct
11 Correct 9 ms 37464 KB Output is correct
12 Correct 9 ms 37724 KB Output is correct
13 Correct 9 ms 37724 KB Output is correct
14 Correct 10 ms 37772 KB Output is correct
15 Correct 10 ms 37776 KB Output is correct
16 Correct 10 ms 37724 KB Output is correct
17 Correct 9 ms 37724 KB Output is correct
18 Correct 9 ms 37736 KB Output is correct
19 Correct 1282 ms 108372 KB Output is correct
20 Correct 1337 ms 109592 KB Output is correct
21 Correct 1245 ms 108912 KB Output is correct
22 Correct 1230 ms 109604 KB Output is correct
23 Correct 1104 ms 105068 KB Output is correct
24 Correct 76 ms 41300 KB Output is correct
25 Correct 78 ms 40496 KB Output is correct
26 Correct 66 ms 38876 KB Output is correct
27 Correct 69 ms 39248 KB Output is correct
28 Correct 69 ms 39252 KB Output is correct
29 Correct 59 ms 39964 KB Output is correct
30 Correct 65 ms 40024 KB Output is correct
31 Correct 63 ms 40740 KB Output is correct
32 Correct 34 ms 39388 KB Output is correct
33 Correct 61 ms 40732 KB Output is correct
34 Correct 186 ms 51216 KB Output is correct
35 Correct 191 ms 51284 KB Output is correct
36 Correct 152 ms 49560 KB Output is correct
37 Correct 158 ms 49492 KB Output is correct
38 Correct 166 ms 49488 KB Output is correct
39 Correct 129 ms 45072 KB Output is correct
40 Correct 126 ms 45136 KB Output is correct
41 Correct 170 ms 45952 KB Output is correct
42 Correct 146 ms 46036 KB Output is correct
43 Correct 160 ms 46416 KB Output is correct
44 Correct 171 ms 47348 KB Output is correct
45 Correct 151 ms 47184 KB Output is correct
46 Correct 165 ms 47144 KB Output is correct
47 Correct 168 ms 47192 KB Output is correct
48 Correct 151 ms 47136 KB Output is correct
49 Correct 122 ms 47052 KB Output is correct
50 Correct 126 ms 46908 KB Output is correct
51 Correct 125 ms 46652 KB Output is correct
52 Correct 127 ms 46780 KB Output is correct
53 Correct 134 ms 46908 KB Output is correct
54 Correct 159 ms 47852 KB Output is correct
55 Correct 111 ms 44788 KB Output is correct
56 Correct 128 ms 49556 KB Output is correct
57 Correct 1273 ms 107940 KB Output is correct
58 Correct 1175 ms 107928 KB Output is correct
59 Correct 1111 ms 103848 KB Output is correct
60 Correct 1074 ms 103844 KB Output is correct
61 Correct 1093 ms 103844 KB Output is correct
62 Correct 1153 ms 103788 KB Output is correct
63 Correct 742 ms 87808 KB Output is correct
64 Correct 688 ms 87820 KB Output is correct
65 Correct 963 ms 96300 KB Output is correct
66 Correct 1008 ms 96148 KB Output is correct
67 Correct 929 ms 96472 KB Output is correct
68 Correct 1074 ms 101024 KB Output is correct
69 Correct 1052 ms 101008 KB Output is correct
70 Correct 1110 ms 100456 KB Output is correct
71 Correct 1034 ms 100084 KB Output is correct
72 Correct 1068 ms 100036 KB Output is correct
73 Correct 692 ms 88012 KB Output is correct
74 Correct 639 ms 88872 KB Output is correct
75 Correct 690 ms 88004 KB Output is correct
76 Correct 625 ms 87856 KB Output is correct
77 Correct 690 ms 87936 KB Output is correct
78 Correct 928 ms 95292 KB Output is correct
79 Correct 654 ms 83220 KB Output is correct
80 Correct 899 ms 93116 KB Output is correct