結果

問題 No.2643 Many Range Sums Problems
ユーザー shobonvipshobonvip
提出日時 2024-02-13 15:11:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 115 ms / 8,000 ms
コード長 1,049 bytes
コンパイル時間 2,032 ms
コンパイル使用メモリ 206,128 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-13 15:32:31
合計ジャッジ時間 4,527 ms
ジャッジサーバーID
(参考情報)
judge11 / 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 53 ms
6,676 KB
testcase_04 AC 44 ms
6,676 KB
testcase_05 AC 43 ms
6,676 KB
testcase_06 AC 61 ms
6,676 KB
testcase_07 AC 58 ms
6,676 KB
testcase_08 AC 55 ms
6,676 KB
testcase_09 AC 61 ms
6,676 KB
testcase_10 AC 52 ms
6,676 KB
testcase_11 AC 48 ms
6,676 KB
testcase_12 AC 71 ms
6,676 KB
testcase_13 AC 115 ms
6,676 KB
testcase_14 AC 56 ms
6,676 KB
testcase_15 AC 57 ms
6,676 KB
testcase_16 AC 47 ms
6,676 KB
testcase_17 AC 51 ms
6,676 KB
testcase_18 AC 33 ms
6,676 KB
testcase_19 AC 5 ms
6,676 KB
testcase_20 AC 14 ms
6,676 KB
testcase_21 AC 4 ms
6,676 KB
testcase_22 AC 17 ms
6,676 KB
testcase_23 AC 29 ms
6,676 KB
testcase_24 AC 55 ms
6,676 KB
testcase_25 AC 49 ms
6,676 KB
testcase_26 AC 6 ms
6,676 KB
testcase_27 AC 7 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 71 ms
6,676 KB
testcase_31 AC 59 ms
6,676 KB
testcase_32 AC 72 ms
6,676 KB
testcase_33 AC 71 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	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];
	}

	vector<ll> tmp_x = x;
	vector<int> tmp_v(n);
	vector<ll> tmp_rx(n+1);
	vector<int> tmp_rv(n+1);
	
	for (int st=0; st<n; st++){
		tmp_x[st] = 0;
		tmp_v[st] = 1;
		bool mode = 1;
		ll m_lb = -1e18;
		ll m_ub = 1e18;
		for (int i=n-1; i>=0; i--){
			tmp_rx[i] = tmp_rx[r[i]] + tmp_x[i];
			tmp_rv[i] = tmp_rv[r[i]] + tmp_v[i];
			ll tar_x = tmp_rx[i] - tmp_rx[i+1];
			ll tar_v = tmp_rv[i] - tmp_rv[i+1];
			if (tar_v == 0){
				if (!(0 <= tar_x && tar_x <= k)){
					mode = 0;
				}
			}else if(tar_v == 1){
				m_lb = max(m_lb, -tar_x);
				m_ub = min(m_ub, k-tar_x);
			}else{
				m_lb = max(m_lb, tar_x-k);
				m_ub = min(m_ub, tar_x);
			}
		}
		if (!(m_lb <= m_ub)){
			mode = 0;
		}
		if (mode){
			cout << "Yes\n";
		}else{
			cout << "No\n";
		}
		tmp_x[st] = x[st];
		tmp_v[st] = 0;
	}
}
0