답안 #832409

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832409 2023-08-21T10:07:38 Z ymm 송신탑 (IOI22_towers) C++17
28 / 100
805 ms 49448 KB
#include "towers.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= l; --x)
typedef long long ll;
using namespace std;

const int inf = 1e9+10;
const int N = 100'010;

template<class T, class CMP>
struct rmq {
	static int constexpr lg = 18;
	CMP cmp;
	typedef pair<T,int> el;
	vector<el> vec[lg];
	int sz;

	el mn(const el &x, const el &y) { return cmp(x.first, y.first)? x: y; }

	void init(const vector<T> &a) {
		sz = a.size();
		vec[0].resize(sz);
		Loop (i,0,sz)
			vec[0][i] = {a[i], i};
		Loop (j,0,lg-1) {
			if ((2<<j) > sz)
				break;
			vec[j+1].resize(sz-(2<<j)+1);
			for (int i = 0; i + (2<<j) <= sz; ++i)
				vec[j+1][i] = mn(vec[j][i], vec[j][i+(1<<j)]);
		}
	}
	el get(int l, int r) {
		int k = __lg(r-l);
		return mn(vec[k][l], vec[k][r-(1<<k)]);
	}
};
rmq<int, less<int>> rmq_mn;
rmq<int, greater<int>> rmq_mx;

namespace seg {
	vector<int> t[4*N];
	int sz;

	void init(const vector<int> &vec, int i, int b, int e) {
		if (e-b == 1) {
			t[i] = {vec[b]};
			return;
		}
		init(vec, 2*i+1, b, (b+e)/2);
		init(vec, 2*i+2, (b+e)/2, e);
		t[i].resize(t[2*i+1].size() + t[2*i+2].size());
		merge(t[2*i+1].begin(), t[2*i+1].end(),
		      t[2*i+2].begin(), t[2*i+2].end(),
		      t[i].begin());
	}
	void init(const vector<int> &vec) { sz = vec.size(); init(vec, 0, 0, sz); }

	int get(int l, int r, int d, int i, int b, int e) {
		if (l <= b && e <= r)
			return t[i].end() - lower_bound(t[i].begin(), t[i].end(), d);
		if (r <= b || e <= l)
			return 0;
		return   get(l, r, d, 2*i+1, b, (b+e)/2)
		       + get(l, r, d, 2*i+2, (b+e)/2, e);
	}
	int get(int l, int r, int d) { return get(l, r, d, 0, 0, sz); }

	int lrmost(int l, int r, int d, bool dir, int i, int b, int e) {
		if (r <= b || e <= l || t[i].back() < d)
			return -1;
		if (e-b == 1)
			return b;
		int ans = -1;
		ans = lrmost(l, r, d, dir, 2*i+1+ dir, dir? (b+e)/2: b, dir? e: (b+e)/2);
		if (ans != -1)
			return ans;
		ans = lrmost(l, r, d, dir, 2*i+1+!dir, dir? b: (b+e)/2, dir? (b+e)/2: e);
		return ans;
	}
	int leftmost(int l, int r, int d) { return lrmost(l, r, d, 0, 0, 0, sz); }
	int rightmost(int l, int r, int d) { return lrmost(l, r, d, 1, 0, 0, sz); }
}

int height[N];
int lsml[N], rsml[N];
int lval[N], rval[N], val[N];
int n;

void init_sml()
{
	vector<int> vec;
	Loop (i,0,n) {
		while (vec.size() && height[vec.back()] > height[i])
			vec.pop_back();
		lsml[i] = vec.size()? vec.back(): -1;
		vec.push_back(i);
	}
	vec.clear();
	LoopR (i,0,n) {
		while (vec.size() && height[vec.back()] > height[i])
			vec.pop_back();
		rsml[i] = vec.size()? vec.back(): n;
		vec.push_back(i);
	}
}

void init_val()
{
	Loop (i,0,n) {
		lval[i] = lsml[i] == -1? inf: lsml[i] == i-1? 0: rmq_mx.get(lsml[i]+1, i+1).first - height[i];
		rval[i] = rsml[i] ==  n? inf: rsml[i] == i+1? 0: rmq_mx.get(i, rsml[i]).first - height[i];
		val[i] = min(lval[i], rval[i]);
	}
	seg::init(vector<int>(val, val+n));
}

bool darre(int l, int r, int d, int i)
{
	int val = min(lsml[i] < l? inf: lval[i], rsml[i] >= r? inf: rval[i]);
	return val >= d;
}

void init(int N, std::vector<int> H)
{
	n = N;
	Loop (i,0,n)
		height[i] = H[i];
	rmq_mx.init(H);
	rmq_mn.init(H);
	init_sml();
	init_val();
}

