結果

問題 No.686 Uncertain LIS
ユーザー shadowYYHshadowYYH
提出日時 2023-12-08 16:54:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,656 bytes
コンパイル時間 2,233 ms
コンパイル使用メモリ 184,784 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-08 16:54:52
合計ジャッジ時間 7,007 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,676 KB
testcase_01 AC 3 ms
6,676 KB
testcase_02 AC 4 ms
6,676 KB
testcase_03 AC 9 ms
6,676 KB
testcase_04 AC 6 ms
6,676 KB
testcase_05 AC 11 ms
6,676 KB
testcase_06 AC 14 ms
6,676 KB
testcase_07 AC 4 ms
6,676 KB
testcase_08 AC 34 ms
6,676 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

char buf[(1<<21)+5],*p1,*p2;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)

inline int read() {
	int x = 0, f = 0; char ch = getchar();
	while (!isdigit(ch)) f |= (ch == '-'), ch = getchar();
	while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return f ? -x : x;
}

const int N = 1e5 + 100, unit = 320;

int m, s, b[N << 1];
deque<int> q[unit]; int add[unit];

int& pos(int x) { return q[b[x]][x % unit]; }
int val(int x) { return q[b[x]][x % unit] + add[b[x]]; }

signed main() {
	// freopen("a.in", "r", stdin);
	// freopen("a.out", "w", stdout);
	for (s = 0; s <= 1e5; s += unit) { 
		m = s / unit, q[m].assign(unit, 0);
		for (int i = s; i < s + unit; ++i) b[i] = m;
	}
	int T = read(); while (T--) {
		int l = read(), r = read();
		if (b[l] == b[r]) for (int i = r; i >= l; --i) pos(i) = pos(i - 1) + 1;
		else {	
			for (int i = r; i > b[r] * unit; --i) pos(i) = pos(i - 1) + 1; 
			pos(b[r] * unit) = val(b[r] * unit - 1) + 1 - add[b[r]];
			for (int i = b[r] - 1; i > b[l]; --i) {
				q[i].push_front(val(i * unit - 1) - add[i]);
				q[i].pop_back(), ++add[i];
			}
			for (int i = (b[l] + 1) * unit - 1; i > l; --i) pos(i) = pos(i - 1) + 1;
			pos(l) = val(l - 1) + 1 - add[b[l]];
		}
		for (int i = r + 1; i < (b[r] + 1) * unit; ++i) 
			if (val(i) < val(r)) pos(i) = val(r) - add[b[i]];	
		for (int i = b[r] + 1; i <= m; ++i) {
			if (val((i + 1) * unit - 1) < val(r)) { ++add[i]; continue; }
			for (int j = i * unit; j < (i + 1) * unit; ++j)
				if (val(j) < val(r)) pos(j) = val(r) - add[i];	
		}
	}
	cout << val((m + 1) * unit - 1);
	return 0;
}
0