結果
| 問題 | No.2567 A_1 > A_2 > ... > A_N | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-12-02 15:47:41 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 106 ms / 2,000 ms | 
| コード長 | 1,282 bytes | 
| コンパイル時間 | 2,005 ms | 
| コンパイル使用メモリ | 194,372 KB | 
| 最終ジャッジ日時 | 2025-02-18 04:57:23 | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 16 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) {
    if(vec.empty()) return os;
    os << vec[0];
    for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it;
    return os;
}
template<typename T>
T MUL(T a, T b){
    T res;
    return __builtin_mul_overflow(a, b, &res)? std::numeric_limits<T>::max() : res;
}
long long arith_sum1(long long fst, long long n, long long d){
    return MUL(n, MUL(2ll, fst) + MUL(n - 1, d)) / 2;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        ll n, x;
        cin >> n >> x;
        if(x < n * (n + 1) / 2){
            cout << -1 << '\n';
            continue;
        }
        auto f = [&](ll v){
            return MUL(v, v + 1) / 2;
        };
        vector<ll> ans(n);
        for(int i = 0; i < n; i++){
            ll ng = 0, ok = x, mid;
            ll r = (n - i) * (n - i - 1) / 2;
            while(ng + 1 < ok){
                mid = (ok + ng) / 2;
                if(x - mid <= arith_sum1(mid - 1, n - i - 1, -1)) ok = mid;
                else ng = mid;
            }
            ans[i] = ok;
            x -= ok;
        }
        cout << ans << '\n';
    }
}
            
            
            
        