답안 #889888

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
889888 2023-12-20T09:10:07 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
150 ms 262144 KB
//#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
//#pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ordered_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define len(x) (int)x.size()
#define ull unsigned long long
#define F first
#define S second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define int long long
#define ld long double
#define pii pair<int,int>
#define mii map<int,int>

using namespace std;
using namespace __gnu_pbds;
using ll = long long;

const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const ll inf = 1e9;
int n,q,a[N],c[N],lg[N],sp[25][N],s[25][N];
pii t[N*4];

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

pii com(pii l, pii r){
	if (l.F > r.F) return l;
	else return r;
}

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

signed main(){
	// freopen("txt.in", "r", stdin);
	// freopen("txt.out", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	lg[2] = 1;
	for (int i=2;i<=n;i++){
		if (!lg[i]) lg[i] = lg[i-1];
		if (i*2<=n) lg[i*2] = lg[i] + 1;
	}
	cin >> n >> q;
	for (int i=1;i<=n;i++){
		cin >> a[i];
		s[0][i] = a[i];
	}
	for (int i=2;i<=n;i++){
		if (a[i-1]<=a[i]) {
			c[i-1] = 1;
			sp[0][i-1] = c[i-1];
		}
	}
	for (int i=1;i<=20;i++){
		for (int j=1;j+(1<<i)-1<=n;j++){
			sp[i][j] = min(sp[i-1][j], sp[i-1][j+(1<<(i-1))]);
			s[i][j] = min(s[i-1][j], s[i-1][j+(1<<(i-1))]);
		}
	}
	build();
	while(q--){
		int ll,rr,k;
		cin >> ll >> rr >> k;
		if (ll==rr){
			cout << 1 << '\n';
			continue;
		}
		int l = ll;
		int r = rr-1;
		while(l<=r){
			int md = (l + r) / 2;
			int x = lg[(rr-1)-md+1];
			int cur = min(sp[x][md], sp[x][(rr-1)-(1<<x)+1]);
			if (cur==1){
				r = md - 1;
			}
			else{
				l = md + 1;
			}
		}
		if (ll<l){
			pii res = get(ll, l-1);
			r = rr;
			while(l<=r){
				int md = (l + r) / 2;
				if (res.F < a[md]){
					r = md - 1;
				}
				else{
					l = md + 1;
				}
			}
			pii act = get(res.S+1, r);
			if (res.F + act.F <= k){
				cout << 1 << '\n';
			}
			else{
				cout << 0 << '\n';
			}
			// cout <<  res.F << ' ' << res.S << ' ' << act.F << ' ' << act.S << '\n';
		}
		else{
			cout << 1 << '\n';
		}
	}
}

//order_of_key(k): Number of items strictly smaller than k .
//find_by_order(k): K-th element in a set (counting from zero).

//sum of squares n*(n+1)*(2n+1)/6
//sum of cubes [n*(n+1)/2]^2
//sum of squares for odds n*(4*n*n-1)/3
//sum of cubes for odds n*n*(2*n*n-1)

//a/b%mod = a*(b^(m-2)%mod)
//(a>>x)&1 == 0
//a^b = (a+b)-2(a&b)

//srand(time(0))-always changing
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 18776 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Incorrect 7 ms 39260 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 18776 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Incorrect 7 ms 39260 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 150 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 133 ms 107356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 18776 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Incorrect 7 ms 39260 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 18776 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Incorrect 7 ms 39260 KB Output isn't correct
4 Halted 0 ms 0 KB -