답안 #684483

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684483 2023-01-21T10:45:51 Z Chal1shkan Red-blue table (IZhO19_stones) C++14
0 / 100
33 ms 48052 KB
# include <bits/stdc++.h>

# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll maxn = 1e6 + 25;
const ll inf = 1e18 + 0;
const ll mod = 1e9 + 7;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};

using namespace std;

struct query
{
	ll L, K, ID;
	query (ll x, ll y, ll z)
	{
		L = x;
		K = y;
		ID = x;
	}
};

vector <query> q[maxn];

ll n, m, a[maxn];
ll t[maxn * 4];
ll ans[maxn];

void update (ll pos, ll x, ll v = 1, ll tl = 1, ll tr = n)
{
	if (tl == tr)
	{
		t[v] = max(t[v], x);
		return;
	}
	ll tm = (tl + tr) >> 1;
	if (pos <= tm) update(pos, x, v * 2, tl, tm);
	else update(pos, x, v * 2 + 1, tm + 1, tr);
	t[v] = max(t[v * 2], t[v * 2 + 1]);
}

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

void ma1n (/* SABR */)
{
	cin >> n >> m;
	for (ll i = 1; i <= n; ++i)
	{
		cin >> a[i];
	}
	for (ll i = 1; i <= m; ++i)
	{
		ll l, r, k;
		cin >> l >> r >> k;
		q[r].pb({l, k, i});
	}
	vector <ll> v;
	for (ll r = 1; r <= n; ++r)
	{
		while (!v.empty() && a[v.back()] <= a[r]) v.pop_back();
		if (!v.empty())
		{
			update(v.back(), a[r] + a[v.back()]); 
		}
		for (query i : q[r])
		{
			ll l = i.L, k = i.K, id = i.ID;
			if (get(l, r) <= k)
			{ 
				ans[id] = 1;
			}
		}
		v.pb(r);
	}
	for (ll i = 1; i <= m; ++i) cout << ans[i] << nl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//  freopen("file.in", "r", stdin);
//  freopen("file.out", "w", stdout);
    int ttt = 1;
//  cin >> ttt;
    for (int test = 1; test <= ttt; ++test)
    {
//      cout << "Case " << test << ":" << ' ';
        ma1n();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 48052 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 23788 KB Wrong answer
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 48052 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 23764 KB Wrong answer
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 23764 KB Wrong answer
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 33 ms 48052 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -