結果

問題 No.2821 A[i] ← 2A[j] - A[i]
ユーザー 🦠みどりむし
提出日時 2023-08-31 23:59:08
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 80 ms / 1,500 ms
コード長 873 bytes
コンパイル時間 1,199 ms
コンパイル使用メモリ 122,292 KB
実行使用メモリ 12,560 KB
最終ジャッジ日時 2024-07-26 20:50:18
合計ジャッジ時間 3,742 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdint>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <iostream>
#include <valarray>
#include <ranges>

using i64 = std::int64_t;

std::valarray<i64> solve() {
    int n; std::cin >> n;

    std::valarray<i64> a(n); for(i64& x : a) std::cin >> x;

    std::valarray<i64> diff(n), prefix_gcd(n), ans(n);
    std::adjacent_difference(std::begin(a), std::end(a), std::begin(diff));
    std::inclusive_scan(std::next(std::begin(diff)), std::end(diff), std::next(std::begin(prefix_gcd)), std::gcd<i64,i64>);
    std::transform(std::begin(prefix_gcd), std::end(prefix_gcd), std::begin(ans), [&](const i64 v) { return std::abs(v); });

    return ans;
}

int main() {
    for(i64 x : solve()) std::cout << x << "\n";
    return 0;
}

__attribute__((constructor)) inline void fast_io() { std::ios::sync_with_stdio(false), std::cin.tie(nullptr); }
0