結果

問題 No.1031 いたずら好きなお姉ちゃん
ユーザー 👑 kmjpkmjp
提出日時 2020-04-18 01:32:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 119 ms / 3,500 ms
コード長 1,624 bytes
コンパイル時間 2,509 ms
コンパイル使用メモリ 211,060 KB
実行使用メモリ 25,924 KB
最終ジャッジ日時 2024-04-14 19:03:00
合計ジャッジ時間 8,425 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,944 KB
testcase_03 AC 5 ms
6,940 KB
testcase_04 AC 5 ms
6,940 KB
testcase_05 AC 5 ms
6,944 KB
testcase_06 AC 5 ms
6,944 KB
testcase_07 AC 5 ms
6,944 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 AC 5 ms
6,940 KB
testcase_10 AC 5 ms
6,944 KB
testcase_11 AC 88 ms
23,592 KB
testcase_12 AC 86 ms
23,080 KB
testcase_13 AC 108 ms
25,620 KB
testcase_14 AC 92 ms
23,888 KB
testcase_15 AC 106 ms
24,672 KB
testcase_16 AC 89 ms
23,200 KB
testcase_17 AC 105 ms
25,144 KB
testcase_18 AC 100 ms
24,344 KB
testcase_19 AC 110 ms
24,896 KB
testcase_20 AC 119 ms
25,444 KB
testcase_21 AC 100 ms
24,716 KB
testcase_22 AC 88 ms
24,224 KB
testcase_23 AC 86 ms
23,352 KB
testcase_24 AC 104 ms
24,856 KB
testcase_25 AC 112 ms
25,408 KB
testcase_26 AC 101 ms
24,264 KB
testcase_27 AC 94 ms
23,620 KB
testcase_28 AC 111 ms
25,604 KB
testcase_29 AC 113 ms
25,576 KB
testcase_30 AC 119 ms
25,492 KB
testcase_31 AC 114 ms
25,632 KB
testcase_32 AC 115 ms
25,508 KB
testcase_33 AC 115 ms
25,696 KB
testcase_34 AC 79 ms
25,924 KB
testcase_35 AC 76 ms
25,684 KB
testcase_36 AC 77 ms
25,592 KB
testcase_37 AC 75 ms
25,792 KB
testcase_38 AC 72 ms
25,344 KB
testcase_39 AC 70 ms
25,028 KB
testcase_40 AC 71 ms
25,160 KB
testcase_41 AC 73 ms
25,408 KB
testcase_42 AC 73 ms
25,380 KB
testcase_43 AC 68 ms
25,524 KB
testcase_44 AC 67 ms
25,504 KB
testcase_45 AC 66 ms
24,952 KB
testcase_46 AC 85 ms
25,592 KB
testcase_47 AC 74 ms
25,080 KB
testcase_48 AC 74 ms
25,704 KB
testcase_49 AC 75 ms
25,532 KB
testcase_50 AC 72 ms
25,680 KB
testcase_51 AC 85 ms
25,860 KB
testcase_52 AC 86 ms
25,832 KB
testcase_53 AC 86 ms
25,896 KB
testcase_54 AC 3 ms
6,944 KB
testcase_55 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N;
int P[101010];
int L[101010][21],R[101010][21];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	vector<pair<int,int>> cand;
	FOR(i,N) {
		cin>>P[i+1];
		cand.push_back({P[i+1],i+1});
	}
	FOR(j,20) R[N+1][j]=N+1;
	vector<int> V;
	FOR(i,N+1) {
		while(V.size()&&P[V.back()]>P[i]) V.pop_back();
		if(V.size()) L[i][0]=V.back();
		V.push_back(i);
	}
	V.clear();
	V.push_back(N+1);
	for(i=N;i>=1;i--) {
		while(V.size()&&P[V.back()]>P[i]) V.pop_back();
		if(V.size()) R[i][0]=V.back();
		V.push_back(i);
	}
	FOR(i,20) FOR(j,N) L[j+1][i+1]=L[L[j+1][i]][i],R[j+1][i+1]=R[R[j+1][i]][i];
	
	set<int> D;
	D.insert(0);
	D.insert(N+1);
	sort(ALL(cand));
	reverse(ALL(cand));
	ll ret=0;
	FORR(c,cand) {
		x=c.second;
		auto it=D.insert(x).first;
		i=*prev(it);
		j=*next(it);
		int cur=x;
		for(y=19;y>=0;y--) if(R[cur][y]<j) cur=R[cur][y],ret+=1<<y;
		cur=x;
		for(y=19;y>=0;y--) if(L[cur][y]>i) cur=L[cur][y],ret+=1<<y;
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0