답안 #889877

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
889877 2023-12-20T08:51:41 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
30 / 100
841 ms 144588 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define forik(x) ll i = 1; i <= x; i++

// (a mod 1e9) / (b mod 1e9) = a * (b^1e9)

using namespace std;

ll a, b, c, e, f, t[8000001], n, m, k, p[1000001], d[5001][5001];
vector <pair <ll, ll>> g;

void upd (ll idx, ll val, ll tl = 1, ll tr = n, ll v = 1){
	if (tl > idx || tr < idx){
		return;
	}
	if (tl == tr && tr == idx){
		t[v] = val;
		return;
	}
	ll tm = (tl + tr) / 2;
	upd (idx, val, tl, tm, v * 2);
	upd (idx, val, tm + 1, tr, v * 2 + 1);
	t[v] = t[v * 2 + 1] + t[v * 2];
}

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

signed main (){
	//freopen (".in", "r", stdin);
	//freopen (".out", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++){
		cin >> p[i];
	}
	if (n <= 5000 && m <= 5000){
		for (int i = 1; i <= n; i++){
			a = p[i];
			for (int y = i + 1; y <= n; y++){
				d[i][y] = d[i][y - 1];
				a = max (a, p[y]);
				if (a > p[y]){
					d[i][y] = max (d[i][y], a + p[y]);
				}
			}	
		}
		while (m--){
			cin >> a >> b >> c;
			e = 1;
			if (d[a][b] > c){
				e = 0;
			}
			cout << e << '\n';
		}	
	}
	else{
		a = p[1];
		for (int i = 1; i <= n; i++){
			if (a > p[i]){
				upd (i, 1);
			}
			a = p[i];
		}
		while (m--){
			cin >> a >> b >> c;
			if (a == b){
				cout << 1 << '\n';
				continue;
			}
			if (get (a + 1, b) > 0){
				cout << "0\n";
			}
			else{
				cout << "1\n";
			}
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 5468 KB Output is correct
6 Correct 2 ms 7516 KB Output is correct
7 Correct 2 ms 7516 KB Output is correct
8 Correct 2 ms 7516 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 2 ms 7516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 5468 KB Output is correct
6 Correct 2 ms 7516 KB Output is correct
7 Correct 2 ms 7516 KB Output is correct
8 Correct 2 ms 7516 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 2 ms 7516 KB Output is correct
11 Correct 12 ms 22876 KB Output is correct
12 Correct 54 ms 140008 KB Output is correct
13 Correct 56 ms 140120 KB Output is correct
14 Correct 58 ms 144296 KB Output is correct
15 Correct 56 ms 144504 KB Output is correct
16 Correct 50 ms 144464 KB Output is correct
17 Correct 37 ms 109868 KB Output is correct
18 Correct 55 ms 144588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 841 ms 29132 KB Output is correct
2 Correct 828 ms 29340 KB Output is correct
3 Correct 788 ms 28920 KB Output is correct
4 Correct 757 ms 29008 KB Output is correct
5 Correct 636 ms 12736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 56 ms 6740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 5468 KB Output is correct
6 Correct 2 ms 7516 KB Output is correct
7 Correct 2 ms 7516 KB Output is correct
8 Correct 2 ms 7516 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 2 ms 7516 KB Output is correct
11 Correct 12 ms 22876 KB Output is correct
12 Correct 54 ms 140008 KB Output is correct
13 Correct 56 ms 140120 KB Output is correct
14 Correct 58 ms 144296 KB Output is correct
15 Correct 56 ms 144504 KB Output is correct
16 Correct 50 ms 144464 KB Output is correct
17 Correct 37 ms 109868 KB Output is correct
18 Correct 55 ms 144588 KB Output is correct
19 Incorrect 138 ms 10852 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 1 ms 5468 KB Output is correct
6 Correct 2 ms 7516 KB Output is correct
7 Correct 2 ms 7516 KB Output is correct
8 Correct 2 ms 7516 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 2 ms 7516 KB Output is correct
11 Correct 12 ms 22876 KB Output is correct
12 Correct 54 ms 140008 KB Output is correct
13 Correct 56 ms 140120 KB Output is correct
14 Correct 58 ms 144296 KB Output is correct
15 Correct 56 ms 144504 KB Output is correct
16 Correct 50 ms 144464 KB Output is correct
17 Correct 37 ms 109868 KB Output is correct
18 Correct 55 ms 144588 KB Output is correct
19 Correct 841 ms 29132 KB Output is correct
20 Correct 828 ms 29340 KB Output is correct
21 Correct 788 ms 28920 KB Output is correct
22 Correct 757 ms 29008 KB Output is correct
23 Correct 636 ms 12736 KB Output is correct
24 Incorrect 56 ms 6740 KB Output isn't correct
25 Halted 0 ms 0 KB -