結果

問題 No.1008 Bench Craftsman
ユーザー dyktr_06dyktr_06
提出日時 2024-03-21 02:09:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 363 ms / 2,000 ms
コード長 2,401 bytes
コンパイル時間 2,181 ms
コンパイル使用メモリ 206,256 KB
実行使用メモリ 7,180 KB
最終ジャッジ日時 2024-03-21 02:09:24
合計ジャッジ時間 11,041 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 351 ms
7,180 KB
testcase_06 AC 53 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 5 ms
6,676 KB
testcase_09 AC 58 ms
6,676 KB
testcase_10 AC 337 ms
7,180 KB
testcase_11 AC 337 ms
7,180 KB
testcase_12 AC 349 ms
7,180 KB
testcase_13 AC 336 ms
7,180 KB
testcase_14 AC 336 ms
7,180 KB
testcase_15 AC 363 ms
7,180 KB
testcase_16 AC 336 ms
7,180 KB
testcase_17 AC 346 ms
7,180 KB
testcase_18 AC 336 ms
7,180 KB
testcase_19 AC 344 ms
7,180 KB
testcase_20 AC 91 ms
6,676 KB
testcase_21 AC 110 ms
6,676 KB
testcase_22 AC 217 ms
6,676 KB
testcase_23 AC 268 ms
6,676 KB
testcase_24 AC 273 ms
6,676 KB
testcase_25 AC 68 ms
6,676 KB
testcase_26 AC 54 ms
6,676 KB
testcase_27 AC 177 ms
6,676 KB
testcase_28 AC 166 ms
6,676 KB
testcase_29 AC 276 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template <typename T>
struct imos_linear{
    int N;
    vector<T> imos1, imos0;
    imos_linear(int N) : N(N){ init(); }

    void init(){
        imos1.resize(N + 1);
        imos0.resize(N + 1);
    }

    // [l, r) に wX + v を加算 
    // imos[l] += v, imos[l + 1] += v + w, ...
    void add(int l, int r, T v, T w){
        l = clamp(l, 0, N), r = clamp(r, 0, N);
        imos1[l] += w;
        imos1[r] -= w;
        imos0[l] += v - w;
        imos0[r] -= v + w * (r - l - 1);
    }

    void build(){
        for(int i = 0; i < N; i++){
            imos1[i + 1] += imos1[i];
            imos0[i] += imos1[i];
            imos0[i + 1] += imos0[i];
        }
    }
    
    T & operator [](int i){
        return imos0[i];
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m; cin >> n >> m;
    vector<long long> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    vector<long long> x(m), w(m);
    for(int i = 0; i < m; i++){
        cin >> x[i] >> w[i];
        x[i]--;
    }
    long long ok = 1LL << 20, ng = -1;
    while(abs(ok - ng) > 1){
        long long mid = (ok + ng) / 2;
        imos_linear<long long> imos(n);
        for(int i = 0; i < m; i++){
            {
                long long ok2 = x[i], ng2 = n;
                while(abs(ok2 - ng2) > 1){
                    long long mid2 = (ok2 + ng2) / 2;
                    if((mid2 - x[i]) * mid <= w[i]){
                        ok2 = mid2;
                    }else{
                        ng2 = mid2;
                    }
                }
                imos.add(x[i], ok2 + 1, w[i], -mid);
            }
            {
                long long ok2 = x[i], ng2 = -1;
                while(abs(ok2 - ng2) > 1){
                    long long mid2 = (ok2 + ng2) / 2;
                    if((x[i] - mid2) * mid <= w[i]){
                        ok2 = mid2;
                    }else{
                        ng2 = mid2;
                    }
                }
                imos.add(ok2, x[i], w[i] - (x[i] - ok2) * mid, mid);
            }
        }
        imos.build();
        int is_ok = 1;
        for(int i = 0; i < n; i++){
            if(imos[i] >= a[i]) is_ok = 0;
        }
        if(is_ok) ok = mid;
        else ng = mid;
    }
    if(ok == 1LL << 20) cout << -1 << "\n";
    else cout << ok << "\n";
}
0