QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#572697#8218. 水镜guosoun0 2ms9796kbC++172.2kb2024-09-18 15:59:362024-09-18 15:59:39

Judging History

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

  • [2024-09-18 15:59:39]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:9796kb
  • [2024-09-18 15:59:36]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
template <class T>
void chkmax(T &x, const T &y) {
  if (x < y) x = y;
}
template <class T>
void chkmin(T &x, const T &y) {
  if (x > y) x = y;
}
using ll = long long;
const int N = 5e5 + 10;

int n;
ll h[N];
std::pair<ll, ll> s[N];

int tg[N * 2], tr[N * 2], ls[N * 2], rs[N * 2], ntot = 1, rt = 1;
void get_down(int &i, int t) {
  if (!i) i = ++ntot;
  tr[i] += t, tg[i] += t;
}
void push_down(int i) {
  if (tg[i]) get_down(ls[i], tg[i]), get_down(rs[i], tg[i]), tg[i] = 0;
}
void add(int &i, ll l, ll r, ll ql, ll qr, int v) {
  if (ql > qr) return;
  if (!i) i = ++ntot;
  if (ql <= l && r <= qr) return get_down(i, v);
  ll mid = (l + r) >> 1;
  push_down(i);
  if (ql <= mid) add(ls[i], l, mid, ql, qr, v);
  if (qr > mid) add(rs[i], mid + 1, r, ql, qr, v);
  tr[i] = std::min(tr[ls[i]], tr[rs[i]]);
}

int main() {
  std::cin.tie(0)->sync_with_stdio(0);
  std::cin >> n;
  for (int i = 1; i <= n; i++) std::cin >> h[i], h[i] *= 2;
  for (int i = 2; i < n; i++) {
    ll v1 = (h[i - 1] + h[i]) / 2;
    s[i] = {-2e12, 2e12};
    if (h[i] < h[i - 1]) chkmax(s[i].first, v1);
    if (h[i] > h[i - 1]) chkmin(s[i].second, v1 - 1);
    ll v2 = (h[i] + h[i + 1]) / 2;
    if (h[i] < h[i + 1]) chkmax(s[i].first, v2);
    if (h[i] > h[i + 1]) chkmin(s[i].second, v2 - 1);
  }
  std::vector<ll> v;
  for (int i = 2; i < n; i++) v.push_back(s[i].first), v.push_back(s[i].second);
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
  for (int i = 2; i < n; i++) {
    s[i].first = std::lower_bound(v.begin(), v.end(), s[i].first) - v.begin();
    s[i].second = std::lower_bound(v.begin(), v.end(), s[i].second) - v.begin();
  }
  int m = v.size() - 1;
  ll ans = n - 1;
  for (int i = 2, j = 1; i < n; ) {
    if (j < i - 1) j = i - 1;
    for (;;) {
      if (j == n - 1) break;
      j++;
      add(rt, 0, m, s[j].first, s[j].second, 1);
      if (tr[rt]) {
        add(rt, 0, m, s[j].first, s[j].second, -1);
        j--;
        break;
      }
    }
    ans += j - i + 1;
    if (j >= i) add(rt, 0, m, s[i].first, s[i].second, -1);
    i++;
  }
  std::cout << ans << '\n';

}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

2
2 1

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

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: 2ms
memory: 9732kb

input:

10
2 2 1 2 2 2 1 4 1 4

output:

17

result:

ok 1 number(s): "17"

Test #4:

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

input:

10
1 5 2 2 5 4 4 4 1 3

output:

20

result:

ok 1 number(s): "20"

Test #5:

score: 0
Wrong Answer
time: 0ms
memory: 9788kb

input:

10
904418845477 67070474418 839309493679 528132965435 512894488193 602880026087 180594485896 804608714469 235337679831 584564033737

output:

28

result:

wrong answer 1st numbers differ - expected: '33', found: '28'

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%