제출 #1359489

#제출 시각아이디문제언어결과실행 시간메모리
1359489thewizardmanZoltan (COCI16_zoltan)C++20
42 / 140
77 ms9720 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const ll md = 1'000'000'007;

ll n, a[200005];
vector<ll> vals;
array<ll, 2> ans;

class base {
protected:
  using node = array<ll, 2>;
  const node DEFAULT = {0, 1};
  int n = 0;
  node fw[200005];

  void mg(node &a, node b) {
  if (a[0] <= b[0]) {
    if (a[0] < b[0]) a = b;
    else a[1] += b[1], a[1] %= md;
  }
}
};

class : base {
public:
  using base::n;
  void update(int i, node val) {
    for (; i < n; i = i | (i + 1)) mg(fw[i], val);
  }
  node query(int i) {
    node ret = DEFAULT;
    for (; i >= 0; i = (i & (i + 1)) - 1) mg(ret, fw[i]);
    return ret;
  }
} lis;

class : base {
public:
  using base::n;
  void update(int i, node val) {
    for (; i >= 0; i = (i & (i + 1)) - 1) mg(fw[i], val);
  }
  node query(int i) {
    node ret = DEFAULT;
    for (; i < n; i = i | (i + 1)) mg(ret, fw[i]);
    return ret;
  }
} lds;

ll p(ll a, ll b) {
  ll ret = 1;
  while (b) {
    if (b&1) ret = ret * a % md;
    a = a * a % md;
    b >>= 1;
  }
  return ret;
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    vals.push_back(a[i]);
  }
  sort(vals.begin(), vals.end());
  vals.resize(unique(vals.begin(), vals.end()) - vals.begin());
  for (int i = 0; i < n; i++) a[i] = lower_bound(vals.begin(), vals.end(), a[i]) - vals.begin();
  lis.n = lds.n = vals.size();

  for (int i = n-1; i >= 0; i--) {
    auto q = lis.query(a[i]-1), qr = lds.query(a[i]+1);
    // cout << a[i] << ' ' << q[0] << ' ' << qr[0] << '\n';
    if (q[0] + qr[0] + 1 >= ans[0]) {
      if (q[0] + qr[0] + 1 > ans[0]) ans = {q[0] + qr[0] + 1, q[1] * qr[1] % md};
      else ans[1] += q[1] * qr[1], ans[1] %= md;
    }
    q[0]++, qr[0]++;
    lis.update(a[i], q);
    lds.update(a[i], qr);
  }

  cout << ans[0] << ' ' << ans[1] * p(2, n-ans[0]) << '\n';
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…