QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#329473#8218. 水镜yzy10 1ms7640kbC++172.4kb2024-02-16 19:24:412024-02-16 19:24:41

Judging History

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

  • [2024-02-16 19:24:41]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:7640kb
  • [2024-02-16 19:24:41]
  • 提交

answer

#include <bits/stdc++.h>

#if defined(LOCAL)
#define DBG_MACRO_NO_WARNING
#include <dbg.hpp>
#else
#define dbg(x...) (0)
#endif

using namespace std;

using ll = long long;

// #define int ll
#define rep(i, f, t) for (int i = (f), ed##i = (t); i <= ed##i; ++i)
#define re(i, t) rep (i, 1, t)
#define per(i, t, f) for (int i = (t), ed##i = (f); i >= ed##i; --i)
#define ste(i, f, t, s) for (int i = (f), ed##i = (t); i <= ed##i; i += s)
#define nxt(i, f, g) for (int i = g.h[f]; i; i = g.e[i].n)
#define umod(x) ((x) >= mo && ((x) -= mo))
#define dmod(x) ((x) < 0 && ((x) += mo))
#define y1 y1__
#define fio(x) (freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout))

template <class T, class E>
__attribute__((always_inline)) inline void up(T &x, E &&y) {
  if (x < y) x = y;
}
template <class T, class E>
__attribute__((always_inline)) inline void down(T &x, E &&y) {
  if (y < x) x = y;
}

const int N = 1e6 + 9;
int n, R[N];
ll a[N], b[N];

struct Node {
  int l;
  mutable int r;
  mutable char typ;
};

inline bool operator<(Node x, Node y) { return x.l < y.l; }

inline void Try(ll x) {
  re (i, n) b[i] = max(a[i], x - a[i]);
  vector<Node> S;
  re (i, n - 1) {
    char typ;
    if (b[i] < b[i + 1])
      typ = '<';
    else if (b[i] == b[i + 1])
      typ = '=';
    else
      typ = '>';
    if (S.empty() || S.back().typ != typ)
      S.push_back({i, i, typ});
    else
      ++S.back().r;
  }
  // for (auto [l, r, typ] : S) cerr << l << ' ' << r << ' ' << typ << '\n';
  rep (i, 0, S.size() - 1) {
    if (S[i].typ != '=' || S[i].l == S[i].r) up(R[S[i].l], S[i].r + 1);
    if (i <= (int)S.size() - 2) {
      if (S[i].typ == '>') {
        if (S[i + 1].typ == '<')
          up(R[S[i].l], S[i + 1].r + 1);
        else if (i <= (int)S.size() - 3 && S[i + 1].l == S[i + 1].r && S[i + 2].typ == '<') {
          up(R[S[i].l], S[i + 2].r + 1);
          // dbg(R[S[i].l], S[i + 2].r + 1);
        } else
          up(R[S[i].l], S[i].r + 2);
      } else if (S[i + 1].typ == '<')
        up(R[S[i].r], S[i + 1].r + 1);
    }
  }
}

signed main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  re (i, n) cin >> a[i];
  re (i, n) R[i] = i;
  // Try(5), exit(0);
  re (i, n - 1) Try(a[i] + a[i + 1]);
  ll ans = 0;
  rep (i, 2, n) up(R[i], R[i - 1]);
  // re (i, n) cerr << R[i] << " \n"[i == edi];
  re (i, n) ans += R[i] - i;
  cout << ans << '\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: 1ms
memory: 7624kb

input:

2
2 1

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: -7
Wrong Answer
time: 1ms
memory: 7640kb

input:

10
2 2 2 2 1 4 5 3 3 2

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%