QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#558250#8218. 水镜Fido_Puppy0 0ms24456kbC++232.7kb2024-09-11 15:06:392024-09-11 15:06:39

Judging History

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

  • [2024-09-11 15:06:39]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:24456kb
  • [2024-09-11 15:06:39]
  • 提交

answer

#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
#define eb emplace_back
#define rz resize
#define MP make_pair
#define MT make_tuple
#define IT iterator
#define fi first
#define se second
#define For(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define Rep(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define CLR(a, v) memset(a, v, sizeof(a))
#define CPY(a, b) memcpy(a, b, sizeof(a))
#define debug cerr << "ztxakking\n"
#define y0 ztxaknoi
#define y1 ztxakioi
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using vi = vector<int>;
template<typename T>
using V = vector<T>;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int N = 5e5 + 7;
const ll Inf = 0x3fffffffffffffff;
int n;
ll h[N], ans;
ll a[N], b[N];
#define Bit(x) (31 - __builtin_clz(x))
struct MinSparseTable {
  ll arr[19][N];
  void init(ll *a) {
    For(i, 1, n) arr[0][i] = a[i];
    For(i, 1, Bit(n)) For(j, 1, n - (1 << i) + 1) arr[i][j] = min(arr[i - 1][j], arr[i - 1][j + (1 << i - 1)]);
  }
  ll qry(int l, int r) {
    if (l > r) return Inf;
    int t = Bit(r - l + 1);
    return min(arr[t][l], arr[t][r - (1 << t) + 1]);
  }
} B;
struct MaxSparseTable {
  ll arr[19][N];
  void init(ll *a) {
    For(i, 1, n) arr[0][i] = a[i];
    For(i, 1, Bit(n)) For(j, 1, n - (1 << i) + 1) arr[i][j] = max(arr[i - 1][j], arr[i - 1][j + (1 << i - 1)]);
  }
  ll qry(int l, int r) {
    if (l > r) return -Inf;
    int t = Bit(r - l + 1);
    return max(arr[t][l], arr[t][r - (1 << t) + 1]);
  }
} A;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  For(i, 1, n) cin >> h[i];
  For(i, 1, n - 2) {
    ll l1, r1, l2, r2;
    auto work = [&] (ll a, ll b, ll &l, ll &r) -> void { // >=
      if (a == b) return l = -Inf, r = Inf, void();
      if (a > b) l = -Inf, r = a + b;
      else l = a + b, r = Inf;
    };
    work(h[i + 1], h[i], l1, r1), work(h[i + 1], h[i + 2], l2, r2);
    l1 = max(l1, l2), r1 = min(r1, r2);
    if (l1 <= r1) {
      assert(l1 == -Inf || r1 == Inf);
      if (l1 == -Inf) a[i] = r1 + 1, b[i] = Inf;
      else b[i] = l1 - 1, a[i] = -Inf;
    } else a[i] = -Inf, b[i] = Inf;
  }
  A.init(a), B.init(b);
  for (int i = 1, j = 1; i <= n; ++i) {
    auto check = [&] (int l, int r) {
      return A.qry(l, r - 2) <= B.qry(l, r - 2);
    };
    j = max(j, i + 1);
    while (j <= n && check(i, j)) ++j;
    ans += j - i - 1;
  }
  cout << ans << '\n';
  cerr << (double)(clock()) / CLOCKS_PER_SEC << '\n';
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

2
2 1

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

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: 0ms
memory: 24336kb

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: 0ms
memory: 24456kb

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%