結果

問題 No.2643 Many Range Sums Problems
ユーザー otoshigootoshigo
提出日時 2024-02-20 16:22:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 8,000 ms
コード長 1,813 bytes
コンパイル時間 917 ms
コンパイル使用メモリ 80,528 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-20 16:22:16
合計ジャッジ時間 3,489 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 80 ms
6,676 KB
testcase_04 AC 65 ms
6,676 KB
testcase_05 AC 64 ms
6,676 KB
testcase_06 AC 92 ms
6,676 KB
testcase_07 AC 89 ms
6,676 KB
testcase_08 AC 60 ms
6,676 KB
testcase_09 AC 39 ms
6,676 KB
testcase_10 AC 81 ms
6,676 KB
testcase_11 AC 64 ms
6,676 KB
testcase_12 AC 18 ms
6,676 KB
testcase_13 AC 17 ms
6,676 KB
testcase_14 AC 74 ms
6,676 KB
testcase_15 AC 76 ms
6,676 KB
testcase_16 AC 49 ms
6,676 KB
testcase_17 AC 63 ms
6,676 KB
testcase_18 AC 9 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 12 ms
6,676 KB
testcase_21 AC 5 ms
6,676 KB
testcase_22 AC 9 ms
6,676 KB
testcase_23 AC 11 ms
6,676 KB
testcase_24 AC 15 ms
6,676 KB
testcase_25 AC 18 ms
6,676 KB
testcase_26 AC 3 ms
6,676 KB
testcase_27 AC 3 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 95 ms
6,676 KB
testcase_31 AC 97 ms
6,676 KB
testcase_32 AC 18 ms
6,676 KB
testcase_33 AC 18 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

const ll INF=1LL<<60;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    ll K;
    cin>>N>>K;
    vector<int>R(N);
    vector<ll>X(N);
    for(int i=0;i<N;i++){
        cin>>R[i]>>X[i];
        R[i]--;
    }
    for(int i=0;i<N;i++){
        vector<ll>A(N),S(N+1);
        bool ok=true;
        for(int j=N-1;j>i;j--){
            A[j]=X[j]-(S[j+1]-S[R[j]+1]);
            if(A[j]<0||A[j]>K){
                ok=false;
                break;
            }
            S[j]=A[j]+S[j+1];
        }
        if(!ok){
            cout<<"No"<<"\n";
            continue;
        }
        /* A[i] = x */
        vector<ll>x(i+1),y(N+1);
        x[i]=1;
        y[i]=1;
        S[i]=S[i+1];
        for(int j=i-1;j>=0;j--){
            A[j]=X[j]-(S[j+1]-S[R[j]+1]);
            x[j]=-(y[j+1]-y[R[j]+1]);
            if(x[j]==0&&(A[j]<0||A[j]>K)){
                ok=false;
                break;
            }
            S[j]=A[j]+S[j+1];
            y[j]=x[j]+y[j+1];
        }
        if(!ok){
            cout<<"No"<<"\n";
        }else{
            ll l=-INF,r=INF;
            for(int j=i;j>=0;j--){
                if(x[j]==1){
                    chmax(l,-A[j]);
                    chmin(r,K-A[j]);
                }else if(x[j]==-1){
                    chmax(l,A[j]-K);
                    chmin(r,A[j]);
                }
            }
            if(l>r)cout<<"No"<<"\n";
            else cout<<"Yes"<<"\n";
        }
    }
}
0