Submission #690832

# Submission time Handle Problem Language Result Execution time Memory
690832 2023-01-30T12:53:59 Z Nuraly_Serikbay Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1431 ms 100236 KB
/* Speech to the young */
 
//#include <bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#include <unordered_map>
 
using namespace std;
 
#define pb push_back
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define YOSIK() ios_base::sync_with_stdio(0),cin.tie(0)
#define int long long
#define pans cout << "\n------ans-------\n" 
 
const int N = 1e6 + 10;
const int INF = 1e18 + 7;
const int MOD = 1e9 + 7;
const int P = 31;
 
int n, m, t[N * 4];
int a[N], res[N], l[N], r[N], k[N];
vector <int> qu[N]; 

void upd (int v, int tl, int tr, int pos, int val) {
	if (tl == tr) {
		t[v] = max (t[v], val);
		return;
	}
	int mid = (tl + tr) >> 1;
	if (pos <= mid) upd (v + v, tl, mid, pos, val);
	else upd (v + v + 1, mid + 1, tr, pos, val);
	t[v] = max (t[v + v], t[v + v + 1]);
	return;
}

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


void Solution () {
	cin >> n >> m;
	for (int i = 1; i <= n; ++ i) cin >> a[i];
	stack <int> s;
	for (int i = 1; i <= m; ++ i) {
		cin >> l[i] >> r[i] >> k[i];
		qu[r[i]].pb (i);
	}
	s.push (0);
	a[0] = INF;
	for (int i = 1; i <= n; ++ i) {
		while (a[s.top()] <= a[i]) s.pop();
		if (s.top() != 0) upd (1, 1, n, s.top(), a[s.top()] + a[i]);
		s.push (i);
		for (auto to: qu[i]) if (get (1, 1, n, l[to], i) <= k[to]) res[to] = 1;
	}
	for (int i = 1; i <= m; ++ i) cout << res[i] << '\n';
	return;
}
 
