QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#329525#8218. 水镜yzy17 1ms5884kbC++173.7kb2024-02-16 20:31:482024-02-16 20:31:50

Judging History

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

  • [2024-02-16 20:31:50]
  • 评测
  • 测评结果:7
  • 用时:1ms
  • 内存:5884kb
  • [2024-02-16 20:31:48]
  • 提交

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];

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

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

multiset<Node> S;
map<ll, vector<int>> mp;

inline void Upd(multiset<Node>::iterator it) {
  if (it->typ != '=') up(R[it->l], it->r + 1);
  auto it1 = next(it);
  if (it1 == S.end()) return;
  if (it->typ == '>') {
    if (it1->typ == '<')
      up(R[it->l], it1->r + 1);
    else if (auto it2 = next(it1); it2 != S.end() && it1->l == it1->r && it2->typ == '<') {
      up(R[it->l], it2->r + 1);
      // dbg(R[it->l], S[i + 2].r + 1);
    } else
      up(R[it->l], it->r + 2);
  } else if (it1->typ == '<')
    up(R[it->r], it1->r + 1);
}

inline char Cmp(ll x, ll y) {
  if (x < y) return '<';
  if (x == y) return '=';
  return '>';
}

inline void Cha(int p, char typ) {
  auto it = prev(S.upper_bound({p, 0, 0}));
  auto bak = *it;
  S.erase(it);
  if (bak.l <= p - 1) S.insert({bak.l, p - 1, bak.typ});
  if (p + 1 <= bak.r) S.insert({p + 1, bak.r, bak.typ});
  it = S.insert({p, p, typ});
  if (it != S.begin() && prev(it)->typ == typ) {
    int l = prev(it)->l, r = it->r;
    S.erase(prev(it)), S.erase(it);
    it = S.insert({l, r, typ});
  }
  if (next(it) != S.end() && next(it)->typ == typ) {
    int l = it->l, r = next(it)->r;
    S.erase(next(it)), S.erase(it);
    it = S.insert({l, r, typ});
  }
}

signed main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  re (i, n) cin >> a[i], a[i] <<= 1;
  re (i, n - 1) R[i] = i + 1;
  re (i, n - 1) {
    char typ = Cmp(a[i], a[i + 1]);
    if (S.empty() || S.rbegin()->typ != typ)
      S.insert({i, i, typ});
    else
      ++S.rbegin()->r;
  }
  // for (auto [l, r, typ] : S) cerr << l << ' ' << r << ' ' << typ << '\n';
  for (auto it = S.begin(); it != S.end(); ++it) Upd(it);
  re (i, n - 1) mp[a[i] + a[i + 1]].push_back(i), mp[a[i] + a[i + 1] + 1].push_back(i);
  for (auto [x, vec] : mp) {
    // cerr << "Before cha " << x << '\n';
    for (auto y : vec) {
      // dbg(y, Cmp(max(a[y], x - a[y]), max(a[y + 1], x - a[y + 1])));
      Cha(y, Cmp(max(a[y], x - a[y]), max(a[y + 1], x - a[y + 1])));
      // for (auto [l, r, typ] : S) cerr << l << ' ' << r << ' ' << typ << '\n';
    }
    // cerr << "After cha " << x << '\n';
    // for (auto [l, r, typ] : S) cerr << l << ' ' << r << ' ' << typ << '\n';
    for (auto y : vec) {
      auto it = prev(S.upper_bound({y, 0, 0}));
      re (_, 2) {
        Upd(it);
        if (it == S.begin()) break;
        --it;
      }
    }
  }
  ll ans = 0;
  rep (i, 2, n - 1) up(R[i], R[i - 1]);
  // re (i, n - 1) cerr << R[i] << " \n"[i == edi];
  re (i, n - 1) ans += R[i] - i;
  cout << ans << '\n';
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 7
Accepted

Test #1:

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

input:

2
2 1

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 5884kb

input:

10
2 2 2 2 1 4 5 3 3 2

output:

20

result:

ok 1 number(s): "20"

Test #3:

score: 0
Accepted
time: 0ms
memory: 5672kb

input:

10
2 2 1 2 2 2 1 4 1 4

output:

17

result:

ok 1 number(s): "17"

Test #4:

score: 0
Accepted
time: 1ms
memory: 5676kb

input:

10
1 5 2 2 5 4 4 4 1 3

output:

20

result:

ok 1 number(s): "20"

Test #5:

score: 0
Accepted
time: 1ms
memory: 5668kb

input:

10
904418845477 67070474418 839309493679 528132965435 512894488193 602880026087 180594485896 804608714469 235337679831 584564033737

output:

33

result:

ok 1 number(s): "33"

Test #6:

score: 0
Accepted
time: 1ms
memory: 5600kb

input:

10
2550179579 103777915839 144714526810 113623620429 670640709602 630479108288 925117980861 409440663027 851501568790 70823805701

output:

24

result:

ok 1 number(s): "24"

Test #7:

score: 0
Accepted
time: 0ms
memory: 5592kb

input:

10
814733530324 125370066936 893046741545 865528217532 707538863565 13490262680 251316040999 984630720558 697932598323 635301702897

output:

28

result:

ok 1 number(s): "28"

Test #8:

score: 0
Accepted
time: 1ms
memory: 5648kb

input:

10
501904615091 622412193418 211917353535 453793869542 275851842760 930019650158 919242753532 856846287041 5971781899 267788891712

output:

25

result:

ok 1 number(s): "25"

Test #9:

score: 0
Accepted
time: 1ms
memory: 5604kb

input:

10
1 2 3 4 5 6 7 8 9 10

output:

45

result:

ok 1 number(s): "45"

Test #10:

score: 0
Accepted
time: 1ms
memory: 5652kb

input:

10
1 9 3 7 5 5 7 3 9 1

output:

45

result:

ok 1 number(s): "45"

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #11:

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

input:

100
19 17 1 6 13 14 4 2 10 18 14 13 15 6 11 20 3 4 12 13 16 12 19 20 12 15 7 7 5 8 1 2 1 10 4 8 6 3 15 4 7 20 9 5 5 19 12 3 19 12 11 20 11 13 19 12 11 1 11 13 17 12 3 19 3 6 9 1 16 20 11 6 5 18 10 5 17 3 6 6 5 19 12 18 20 8 11 7 4 10 12 2 3 8 10 11 12 17 10 13

output:

353

result:

wrong answer 1st numbers differ - expected: '355', found: '353'

Subtask #3:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%