結果

問題 No.1031 いたずら好きなお姉ちゃん
ユーザー RhoRho
提出日時 2020-04-17 00:01:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 527 ms / 3,500 ms
コード長 1,748 bytes
コンパイル時間 2,132 ms
コンパイル使用メモリ 177,184 KB
実行使用メモリ 18,304 KB
最終ジャッジ日時 2024-04-14 07:16:25
合計ジャッジ時間 20,645 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 8 ms
6,944 KB
testcase_04 AC 8 ms
6,940 KB
testcase_05 AC 8 ms
6,940 KB
testcase_06 AC 8 ms
6,944 KB
testcase_07 AC 8 ms
6,944 KB
testcase_08 AC 8 ms
6,940 KB
testcase_09 AC 8 ms
6,940 KB
testcase_10 AC 8 ms
6,944 KB
testcase_11 AC 314 ms
15,636 KB
testcase_12 AC 303 ms
15,432 KB
testcase_13 AC 404 ms
17,748 KB
testcase_14 AC 323 ms
15,852 KB
testcase_15 AC 363 ms
16,932 KB
testcase_16 AC 295 ms
15,072 KB
testcase_17 AC 378 ms
17,000 KB
testcase_18 AC 357 ms
16,436 KB
testcase_19 AC 385 ms
16,968 KB
testcase_20 AC 410 ms
17,880 KB
testcase_21 AC 355 ms
16,600 KB
testcase_22 AC 294 ms
15,200 KB
testcase_23 AC 307 ms
15,612 KB
testcase_24 AC 361 ms
17,024 KB
testcase_25 AC 382 ms
17,788 KB
testcase_26 AC 357 ms
16,864 KB
testcase_27 AC 334 ms
15,904 KB
testcase_28 AC 398 ms
17,788 KB
testcase_29 AC 405 ms
17,888 KB
testcase_30 AC 407 ms
17,792 KB
testcase_31 AC 401 ms
17,796 KB
testcase_32 AC 408 ms
17,792 KB
testcase_33 AC 401 ms
17,796 KB
testcase_34 AC 499 ms
18,176 KB
testcase_35 AC 376 ms
18,304 KB
testcase_36 AC 328 ms
18,196 KB
testcase_37 AC 362 ms
18,300 KB
testcase_38 AC 328 ms
18,020 KB
testcase_39 AC 311 ms
17,988 KB
testcase_40 AC 322 ms
18,048 KB
testcase_41 AC 343 ms
17,996 KB
testcase_42 AC 359 ms
17,948 KB
testcase_43 AC 287 ms
18,184 KB
testcase_44 AC 282 ms
18,060 KB
testcase_45 AC 271 ms
17,520 KB
testcase_46 AC 367 ms
17,436 KB
testcase_47 AC 385 ms
17,376 KB
testcase_48 AC 381 ms
17,712 KB
testcase_49 AC 375 ms
17,820 KB
testcase_50 AC 366 ms
17,628 KB
testcase_51 AC 526 ms
17,464 KB
testcase_52 AC 527 ms
17,356 KB
testcase_53 AC 525 ms
17,340 KB
testcase_54 AC 2 ms
6,944 KB
testcase_55 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma warning(disable:4996)
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define RE assert(0);
const long long inf = 1e17;
typedef pair<int, int> P;
int p[100006];
vector<P>seg[400];
int segmax[400];
int n, k, sqrtN;
void maekei() {
	rep(i, k) {
		for (int j = i*sqrtN; j < min((i + 1)*sqrtN, n); j++) {
			segmax[i] = max(segmax[i], p[j]);
			int cnt = 0, mn = p[j];
			for (int l = i*sqrtN; l < min((i + 1)*sqrtN, n); l++) {
				if (mn <= p[l]) {
					cnt++;
					mn = p[l];
				}
			}
			seg[i].push_back(P(p[j], cnt));
		}
		sort(seg[i].begin(), seg[i].end());
	}
}
int calseg(int l, int r) {
	int mx = p[l];
	int ans = 0;
	rep(i, k) {
		int L = i*sqrtN, R = (i + 1)*sqrtN;
		if (R <= l || r <= L)continue;
		if (l <= L&&R <= r) {
			auto p = lower_bound(seg[i].begin(), seg[i].end(), P(mx, inf));
			if (p != seg[i].end()) {
				ans += (*p).second;
				mx = segmax[i];
			}
		}
		else {
			for (int j = max(L, l); j < min(R, r); j++) {
				if (mx < p[j]) {
					ans++;
					mx = p[j];
				}
			}
		}
	}
	return ans;
}
int divseg() {
	int res = 0;
	maekei();
	vector<P>V;
	rep(i, n)V.push_back(P(p[i], i));
	sort(V.begin(), V.end());
	set<int>S;
	S.insert(n);
	rep(i, n) {
		int r = *S.lower_bound(V[i].second);
		res += calseg(V[i].second, r);
		S.insert(V[i].second);
	}
	return res;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	sqrtN = sqrt(n);
	k = (n + sqrtN - 1) / sqrtN;
	if (1 > n || n > 100000)RE;
	set<int>S;
	rep(i, n) {
		cin >> p[i];
		if (p[i]<1 || p[i]>n)RE;
		S.insert(p[i]);
	}
	if (S.size() != n)RE;
	int res = divseg();
	reverse(p, p + n);
	rep(i, 400) {
		seg[i].clear();
		segmax[i] = 0;
	}
	res += divseg();
	cout << res << endl;
}
0