답안 #881361

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
881361 2023-12-01T07:44:09 Z nima_aryan Fancy Fence (CEOI20_fancyfence) C++17
12 / 100
1 ms 348 KB
/**
 *    author:  NimaAryan
 *    created: 2023-12-01 09:55:42  
**/
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "algo/debug.h"
#endif

using i64 = long long;

constexpr i64 M = 1E9 + 7;

void add(i64& x, i64 y) {
  if ((x += y) >= M) {
    x -= M;
  }
}

i64 C(i64 h, i64 w) {
  return ((h * (h + 1) / 2) % M) * ((w * (w + 1) / 2) % M) % M;
}
i64 F(i64 h) {
  return (h * (h + 1) / 2) % M;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<i64> h(N);
  for (int i = 0; i < N; ++i) {
    cin >> h[i];
  }
  vector<i64> w(N);
  for (int i = 0; i < N; ++i) {
    cin >> w[i];
  }
  vector<int> L(N);
  vector<int> stk;
  for (int i = 0; i < N; ++i) {
    while (!stk.empty() && h[stk.back()] > h[i]) {
      stk.pop_back();
    }
    L[i] = stk.empty() ? -1 : stk.back();
    stk.push_back(i);
  }
  vector<i64> sum(N + 1);
  for (int i = 0; i < N; ++i) {
    sum[i + 1] = sum[i] + w[i];
  }
  auto range_sum = [&](int l, int r) {
    return (sum[r] - sum[l]) % M;
  };
  vector<i64> mono(N);
  for (int i = 0; i < N; ++i) {
    add(mono[i], C(h[i], w[i]));
    add(mono[i], F(h[i]) * w[i] % M * range_sum(L[i] + 1, i) % M);
    if (L[i] != -1) {
      add(mono[i], w[i] * mono[L[i]] % M);
    }
  }
  cout << accumulate(mono.begin(), mono.end(), 0LL) % M << "\n";
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -