結果

問題 No.1496 不思議な数え上げ
ユーザー kotatsugamekotatsugame
提出日時 2021-05-02 04:22:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 650 ms / 3,000 ms
コード長 743 bytes
コンパイル時間 1,528 ms
コンパイル使用メモリ 74,420 KB
実行使用メモリ 16,204 KB
最終ジャッジ日時 2023-09-27 18:19:38
合計ジャッジ時間 25,524 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,056 KB
testcase_01 AC 2 ms
4,992 KB
testcase_02 AC 1 ms
5,052 KB
testcase_03 AC 521 ms
15,844 KB
testcase_04 AC 508 ms
16,204 KB
testcase_05 AC 516 ms
15,848 KB
testcase_06 AC 542 ms
15,996 KB
testcase_07 AC 539 ms
16,192 KB
testcase_08 AC 540 ms
16,184 KB
testcase_09 AC 538 ms
15,996 KB
testcase_10 AC 533 ms
16,064 KB
testcase_11 AC 533 ms
15,928 KB
testcase_12 AC 518 ms
16,140 KB
testcase_13 AC 524 ms
16,140 KB
testcase_14 AC 520 ms
15,996 KB
testcase_15 AC 520 ms
16,204 KB
testcase_16 AC 529 ms
15,928 KB
testcase_17 AC 650 ms
15,832 KB
testcase_18 AC 625 ms
15,876 KB
testcase_19 AC 635 ms
15,876 KB
testcase_20 AC 629 ms
15,880 KB
testcase_21 AC 624 ms
16,060 KB
testcase_22 AC 627 ms
16,068 KB
testcase_23 AC 625 ms
16,192 KB
testcase_24 AC 635 ms
16,204 KB
testcase_25 AC 626 ms
15,924 KB
testcase_26 AC 626 ms
15,888 KB
testcase_27 AC 602 ms
15,892 KB
testcase_28 AC 603 ms
16,140 KB
testcase_29 AC 609 ms
15,828 KB
testcase_30 AC 605 ms
15,908 KB
testcase_31 AC 600 ms
16,068 KB
testcase_32 AC 547 ms
14,324 KB
testcase_33 AC 275 ms
9,516 KB
testcase_34 AC 260 ms
9,348 KB
testcase_35 AC 7 ms
4,996 KB
testcase_36 AC 562 ms
14,868 KB
testcase_37 AC 298 ms
10,004 KB
testcase_38 AC 279 ms
9,752 KB
testcase_39 AC 397 ms
11,676 KB
testcase_40 AC 210 ms
8,264 KB
testcase_41 AC 416 ms
12,176 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    7 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<set>
using namespace std;
int N,P[2<<17];
long S[2<<17];
int inv[2<<17];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>P[i];
		inv[P[i]-1]=i;
		S[i+1]=S[i]+P[i];
	}
	set<int>st({-1,N});
	for(int i=0;i<N;i++)
	{
		long A;cin>>A;
		int k=inv[i];
		auto it=st.insert(k).first;
		int R=*++it,L=*----it;
		long ans=0;
		if(k-L<R-k)
		{
			for(int x=L+1;x<=k;x++)
			{
				int l=k,r=R+1;
				while(r-l>1)
				{
					int mid=(l+r)/2;
					if(S[mid]-S[x]<=A)l=mid;
					else r=mid;
				}
				ans+=l-k;
			}
		}
		else
		{
			for(int y=k;y<R;y++)
			{
				int l=L-1,r=k;
				while(r-l>1)
				{
					int mid=(l+r)/2;
					if(S[y+1]-S[mid+1]<=A)r=mid;
					else l=mid;
				}
				ans+=k-r;
			}
		}
		cout<<ans<<endl;
	}
}
0