답안 #1011479

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1011479 2024-06-30T14:09:02 Z MilosMilutinovic Zoltan (COCI16_zoltan) C++14
140 / 140
72 ms 8520 KB
#include <bits/stdc++.h>

using namespace std;

const int md = 1e9 + 7;

int add(int a, int b) {
  return a + b < md ? a + b : a + b - md;
}

void ckadd(int& a, int b) {
  a = add(a, b);
}

int mul(int a, int b) {
  return a * 1LL * b % md;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<int> xs = a;
  xs.push_back(-1);
  xs.push_back(1.0001e9);
  sort(xs.begin(), xs.end());
  xs.erase(unique(xs.begin(), xs.end()), xs.end());
  for (int i = 0; i < n; i++) {
    a[i] = (int) (lower_bound(xs.begin(), xs.end(), a[i]) - xs.begin());
  }
  int k = (int) xs.size();
  vector<pair<int, int>> fenw(k, {-1, 0});
  auto Modify = [&](int p, pair<int, int> v) {
    while (p < k) {
      if (fenw[p].first == v.first) {
        ckadd(fenw[p].second, v.second);
      } else {
        fenw[p] = max(fenw[p], v);
      }
      p |= (p + 1);
    }
  };
  auto Query = [&](int p) {
    pair<int, int> ret = {-1, 0};
    while (p >= 0) {
      if (fenw[p].first == ret.first) {
        ckadd(ret.second, fenw[p].second);
      } else {
        ret = max(ret, fenw[p]);
      }
      p = (p & (p + 1)) - 1;
    }
    return ret;
  };
  Modify(0, {0, 1});
  vector<pair<int, int>> dp_big(n);
  vector<pair<int, int>> dp_small(n);
  for (int i = n - 1; i >= 0; i--) {
    dp_big[i] = Query(k - a[i] - 2);
    Modify(k - a[i] - 1, {dp_big[i].first + 1, dp_big[i].second});
  }
  for (int i = 0; i < k; i++){
    fenw[i] = {-1, 0};
  }
  Modify(0, {0, 1});
  for (int i = n - 1; i >= 0; i--) {
    dp_small[i] = Query(a[i] - 1);
    Modify(a[i], {dp_small[i].first + 1, dp_small[i].second});
  }
  pair<int, int> res = {0, 1};
  for (int i = 0; i < n; i++) {
    pair<int, int> my;
    my.first = dp_small[i].first + dp_big[i].first + 1;
    my.second = mul(dp_small[i].second, dp_big[i].second);
    if (my.first == res.first) {
      ckadd(res.second, my.second);
    } else {
      res = max(res, my);
    }
  }
  for (int i = 0; i < n - res.first; i++) {
    res.second = mul(res.second, 2);
  }
  cout << res.first << " " << res.second << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 41 ms 6544 KB Output is correct
12 Correct 38 ms 5812 KB Output is correct
13 Correct 35 ms 5460 KB Output is correct
14 Correct 56 ms 5892 KB Output is correct
15 Correct 65 ms 7352 KB Output is correct
16 Correct 72 ms 8520 KB Output is correct
17 Correct 51 ms 7488 KB Output is correct
18 Correct 52 ms 7488 KB Output is correct
19 Correct 50 ms 7492 KB Output is correct
20 Correct 52 ms 7488 KB Output is correct