結果
| 問題 |
No.3324 ハイライト動画
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-08-22 11:22:30 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 61 ms / 2,000 ms |
| コード長 | 1,553 bytes |
| コンパイル時間 | 2,764 ms |
| コンパイル使用メモリ | 281,324 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-11-01 14:30:37 |
| 合計ジャッジ時間 | 4,573 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#include <bits/stdc++.h>
// A の累積和を求める前計算
[[nodiscard]] static inline constexpr std::vector<uint_least64_t> prepare(const uint_fast32_t M, const std::vector<uint_least32_t>& A) noexcept
{
std::vector<uint_least64_t> csum_A(M + 1, 0);
for (uint_fast32_t i = 0; i != M; ++i)
csum_A[i + 1] = csum_A[i] + A[i];
return csum_A;
}
[[nodiscard]] static inline constexpr std::vector<std::pair<uint_least32_t, uint_least32_t>> solve([[maybe_unused]] const uint_fast32_t N, const uint_fast32_t M, const std::vector<uint_least32_t>& A) noexcept
{
const std::vector<uint_least64_t>& csum_A = prepare(M, A);
std::vector<std::pair<uint_least32_t, uint_least32_t>> ans;
ans.reserve(M);
for (uint_fast32_t i = 0, l = 1, r = M + 1; i != M; i = l, l = i + 1, r = M + 1)
{
while (l + 1 < r) // 二分探索
{
const uint_fast32_t c = (l + r) / 2;
if (csum_A[c] - csum_A[i] == static_cast<uint_fast64_t>(c - i) * (A[i] * 2 + (c - i - 1)) / 2) // 右辺は等差数列の総和の公式の公差 1 の場合
l = c;
else
r = c;
}
ans.emplace_back(A[i], l - i);
}
return ans;
}
static inline void output(const std::vector<std::pair<uint_least32_t, uint_least32_t>>& ans) noexcept
{
std::cout << ans.size() << '\n';
for (const auto& [S, L] : ans)
std::cout << S << ' ' << L << '\n';
}
int main()
{
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
uint_fast32_t N, M;
std::cin >> N >> M;
std::vector<uint_least32_t> A(M);
for (auto& a : A) std::cin >> a;
output(solve(N, M, A));
return 0;
}