結果

問題 No.1496 不思議な数え上げ
ユーザー 沙耶花沙耶花
提出日時 2021-04-30 23:17:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,514 bytes
コンパイル時間 4,478 ms
コンパイル使用メモリ 265,044 KB
実行使用メモリ 14,152 KB
最終ジャッジ日時 2023-09-26 08:14:54
合計ジャッジ時間 16,333 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 RE -
testcase_03 AC 215 ms
13,856 KB
testcase_04 AC 218 ms
13,748 KB
testcase_05 AC 215 ms
14,012 KB
testcase_06 AC 228 ms
13,820 KB
testcase_07 AC 231 ms
13,820 KB
testcase_08 AC 231 ms
13,784 KB
testcase_09 AC 230 ms
14,016 KB
testcase_10 AC 236 ms
13,888 KB
testcase_11 AC 229 ms
13,848 KB
testcase_12 AC 215 ms
13,788 KB
testcase_13 AC 216 ms
13,820 KB
testcase_14 AC 218 ms
13,904 KB
testcase_15 AC 218 ms
13,808 KB
testcase_16 AC 217 ms
13,984 KB
testcase_17 AC 236 ms
13,908 KB
testcase_18 AC 235 ms
13,856 KB
testcase_19 AC 234 ms
13,988 KB
testcase_20 AC 237 ms
13,912 KB
testcase_21 AC 235 ms
13,816 KB
testcase_22 AC 237 ms
13,988 KB
testcase_23 AC 236 ms
14,152 KB
testcase_24 AC 237 ms
13,852 KB
testcase_25 AC 233 ms
13,912 KB
testcase_26 AC 234 ms
13,820 KB
testcase_27 AC 231 ms
13,752 KB
testcase_28 AC 233 ms
13,788 KB
testcase_29 AC 230 ms
14,016 KB
testcase_30 AC 232 ms
13,820 KB
testcase_31 AC 231 ms
14,016 KB
testcase_32 AC 207 ms
12,708 KB
testcase_33 AC 110 ms
8,544 KB
testcase_34 AC 101 ms
8,224 KB
testcase_35 AC 4 ms
4,376 KB
testcase_36 AC 211 ms
12,804 KB
testcase_37 AC 116 ms
8,608 KB
testcase_38 AC 109 ms
8,440 KB
testcase_39 AC 153 ms
10,940 KB
testcase_40 AC 87 ms
7,400 KB
testcase_41 AC 161 ms
11,164 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("%lld",&P[i]);
	}
	
	rep(i,N){
		scanf("%lld",&A[i]);
		
	}
	
	dfs(0,N);
	
	rep(i,N){
		printf("%lld\n",ans[i]);
	}
	
	
	
    return 0;
}
0