QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#329528#8218. 水镜yzy1Compile Error//C++173.8kb2024-02-16 20:33:332024-02-16 20:33:34

Judging History

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

  • [2024-02-16 20:33:34]
  • 评测
  • [2024-02-16 20:33:33]
  • 提交

answer

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")

#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 (_, 3) {
        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

In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from answer.code:5:
/usr/include/c++/13/bits/allocator.h: In destructor ‘std::_Rb_tree<Node, Node, std::_Identity<Node>, std::less<Node>, std::allocator<Node> >::_Rb_tree_impl<std::less<Node>, true>::~_Rb_tree_impl()’:
/usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to ‘always_inline’ ‘std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = std::_Rb_tree_node<Node>]’: target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/map:62,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:152:
/usr/include/c++/13/bits/stl_tree.h:662:16: note: called from here
  662 |         struct _Rb_tree_impl
      |                ^~~~~~~~~~~~~