結果

問題 No.1031 いたずら好きなお姉ちゃん
ユーザー RhoRho
提出日時 2020-04-16 22:37:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 496 ms / 3,500 ms
コード長 1,576 bytes
コンパイル時間 1,906 ms
コンパイル使用メモリ 176,648 KB
実行使用メモリ 13,672 KB
最終ジャッジ日時 2024-04-14 06:05:51
合計ジャッジ時間 18,189 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 7 ms
6,940 KB
testcase_04 AC 7 ms
6,940 KB
testcase_05 AC 6 ms
6,940 KB
testcase_06 AC 7 ms
6,940 KB
testcase_07 AC 7 ms
6,940 KB
testcase_08 AC 7 ms
6,944 KB
testcase_09 AC 7 ms
6,940 KB
testcase_10 AC 7 ms
6,940 KB
testcase_11 AC 241 ms
11,656 KB
testcase_12 AC 240 ms
11,732 KB
testcase_13 AC 315 ms
13,208 KB
testcase_14 AC 250 ms
11,976 KB
testcase_15 AC 287 ms
12,544 KB
testcase_16 AC 235 ms
11,540 KB
testcase_17 AC 288 ms
12,456 KB
testcase_18 AC 276 ms
12,380 KB
testcase_19 AC 298 ms
12,640 KB
testcase_20 AC 317 ms
13,076 KB
testcase_21 AC 274 ms
12,348 KB
testcase_22 AC 235 ms
11,412 KB
testcase_23 AC 244 ms
11,708 KB
testcase_24 AC 294 ms
12,676 KB
testcase_25 AC 310 ms
13,024 KB
testcase_26 AC 279 ms
12,556 KB
testcase_27 AC 256 ms
11,884 KB
testcase_28 AC 313 ms
13,104 KB
testcase_29 AC 310 ms
13,108 KB
testcase_30 AC 315 ms
13,104 KB
testcase_31 AC 314 ms
12,980 KB
testcase_32 AC 310 ms
13,108 KB
testcase_33 AC 316 ms
13,100 KB
testcase_34 AC 467 ms
13,620 KB
testcase_35 AC 347 ms
13,612 KB
testcase_36 AC 296 ms
13,488 KB
testcase_37 AC 328 ms
13,616 KB
testcase_38 AC 302 ms
13,528 KB
testcase_39 AC 287 ms
13,232 KB
testcase_40 AC 290 ms
13,468 KB
testcase_41 AC 315 ms
13,384 KB
testcase_42 AC 323 ms
13,480 KB
testcase_43 AC 254 ms
13,672 KB
testcase_44 AC 252 ms
13,476 KB
testcase_45 AC 243 ms
13,296 KB
testcase_46 AC 336 ms
12,728 KB
testcase_47 AC 357 ms
12,712 KB
testcase_48 AC 352 ms
13,164 KB
testcase_49 AC 343 ms
13,016 KB
testcase_50 AC 340 ms
13,124 KB
testcase_51 AC 495 ms
12,644 KB
testcase_52 AC 496 ms
12,644 KB
testcase_53 AC 494 ms
12,772 KB
testcase_54 AC 2 ms
6,944 KB
testcase_55 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
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;
	rep(i, n)cin >> p[i];
	int res=divseg();
	reverse(p, p + n);
	rep(i,400) {
		seg[i].clear();
		segmax[i] = 0;
	}
	res += divseg();
	cout << res << endl;
}
0