結果

問題 No.1496 不思議な数え上げ
ユーザー 沙耶花沙耶花
提出日時 2021-04-30 23:17:46
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 238 ms / 3,000 ms
コード長 1,512 bytes
コンパイル時間 4,641 ms
コンパイル使用メモリ 265,412 KB
実行使用メモリ 14,080 KB
最終ジャッジ日時 2023-09-26 08:17:07
合計ジャッジ時間 17,022 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 216 ms
13,844 KB
testcase_04 AC 216 ms
13,832 KB
testcase_05 AC 217 ms
14,016 KB
testcase_06 AC 230 ms
14,060 KB
testcase_07 AC 232 ms
13,900 KB
testcase_08 AC 231 ms
13,788 KB
testcase_09 AC 235 ms
13,884 KB
testcase_10 AC 229 ms
13,888 KB
testcase_11 AC 231 ms
14,012 KB
testcase_12 AC 218 ms
13,880 KB
testcase_13 AC 218 ms
13,788 KB
testcase_14 AC 223 ms
13,824 KB
testcase_15 AC 217 ms
13,876 KB
testcase_16 AC 218 ms
14,012 KB
testcase_17 AC 236 ms
13,836 KB
testcase_18 AC 237 ms
13,892 KB
testcase_19 AC 235 ms
14,012 KB
testcase_20 AC 235 ms
13,888 KB
testcase_21 AC 238 ms
13,836 KB
testcase_22 AC 236 ms
13,880 KB
testcase_23 AC 233 ms
13,912 KB
testcase_24 AC 237 ms
13,888 KB
testcase_25 AC 232 ms
14,016 KB
testcase_26 AC 233 ms
14,080 KB
testcase_27 AC 233 ms
13,816 KB
testcase_28 AC 232 ms
13,856 KB
testcase_29 AC 233 ms
14,016 KB
testcase_30 AC 230 ms
13,888 KB
testcase_31 AC 230 ms
13,888 KB
testcase_32 AC 208 ms
12,708 KB
testcase_33 AC 111 ms
8,440 KB
testcase_34 AC 101 ms
8,216 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 212 ms
13,064 KB
testcase_37 AC 117 ms
8,712 KB
testcase_38 AC 108 ms
8,388 KB
testcase_39 AC 156 ms
10,968 KB
testcase_40 AC 85 ms
7,420 KB
testcase_41 AC 162 ms
11,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000

int N;
vector<int> P;
vector<long long> A;
vector<long long> ans;

void check(vector<pair<int,long long>> X,vector<pair<int,long long>> Y){
	rep(i,X.size()){
		if(X[i].first == Inf)continue;
		int ok = -1,ng = Y.size();
		while(ng-ok>1){
			int mid = (ok+ng)/2;
			bool f = true;
			if(Y[mid].first < X[i].first)f=false;
			if(Y[mid].second+X[i].second > A[X[i].first-1])f=false;
			if(f)ok = mid;
			else ng = mid;
		}
		ans[X[i].first-1] += ok+1;
	}
}

void dfs(int l,int r){
	//cout<<l<<','<<r<<endl;
	if(r-l==1){
		if(A[P[l]-1]>=P[l])ans[P[l]-1]++;
		return;
	}
	
	if(r-l==0)return;
	
	int m = (l+r)/2;
//	cout<<l<<','<<r<<endl;
	vector<pair<int,long long>> R(1,make_pair(P[m],P[m]));
	for(int i=m+1;i<r;i++){
		R.emplace_back(min(R.back().first,P[i]),R.back().second + P[i]);
	}
	//cout<<l<<','<<r<<endl;
	vector<pair<int,long long>> L(1,make_pair(P[m-1],P[m-1]));
	
	for(int i=m-2;i>=l;i--){
		L.emplace_back(min(L.back().first,P[i]),L.back().second + P[i]);
	}
	//cout<<l<<','<<r<<endl;
	check(R,L);
	check(L,R);
	//cout<<l<<','<<r<<endl;
	dfs(l,m);
	dfs(m,r);
	
}


int main(){
	
	cin>>N;
	
	P.resize(N),A.resize(N),ans.resize(N,0);
	
	rep(i,N){
		scanf("%d",&P[i]);
	}
	
	rep(i,N){
		scanf("%lld",&A[i]);
		
	}
	
	dfs(0,N);
	
	rep(i,N){
		printf("%lld\n",ans[i]);
	}
	
	
	
    return 0;
}
0