Submission #1115639

# Submission time Handle Problem Language Result Execution time Memory
1115639 2024-11-20T17:34:36 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
17 / 100
543 ms 33612 KB
#include <bits/stdc++.h>
#define ll long long 
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(v) (v).begin(),(v).end()
#define int long long

using namespace std;

const int maxn = 1e6 + 5;

const int mod = 1e9 + 7;

int n,a[maxn],m,b[maxn],c[maxn],d[maxn],e[maxn],t[maxn * 4];

void build(int v = 1, int tl = 1, int tr = n){
	if(tl == tr){
		t[v] = a[tl];
		return; 
	}
	
	int tm = (tl + tr) >> 1;
	
	build(v + v, tl, tm);
	build(v + v + 1, tm + 1, tr);
	
	t[v] = min(t[v + v], t[v + v + 1]);
}

int get(int l, int r, int v = 1, int tl = 1, int tr = n){
	if(tl > r || l > tr) return 1000000000;
	
	if(l <= tl && tr <= r) {
		return t[v];
	}
	
	int tm = (tl + tr) >> 1;
	
	return min(get(l,r,v+v,tl,tm), get(l,r,v+v+1,tm+1,tr));
}

void webbly_abi_spasibo(){
		
	cin >> n >> m;
	
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	
	bool ok1 = 1;
	
	for(int i = 1; i <= m; i++){
		cin >> b[i] >> c[i] >> d[i];
		if(d[i] >= get(b[i],c[i])) ok1 = 0;
	}
	
	if(n <= 5000 && m <= 5000){
		for(int i = 1; i <= m; i++){
			int l = b[i], r = c[i], val = d[i];
			
			int mx = a[l];
			
			bool ok = 1;
			
			for(int j = l + 1; j <= r; j++){
				if(mx > a[j]){
					if(mx + a[j] > val) {
						ok = 0;
						break;
					}
				}
				mx = max(mx, a[j]);
			}
			
			cout << ok << '\n';
			
		}
	}
	else if(ok1){
		for(int i = 2; i <= n; i++){
			if(a[i] < a[i - 1]){
				e[i] = 1;
			}
			e[i] += e[i-1];
		}
		
		for(int i = 1; i <= m; i++){
			int l = b[i], r = c[i], val = d[i];
			if(e[r] - e[l]){
				cout << "0\n";
			}
			else {
				cout << "1\n";
			}
		}
	}
		
}

signed main(){
//	
//	freopen("greedy.in", "r", stdin);
//	freopen("greedy.out", "w", stdout);
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
		
	int tt = 1;
	
	//cin >> tt;
	
	while(tt--){
		webbly_abi_spasibo();
	}
	
	return 0;
}

Compilation message

sortbooks.cpp: In function 'void webbly_abi_spasibo()':
sortbooks.cpp:90:28: warning: unused variable 'val' [-Wunused-variable]
   90 |    int l = b[i], r = c[i], val = d[i];
      |                            ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8528 KB Output is correct
2 Correct 2 ms 8528 KB Output is correct
3 Correct 2 ms 8528 KB Output is correct
4 Correct 2 ms 8528 KB Output is correct
5 Correct 2 ms 8528 KB Output is correct
6 Correct 2 ms 8528 KB Output is correct
7 Correct 2 ms 8528 KB Output is correct
8 Correct 2 ms 8528 KB Output is correct
9 Correct 2 ms 8528 KB Output is correct
10 Correct 2 ms 8528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8528 KB Output is correct
2 Correct 2 ms 8528 KB Output is correct
3 Correct 2 ms 8528 KB Output is correct
4 Correct 2 ms 8528 KB Output is correct
5 Correct 2 ms 8528 KB Output is correct
6 Correct 2 ms 8528 KB Output is correct
7 Correct 2 ms 8528 KB Output is correct
8 Correct 2 ms 8528 KB Output is correct
9 Correct 2 ms 8528 KB Output is correct
10 Correct 2 ms 8528 KB Output is correct
11 Correct 3 ms 8696 KB Output is correct
12 Correct 3 ms 8676 KB Output is correct
13 Correct 3 ms 8528 KB Output is correct
14 Correct 6 ms 10748 KB Output is correct
15 Correct 4 ms 10576 KB Output is correct
16 Correct 10 ms 10740 KB Output is correct
17 Correct 10 ms 10576 KB Output is correct
18 Correct 17 ms 10832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 543 ms 33612 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 50 ms 12520 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8528 KB Output is correct
2 Correct 2 ms 8528 KB Output is correct
3 Correct 2 ms 8528 KB Output is correct
4 Correct 2 ms 8528 KB Output is correct
5 Correct 2 ms 8528 KB Output is correct
6 Correct 2 ms 8528 KB Output is correct
7 Correct 2 ms 8528 KB Output is correct
8 Correct 2 ms 8528 KB Output is correct
9 Correct 2 ms 8528 KB Output is correct
10 Correct 2 ms 8528 KB Output is correct
11 Correct 3 ms 8696 KB Output is correct
12 Correct 3 ms 8676 KB Output is correct
13 Correct 3 ms 8528 KB Output is correct
14 Correct 6 ms 10748 KB Output is correct
15 Correct 4 ms 10576 KB Output is correct
16 Correct 10 ms 10740 KB Output is correct
17 Correct 10 ms 10576 KB Output is correct
18 Correct 17 ms 10832 KB Output is correct
19 Incorrect 110 ms 16620 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8528 KB Output is correct
2 Correct 2 ms 8528 KB Output is correct
3 Correct 2 ms 8528 KB Output is correct
4 Correct 2 ms 8528 KB Output is correct
5 Correct 2 ms 8528 KB Output is correct
6 Correct 2 ms 8528 KB Output is correct
7 Correct 2 ms 8528 KB Output is correct
8 Correct 2 ms 8528 KB Output is correct
9 Correct 2 ms 8528 KB Output is correct
10 Correct 2 ms 8528 KB Output is correct
11 Correct 3 ms 8696 KB Output is correct
12 Correct 3 ms 8676 KB Output is correct
13 Correct 3 ms 8528 KB Output is correct
14 Correct 6 ms 10748 KB Output is correct
15 Correct 4 ms 10576 KB Output is correct
16 Correct 10 ms 10740 KB Output is correct
17 Correct 10 ms 10576 KB Output is correct
18 Correct 17 ms 10832 KB Output is correct
19 Incorrect 543 ms 33612 KB Output isn't correct
20 Halted 0 ms 0 KB -