Submission #245498

# Submission time Handle Problem Language Result Execution time Memory
245498 2020-07-06T14:27:19 Z Yera Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1081 ms 102204 KB
// In The Name Of God
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <bitset>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define sagyndym_seni ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

const ll N = 1e6+5, p1 = 911382323, p2 = 972663749, INF = 1e9+123;

inline int read(){
	char c = getchar_unlocked();
	bool minus = 0;
	while (c < '0' || '9' < c){
		if(c == '-'){ minus = 1;}
		c = getchar_unlocked();
		if(c == '-'){ minus = 1;}
	}
	int res = 0;
	while ('0' <= c && c <= '9') {
		res = (res << 3) + (res << 1) + c - '0';
		c = getchar_unlocked();
	}
	if(minus){ res *= -1;}
	return res;
}

inline void print(bool flag){
	flag ? putchar_unlocked('1') : putchar_unlocked('0');
	putchar_unlocked('\n');
}

int n, m;
bool ans[N];
vector<int> a;
vector<pair<int, pair<int, int>>> q[N];

int tMax[N << 2], tInv[N << 2];

void build(int v, int vl, int vr){
	if(vl == vr){ tMax[v] = a[vl]; return;}
	int vm = (vl + vr) >> 1;
	build(v*2+1, vl, vm);
	build(v*2+2, vm+1, vr);
	tMax[v] = max(tMax[v*2+1], tMax[v*2+2]);
}

void maximize(int v, int vl, int vr, int l, int r, int val){
	if(vl > r || vr < l){ return;}
	if(l <= vl && vr <= r){
		tInv[v] = max(tInv[v], val);
		return;
	}
	int vm = (vl + vr) >> 1;
	maximize(v*2+1, vl, vm, l, r, val);
	maximize(v*2+2, vm+1, vr, l, r, val);
}

int down(int v, int vl, int vr, int i){
	if(tMax[v] <= a[i] || i <= vl){ return -1;}
	if(vl == vr){ return tMax[v] > a[i] ? vl : -1;}
	int vm = (vl + vr) >> 1;
	int q1 = down(v*2+2, vm+1, vr, i);
	if(q1 != -1){
		return q1;
	}
	return down(v*2+1, vl, vm, i);
}

int query(int v, int vl, int vr, int l){
	if(vl == vr){ return tInv[v];}
	int vm = (vl + vr) >> 1;
	if(l <= vm){
		return max(tInv[v], query(v*2+1, vl, vm, l));
	}else{
		return max(tInv[v], query(v*2+2, vm+1, vr, l));
	}
}

int main(){
	n = read(); m = read();
	a.resize(n);
	for(int i = 0; i < n; i++){
		a[i] = read();
	}
	for(int i = 0; i < m; i++){
		int l = read()-1, r = read()-1, k = read();
		q[r].pb({l, {i, k}});
	}
	build(0, 0, n-1);
	for(int i = 0; i < n; i++){
		int res = down(0, 0, n-1, i);
		if(res != -1){
			maximize(0, 0, n-1, 0, res, a[res] + a[i]);
		}
		for(auto j : q[i]){
			ans[j.s.f] = (query(0, 0, n-1, j.f) <= j.s.s);
		}
	}
	for(int i = 0; i < m; i++){
		print(ans[i]);
	}
	return 0;
}
/* TIMUS: 292220YC*/