signed main () {
	YOSIK();
//	precalc();
	int T = 1; 
	//cin >> T;
	while (T --) Solution ();
	exit (0);
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23816 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Correct 14 ms 23856 KB Output is correct
4 Correct 14 ms 23764 KB Output is correct
5 Correct 15 ms 23924 KB Output is correct
6 Correct 11 ms 23892 KB Output is correct
7 Correct 12 ms 23892 KB Output is correct
8 Correct 11 ms 23892 KB Output is correct
9 Correct 11 ms 23824 KB Output is correct
10 Correct 12 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23816 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Correct 14 ms 23856 KB Output is correct
4 Correct 14 ms 23764 KB Output is correct
5 Correct 15 ms 23924 KB Output is correct
6 Correct 11 ms 23892 KB Output is correct
7 Correct 12 ms 23892 KB Output is correct
8 Correct 11 ms 23892 KB Output is correct
9 Correct 11 ms 23824 KB Output is correct
10 Correct 12 ms 23764 KB Output is correct
11 Correct 13 ms 24020 KB Output is correct
12 Correct 17 ms 24148 KB Output is correct
13 Correct 15 ms 24148 KB Output is correct
14 Correct 16 ms 24244 KB Output is correct
15 Correct 16 ms 24252 KB Output is correct
16 Correct 14 ms 24192 KB Output is correct
17 Correct 14 ms 24140 KB Output is correct
18 Correct 14 ms 24112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1364 ms 93552 KB Output is correct
2 Correct 1431 ms 93268 KB Output is correct
3 Correct 1366 ms 93408 KB Output is correct
4 Correct 1413 ms 93340 KB Output is correct
5 Correct 1095 ms 84928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 31928 KB Output is correct
2 Correct 95 ms 31324 KB Output is correct
3 Correct 89 ms 29668 KB Output is correct
4 Correct 79 ms 29688 KB Output is correct
5 Correct 80 ms 29792 KB Output is correct
6 Correct 71 ms 28280 KB Output is correct
7 Correct 75 ms 28236 KB Output is correct
8 Correct 100 ms 29720 KB Output is correct
9 Correct 47 ms 28116 KB Output is correct
10 Correct 77 ms 29760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23816 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Correct 14 ms 23856 KB Output is correct
4 Correct 14 ms 23764 KB Output is correct
5 Correct 15 ms 23924 KB Output is correct
6 Correct 11 ms 23892 KB Output is correct
7 Correct 12 ms 23892 KB Output is correct
8 Correct 11 ms 23892 KB Output is correct
9 Correct 11 ms 23824 KB Output is correct
10 Correct 12 ms 23764 KB Output is correct
11 Correct 13 ms 24020 KB Output is correct
12 Correct 17 ms 24148 KB Output is correct
13 Correct 15 ms 24148 KB Output is correct
14 Correct 16 ms 24244 KB Output is correct
15 Correct 16 ms 24252 KB Output is correct
16 Correct 14 ms 24192 KB Output is correct
17 Correct 14 ms 24140 KB Output is correct
18 Correct 14 ms 24112 KB Output is correct
19 Correct 250 ms 39952 KB Output is correct
20 Correct 239 ms 40016 KB Output is correct
21 Correct 181 ms 38932 KB Output is correct
22 Correct 205 ms 38848 KB Output is correct
23 Correct 184 ms 38888 KB Output is correct
24 Correct 153 ms 34688 KB Output is correct
25 Correct 152 ms 34680 KB Output is correct
26 Correct 181 ms 35220 KB Output is correct
27 Correct 182 ms 35156 KB Output is correct
28 Correct 200 ms 35368 KB Output is correct
29 Correct 216 ms 35916 KB Output is correct
30 Correct 221 ms 35920 KB Output is correct
31 Correct 196 ms 35968 KB Output is correct
32 Correct 187 ms 35864 KB Output is correct
33 Correct 199 ms 35860 KB Output is correct
34 Correct 164 ms 34500 KB Output is correct
35 Correct 150 ms 34468 KB Output is correct
36 Correct 160 ms 34380 KB Output is correct
37 Correct 159 ms 34460 KB Output is correct
38 Correct 150 ms 34368 KB Output is correct
39 Correct 165 ms 36952 KB Output is correct
40 Correct 149 ms 34756 KB Output is correct
41 Correct 170 ms 35840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23816 KB Output is correct
2 Correct 13 ms 23756 KB Output is correct
3 Correct 14 ms 23856 KB Output is correct
4 Correct 14 ms 23764 KB Output is correct
5 Correct 15 ms 23924 KB Output is correct
6 Correct 11 ms 23892 KB Output is correct
7 Correct 12 ms 23892 KB Output is correct
8 Correct 11 ms 23892 KB Output is correct
9 Correct 11 ms 23824 KB Output is correct
10 Correct 12 ms 23764 KB Output is correct
11 Correct 13 ms 24020 KB Output is correct
12 Correct 17 ms 24148 KB Output is correct
13 Correct 15 ms 24148 KB Output is correct
14 Correct 16 ms 24244 KB Output is correct
15 Correct 16 ms 24252 KB Output is correct
16 Correct 14 ms 24192 KB Output is correct
17 Correct 14 ms 24140 KB Output is correct
18 Correct 14 ms 24112 KB Output is correct
19 Correct 1364 ms 93552 KB Output is correct
20 Correct 1431 ms 93268 KB Output is correct
21 Correct 1366 ms 93408 KB Output is correct
22 Correct 1413 ms 93340 KB Output is correct
23 Correct 1095 ms 84928 KB Output is correct
24 Correct 109 ms 31928 KB Output is correct
25 Correct 95 ms 31324 KB Output is correct
26 Correct 89 ms 29668 KB Output is correct
27 Correct 79 ms 29688 KB Output is correct
28 Correct 80 ms 29792 KB Output is correct
29 Correct 71 ms 28280 KB Output is correct
30 Correct 75 ms 28236 KB Output is correct
31 Correct 100 ms 29720 KB Output is correct
32 Correct 47 ms 28116 KB Output is correct
33 Correct 77 ms 29760 KB Output is correct
34 Correct 250 ms 39952 KB Output is correct
35 Correct 239 ms 40016 KB Output is correct
36 Correct 181 ms 38932 KB Output is correct
37 Correct 205 ms 38848 KB Output is correct
38 Correct 184 ms 38888 KB Output is correct
39 Correct 153 ms 34688 KB Output is correct
40 Correct 152 ms 34680 KB Output is correct
41 Correct 181 ms 35220 KB Output is correct
42 Correct 182 ms 35156 KB Output is correct
43 Correct 200 ms 35368 KB Output is correct
44 Correct 216 ms 35916 KB Output is correct
45 Correct 221 ms 35920 KB Output is correct
46 Correct 196 ms 35968 KB Output is correct
47 Correct 187 ms 35864 KB Output is correct
48 Correct 199 ms 35860 KB Output is correct
49 Correct 164 ms 34500 KB Output is correct
50 Correct 150 ms 34468 KB Output is correct
51 Correct 160 ms 34380 KB Output is correct
52 Correct 159 ms 34460 KB Output is correct
53 Correct 150 ms 34368 KB Output is correct
54 Correct 165 ms 36952 KB Output is correct
55 Correct 149 ms 34756 KB Output is correct
56 Correct 170 ms 35840 KB Output is correct
57 Correct 1415 ms 100236 KB Output is correct
58 Correct 1369 ms 100168 KB Output is correct
59 Correct 1296 ms 97428 KB Output is correct
60 Correct 1271 ms 97524 KB Output is correct
61 Correct 1284 ms 97484 KB Output is correct
62 Correct 1267 ms 97452 KB Output is correct
63 Correct 820 ms 77516 KB Output is correct
64 Correct 842 ms 77484 KB Output is correct
65 Correct 1036 ms 80844 KB Output is correct
66 Correct 1043 ms 80852 KB Output is correct
67 Correct 1067 ms 80984 KB Output is correct
68 Correct 1109 ms 83952 KB Output is correct
69 Correct 1121 ms 83864 KB Output is correct
70 Correct 1119 ms 83360 KB Output is correct
71 Correct 1081 ms 83252 KB Output is correct
72 Correct 1111 ms 83352 KB Output is correct
73 Correct 791 ms 75804 KB Output is correct
74 Correct 806 ms 75896 KB Output is correct
75 Correct 778 ms 75868 KB Output is correct
76 Correct 829 ms 75828 KB Output is correct
77 Correct 805 ms 75672 KB Output is correct
78 Correct 974 ms 87432 KB Output is correct
79 Correct 757 ms 76000 KB Output is correct
80 Correct 1000 ms 82376 KB Output is correct