QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#559183#8218. 水镜Lu_xZ0 1ms9792kbC++201.5kb2024-09-11 20:41:072024-09-11 20:41:12

Judging History

你现在查看的是最新测评结果

  • [2024-09-11 20:41:12]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:9792kb
  • [2024-09-11 20:41:07]
  • 提交

answer

#include<bits/stdc++.h>
#define eb emplace_back
#define ep emplace
using namespace std;

using ll = long long;
constexpr int N = 1.5e6 + 5;

int n, m; ll h[N], b[N], x[N], ans;

struct Node {
	int mi, tag;
	void addtag(int v) {mi = tag = v;}
} t[N << 2];
#define ls x << 1
#define rs ls | 1

void pushup(int x) {
	t[x].mi = min(t[ls].mi, t[rs].mi);
}
void pushdown(int x) {
	if(t[x].tag) {
		t[ls].addtag(t[x].tag), t[rs].addtag(t[x].tag);
		t[x].tag = 0;
	}
}
void assign(int L, int R, int v, int x = 1, int l = 1, int r = m) {
	if(L > R) return;
	if(L <= l && r <= R) return t[x].addtag(v);
	pushdown(x);
	int mid = l + r >> 1;
	if(L <= mid) assign(L, R, v, ls, l, mid);
	if(R > mid) assign(L, R, v, rs, mid + 1, r);
	pushup(x);
}
int F(ll val) {
	return lower_bound(b + 1, b + m + 1, val) - b;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for(int i = 1; i <= n; ++ i) {
		cin >> h[i], h[i] <<= 1;
	}
	for(int i = 1; i < n; ++ i) {
		b[++ m] = x[i] = (h[i] + h[i + 1]) / 2;
		b[++ m] = x[i] + 1;
		b[++ m] = x[i] - 1;
	}
	sort(b + 1, b + m + 1);
	m = unique(b + 1, b + m + 1) - b - 1;
	
	ans = n * ll(n - 1) / 2;
	for(int i = 2; i < n; ++ i) {
		int l, r, L, R;
		if(h[i] == h[i - 1]) l = 1, r = m;
		else {
			if(h[i] < h[i - 1]) l = F(x[i - 1]), r = m;
			else l = 1, r = F(x[i - 1]);
		}
		if(h[i] == h[i + 1]) L = 1, R = m;
		else {
			if(h[i] < h[i + 1]) L = F(x[i]), R = m;
			else L = 1, R = F(x[i]);
		}
		assign(max(l, L), min(r, R), i - 1);
		ans -= t[1].mi;
	}
	cout << ans;
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 7
Accepted
time: 0ms
memory: 9792kb

input:

2
2 1

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 7
Accepted
time: 1ms
memory: 9764kb

input:

10
2 2 2 2 1 4 5 3 3 2

output:

20

result:

ok 1 number(s): "20"

Test #3:

score: 7
Accepted
time: 1ms
memory: 9772kb

input:

10
2 2 1 2 2 2 1 4 1 4

output:

17

result:

ok 1 number(s): "17"

Test #4:

score: 0
Wrong Answer
time: 1ms
memory: 9736kb

input:

10
1 5 2 2 5 4 4 4 1 3

output:

18

result:

wrong answer 1st numbers differ - expected: '20', found: '18'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%