結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 RE -
testcase_03 AC 219 ms
13,820 KB
testcase_04 AC 216 ms
13,860 KB
testcase_05 AC 215 ms
13,848 KB
testcase_06 AC 228 ms
13,888 KB
testcase_07 AC 229 ms
13,876 KB
testcase_08 AC 230 ms
14,080 KB
testcase_09 AC 228 ms
13,872 KB
testcase_10 AC 229 ms
13,888 KB
testcase_11 AC 228 ms
13,880 KB
testcase_12 AC 220 ms
13,752 KB
testcase_13 AC 216 ms
13,872 KB
testcase_14 AC 217 ms
13,860 KB
testcase_15 AC 217 ms
13,812 KB
testcase_16 AC 219 ms
13,820 KB
testcase_17 AC 237 ms
13,860 KB
testcase_18 AC 236 ms
13,800 KB
testcase_19 AC 235 ms
13,872 KB
testcase_20 AC 237 ms
13,800 KB
testcase_21 AC 234 ms
13,820 KB
testcase_22 AC 236 ms
13,900 KB
testcase_23 AC 233 ms
13,824 KB
testcase_24 AC 236 ms
13,976 KB
testcase_25 AC 232 ms
13,832 KB
testcase_26 AC 232 ms
13,840 KB
testcase_27 AC 230 ms
13,844 KB
testcase_28 AC 230 ms
13,888 KB
testcase_29 AC 231 ms
14,060 KB
testcase_30 AC 231 ms
13,884 KB
testcase_31 AC 230 ms
13,872 KB
testcase_32 AC 208 ms
12,672 KB
testcase_33 AC 110 ms
8,648 KB
testcase_34 AC 101 ms
8,220 KB
testcase_35 AC 3 ms
4,384 KB
testcase_36 AC 210 ms
12,828 KB
testcase_37 AC 117 ms
8,736 KB
testcase_38 AC 109 ms
8,372 KB
testcase_39 AC 153 ms
10,948 KB
testcase_40 AC 86 ms
7,404 KB
testcase_41 AC 161 ms
11,080 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