# Verdict Execution time Memory Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 19 ms 23808 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 18 ms 23808 KB Output is correct
5 Correct 19 ms 23808 KB Output is correct
6 Correct 19 ms 23808 KB Output is correct
7 Correct 18 ms 23808 KB Output is correct
8 Correct 19 ms 23808 KB Output is correct
9 Correct 21 ms 23808 KB Output is correct
10 Correct 21 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 19 ms 23808 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 18 ms 23808 KB Output is correct
5 Correct 19 ms 23808 KB Output is correct
6 Correct 19 ms 23808 KB Output is correct
7 Correct 18 ms 23808 KB Output is correct
8 Correct 19 ms 23808 KB Output is correct
9 Correct 21 ms 23808 KB Output is correct
10 Correct 21 ms 23808 KB Output is correct
11 Correct 22 ms 24064 KB Output is correct
12 Correct 21 ms 24192 KB Output is correct
13 Correct 20 ms 24192 KB Output is correct
14 Correct 21 ms 24192 KB Output is correct
15 Correct 22 ms 24192 KB Output is correct
16 Correct 20 ms 24192 KB Output is correct
17 Correct 20 ms 24064 KB Output is correct
18 Correct 24 ms 24192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1038 ms 70012 KB Output is correct
2 Correct 1056 ms 68996 KB Output is correct
3 Correct 1080 ms 101752 KB Output is correct
4 Correct 1081 ms 101940 KB Output is correct
5 Correct 763 ms 93560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 29432 KB Output is correct
2 Correct 65 ms 30456 KB Output is correct
3 Correct 54 ms 29560 KB Output is correct
4 Correct 54 ms 29692 KB Output is correct
5 Correct 63 ms 29688 KB Output is correct
6 Correct 43 ms 29048 KB Output is correct
7 Correct 47 ms 29048 KB Output is correct
8 Correct 60 ms 29232 KB Output is correct
9 Correct 30 ms 26928 KB Output is correct
10 Correct 55 ms 29232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 19 ms 23808 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 18 ms 23808 KB Output is correct
5 Correct 19 ms 23808 KB Output is correct
6 Correct 19 ms 23808 KB Output is correct
7 Correct 18 ms 23808 KB Output is correct
8 Correct 19 ms 23808 KB Output is correct
9 Correct 21 ms 23808 KB Output is correct
10 Correct 21 ms 23808 KB Output is correct
11 Correct 22 ms 24064 KB Output is correct
12 Correct 21 ms 24192 KB Output is correct
13 Correct 20 ms 24192 KB Output is correct
14 Correct 21 ms 24192 KB Output is correct
15 Correct 22 ms 24192 KB Output is correct
16 Correct 20 ms 24192 KB Output is correct
17 Correct 20 ms 24064 KB Output is correct
18 Correct 24 ms 24192 KB Output is correct
19 Correct 156 ms 40184 KB Output is correct
20 Correct 149 ms 39544 KB Output is correct
21 Correct 121 ms 39160 KB Output is correct
22 Correct 122 ms 39160 KB Output is correct
23 Correct 126 ms 39164 KB Output is correct
24 Correct 94 ms 36984 KB Output is correct
25 Correct 95 ms 36984 KB Output is correct
26 Correct 107 ms 37240 KB Output is correct
27 Correct 108 ms 37288 KB Output is correct
28 Correct 117 ms 37416 KB Output is correct
29 Correct 128 ms 37624 KB Output is correct
30 Correct 155 ms 37624 KB Output is correct
31 Correct 145 ms 37624 KB Output is correct
32 Correct 119 ms 37624 KB Output is correct
33 Correct 130 ms 37752 KB Output is correct
34 Correct 84 ms 36856 KB Output is correct
35 Correct 85 ms 36796 KB Output is correct
36 Correct 87 ms 36588 KB Output is correct
37 Correct 81 ms 36600 KB Output is correct
38 Correct 84 ms 36756 KB Output is correct
39 Correct 116 ms 37016 KB Output is correct
40 Correct 86 ms 33940 KB Output is correct
41 Correct 106 ms 35912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23808 KB Output is correct
2 Correct 19 ms 23808 KB Output is correct
3 Correct 19 ms 23808 KB Output is correct
4 Correct 18 ms 23808 KB Output is correct
5 Correct 19 ms 23808 KB Output is correct
6 Correct 19 ms 23808 KB Output is correct
7 Correct 18 ms 23808 KB Output is correct
8 Correct 19 ms 23808 KB Output is correct
9 Correct 21 ms 23808 KB Output is correct
10 Correct 21 ms 23808 KB Output is correct
11 Correct 22 ms 24064 KB Output is correct
12 Correct 21 ms 24192 KB Output is correct
13 Correct 20 ms 24192 KB Output is correct
14 Correct 21 ms 24192 KB Output is correct
15 Correct 22 ms 24192 KB Output is correct
16 Correct 20 ms 24192 KB Output is correct
17 Correct 20 ms 24064 KB Output is correct
18 Correct 24 ms 24192 KB Output is correct
19 Correct 1038 ms 70012 KB Output is correct
20 Correct 1056 ms 68996 KB Output is correct
21 Correct 1080 ms 101752 KB Output is correct
22 Correct 1081 ms 101940 KB Output is correct
23 Correct 763 ms 93560 KB Output is correct
24 Correct 75 ms 29432 KB Output is correct
25 Correct 65 ms 30456 KB Output is correct
26 Correct 54 ms 29560 KB Output is correct
27 Correct 54 ms 29692 KB Output is correct
28 Correct 63 ms 29688 KB Output is correct
29 Correct 43 ms 29048 KB Output is correct
30 Correct 47 ms 29048 KB Output is correct
31 Correct 60 ms 29232 KB Output is correct
32 Correct 30 ms 26928 KB Output is correct
33 Correct 55 ms 29232 KB Output is correct
34 Correct 156 ms 40184 KB Output is correct
35 Correct 149 ms 39544 KB Output is correct
36 Correct 121 ms 39160 KB Output is correct
37 Correct 122 ms 39160 KB Output is correct
38 Correct 126 ms 39164 KB Output is correct
39 Correct 94 ms 36984 KB Output is correct
40 Correct 95 ms 36984 KB Output is correct
41 Correct 107 ms 37240 KB Output is correct
42 Correct 108 ms 37288 KB Output is correct
43 Correct 117 ms 37416 KB Output is correct
44 Correct 128 ms 37624 KB Output is correct
45 Correct 155 ms 37624 KB Output is correct
46 Correct 145 ms 37624 KB Output is correct
47 Correct 119 ms 37624 KB Output is correct
48 Correct 130 ms 37752 KB Output is correct
49 Correct 84 ms 36856 KB Output is correct
50 Correct 85 ms 36796 KB Output is correct
51 Correct 87 ms 36588 KB Output is correct
52 Correct 81 ms 36600 KB Output is correct
53 Correct 84 ms 36756 KB Output is correct
54 Correct 116 ms 37016 KB Output is correct
55 Correct 86 ms 33940 KB Output is correct
56 Correct 106 ms 35912 KB Output is correct
57 Correct 1012 ms 102204 KB Output is correct
58 Correct 954 ms 102124 KB Output is correct
59 Correct 827 ms 100596 KB Output is correct
60 Correct 846 ms 100468 KB Output is correct
61 Correct 938 ms 100464 KB Output is correct
62 Correct 839 ms 100432 KB Output is correct
63 Correct 395 ms 88416 KB Output is correct
64 Correct 408 ms 88312 KB Output is correct
65 Correct 675 ms 92136 KB Output is correct
66 Correct 671 ms 92112 KB Output is correct
67 Correct 670 ms 92116 KB Output is correct
68 Correct 738 ms 93732 KB Output is correct
69 Correct 735 ms 93892 KB Output is correct
70 Correct 775 ms 93548 KB Output is correct
71 Correct 737 ms 93328 KB Output is correct
72 Correct 735 ms 93340 KB Output is correct
73 Correct 347 ms 84500 KB Output is correct
74 Correct 406 ms 85648 KB Output is correct
75 Correct 448 ms 84660 KB Output is correct
76 Correct 370 ms 84512 KB Output is correct
77 Correct 375 ms 84600 KB Output is correct
78 Correct 650 ms 88392 KB Output is correct
79 Correct 498 ms 72788 KB Output is correct
80 Correct 660 ms 82908 KB Output is correct