int max_towers(int L, int R, int D)
{
	++R;
	int ans = seg::get(L, R, D);
	if (ans == 0) {
		ans = 1;
		int p = rmq_mx.get(L, R).second;
		if (p != L && p != R-1) {
			int pl = rmq_mn.get(L, p).second;
			int pr = rmq_mn.get(p+1, R).second;
			if (darre(L, R, D, pl) && darre(L, R, D, pr))
				ans = 2;
		}
		return ans;
	}
	int pl = seg::leftmost(L, R, D);
	int pr = seg::rightmost(L, R, D);
	if (pl != L) {
		int pll = rmq_mn.get(L, pl).second;
		ans += darre(L, R, D, pll);
	}
	if (pr != R-1) {
		int prr = rmq_mn.get(pr+1, R).second;
		ans += darre(L, R, D, prr);
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 326 ms 32424 KB 28917th lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9808 KB Output is correct
2 Correct 5 ms 10192 KB Output is correct
3 Correct 6 ms 10192 KB Output is correct
4 Correct 5 ms 10192 KB Output is correct
5 Correct 6 ms 10192 KB Output is correct
6 Correct 5 ms 10192 KB Output is correct
7 Correct 5 ms 10272 KB Output is correct
8 Correct 5 ms 10192 KB Output is correct
9 Correct 5 ms 10192 KB Output is correct
10 Correct 5 ms 10192 KB Output is correct
11 Correct 7 ms 10192 KB Output is correct
12 Correct 4 ms 9680 KB Output is correct
13 Correct 5 ms 10180 KB Output is correct
14 Correct 6 ms 10212 KB Output is correct
15 Correct 5 ms 10192 KB Output is correct
16 Correct 7 ms 10192 KB Output is correct
17 Correct 6 ms 10192 KB Output is correct
18 Correct 6 ms 10192 KB Output is correct
19 Correct 6 ms 10192 KB Output is correct
20 Correct 6 ms 10192 KB Output is correct
21 Correct 6 ms 10192 KB Output is correct
22 Correct 6 ms 10260 KB Output is correct
23 Correct 5 ms 10192 KB Output is correct
24 Correct 5 ms 10192 KB Output is correct
25 Correct 4 ms 9936 KB Output is correct
26 Correct 5 ms 10192 KB Output is correct
27 Correct 5 ms 10196 KB Output is correct
28 Correct 5 ms 10192 KB Output is correct
29 Correct 5 ms 10192 KB Output is correct
30 Correct 5 ms 10192 KB Output is correct
31 Correct 5 ms 10192 KB Output is correct
32 Correct 5 ms 10192 KB Output is correct
33 Correct 5 ms 10196 KB Output is correct
34 Correct 6 ms 10276 KB Output is correct
35 Correct 5 ms 10192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9808 KB Output is correct
2 Correct 5 ms 10192 KB Output is correct
3 Correct 6 ms 10192 KB Output is correct
4 Correct 5 ms 10192 KB Output is correct
5 Correct 6 ms 10192 KB Output is correct
6 Correct 5 ms 10192 KB Output is correct
7 Correct 5 ms 10272 KB Output is correct
8 Correct 5 ms 10192 KB Output is correct
9 Correct 5 ms 10192 KB Output is correct
10 Correct 5 ms 10192 KB Output is correct
11 Correct 7 ms 10192 KB Output is correct
12 Correct 4 ms 9680 KB Output is correct
13 Correct 5 ms 10180 KB Output is correct
14 Correct 6 ms 10212 KB Output is correct
15 Correct 5 ms 10192 KB Output is correct
16 Correct 7 ms 10192 KB Output is correct
17 Correct 6 ms 10192 KB Output is correct
18 Correct 6 ms 10192 KB Output is correct
19 Correct 6 ms 10192 KB Output is correct
20 Correct 6 ms 10192 KB Output is correct
21 Correct 6 ms 10192 KB Output is correct
22 Correct 6 ms 10260 KB Output is correct
23 Correct 5 ms 10192 KB Output is correct
24 Correct 5 ms 10192 KB Output is correct
25 Correct 4 ms 9936 KB Output is correct
26 Correct 5 ms 10192 KB Output is correct
27 Correct 5 ms 10196 KB Output is correct
28 Correct 5 ms 10192 KB Output is correct
29 Correct 5 ms 10192 KB Output is correct
30 Correct 5 ms 10192 KB Output is correct
31 Correct 5 ms 10192 KB Output is correct
32 Correct 5 ms 10192 KB Output is correct
33 Correct 5 ms 10196 KB Output is correct
34 Correct 6 ms 10276 KB Output is correct
35 Correct 5 ms 10192 KB Output is correct
36 Correct 40 ms 34676 KB Output is correct
37 Incorrect 50 ms 49268 KB 1st lines differ - on the 1st token, expected: '2946', found: '2945'
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 670 ms 48868 KB 29th lines differ - on the 1st token, expected: '9839', found: '9838'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 194 ms 18256 KB Output is correct
2 Correct 618 ms 49224 KB Output is correct
3 Correct 688 ms 49244 KB Output is correct
4 Correct 657 ms 49332 KB Output is correct
5 Correct 794 ms 49352 KB Output is correct
6 Correct 675 ms 49240 KB Output is correct
7 Correct 707 ms 49224 KB Output is correct
8 Correct 688 ms 49228 KB Output is correct
9 Correct 788 ms 49228 KB Output is correct
10 Correct 710 ms 49236 KB Output is correct
11 Correct 805 ms 49276 KB Output is correct
12 Correct 51 ms 49268 KB Output is correct
13 Correct 49 ms 49252 KB Output is correct
14 Correct 50 ms 49232 KB Output is correct
15 Correct 51 ms 49448 KB Output is correct
16 Correct 44 ms 49260 KB Output is correct
17 Correct 49 ms 47836 KB Output is correct
18 Correct 52 ms 49248 KB Output is correct
19 Correct 52 ms 49260 KB Output is correct
20 Correct 58 ms 49240 KB Output is correct
21 Correct 50 ms 49244 KB Output is correct
22 Correct 50 ms 49304 KB Output is correct
23 Correct 62 ms 49236 KB Output is correct
24 Correct 43 ms 49348 KB Output is correct
25 Correct 46 ms 49352 KB Output is correct
26 Correct 62 ms 49244 KB Output is correct
27 Correct 45 ms 49276 KB Output is correct
28 Correct 5 ms 10176 KB Output is correct
29 Correct 5 ms 10192 KB Output is correct
30 Correct 5 ms 10192 KB Output is correct
31 Correct 5 ms 10320 KB Output is correct
32 Correct 5 ms 10192 KB Output is correct
33 Correct 5 ms 9936 KB Output is correct
34 Correct 5 ms 10192 KB Output is correct
35 Correct 5 ms 10192 KB Output is correct
36 Correct 5 ms 10192 KB Output is correct
37 Correct 5 ms 10192 KB Output is correct
38 Correct 5 ms 10192 KB Output is correct
39 Correct 6 ms 10192 KB Output is correct
40 Correct 5 ms 10192 KB Output is correct
41 Correct 5 ms 10264 KB Output is correct
42 Correct 5 ms 10192 KB Output is correct
43 Correct 5 ms 10192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9808 KB Output is correct
2 Correct 5 ms 10192 KB Output is correct
3 Correct 6 ms 10192 KB Output is correct
4 Correct 5 ms 10192 KB Output is correct
5 Correct 6 ms 10192 KB Output is correct
6 Correct 5 ms 10192 KB Output is correct
7 Correct 5 ms 10272 KB Output is correct
8 Correct 5 ms 10192 KB Output is correct
9 Correct 5 ms 10192 KB Output is correct
10 Correct 5 ms 10192 KB Output is correct
11 Correct 7 ms 10192 KB Output is correct
12 Correct 4 ms 9680 KB Output is correct
13 Correct 5 ms 10180 KB Output is correct
14 Correct 6 ms 10212 KB Output is correct
15 Correct 5 ms 10192 KB Output is correct
16 Correct 7 ms 10192 KB Output is correct
17 Correct 6 ms 10192 KB Output is correct
18 Correct 6 ms 10192 KB Output is correct
19 Correct 6 ms 10192 KB Output is correct
20 Correct 6 ms 10192 KB Output is correct
21 Correct 6 ms 10192 KB Output is correct
22 Correct 6 ms 10260 KB Output is correct
23 Correct 5 ms 10192 KB Output is correct
24 Correct 5 ms 10192 KB Output is correct
25 Correct 4 ms 9936 KB Output is correct
26 Correct 5 ms 10192 KB Output is correct
27 Correct 5 ms 10196 KB Output is correct
28 Correct 5 ms 10192 KB Output is correct
29 Correct 5 ms 10192 KB Output is correct
30 Correct 5 ms 10192 KB Output is correct
31 Correct 5 ms 10192 KB Output is correct
32 Correct 5 ms 10192 KB Output is correct
33 Correct 5 ms 10196 KB Output is correct
34 Correct 6 ms 10276 KB Output is correct
35 Correct 5 ms 10192 KB Output is correct
36 Correct 40 ms 34676 KB Output is correct
37 Incorrect 50 ms 49268 KB 1st lines differ - on the 1st token, expected: '2946', found: '2945'
38 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 326 ms 32424 KB 28917th lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -