結果

問題 No.284 門松と魔法(2)
ユーザー yosupotyosupot
提出日時 2015-09-23 12:27:53
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,146 bytes
コンパイル時間 1,888 ms
コンパイル使用メモリ 124,852 KB
実行使用メモリ 22,760 KB
最終ジャッジ日時 2023-09-26 14:35:38
合計ジャッジ時間 5,566 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
21,876 KB
testcase_01 AC 9 ms
21,828 KB
testcase_02 AC 8 ms
21,900 KB
testcase_03 WA -
testcase_04 AC 8 ms
21,824 KB
testcase_05 AC 9 ms
22,060 KB
testcase_06 WA -
testcase_07 AC 9 ms
21,972 KB
testcase_08 AC 9 ms
21,820 KB
testcase_09 AC 9 ms
21,776 KB
testcase_10 AC 9 ms
21,776 KB
testcase_11 AC 9 ms
21,820 KB
testcase_12 AC 9 ms
21,788 KB
testcase_13 AC 9 ms
21,792 KB
testcase_14 AC 9 ms
21,796 KB
testcase_15 AC 8 ms
21,804 KB
testcase_16 AC 10 ms
21,792 KB
testcase_17 AC 9 ms
21,824 KB
testcase_18 WA -
testcase_19 AC 9 ms
21,824 KB
testcase_20 AC 9 ms
21,876 KB
testcase_21 AC 9 ms
21,828 KB
testcase_22 AC 9 ms
21,772 KB
testcase_23 AC 28 ms
21,856 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 8 ms
21,768 KB
testcase_27 AC 9 ms
21,820 KB
testcase_28 AC 9 ms
21,836 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 129 ms
22,504 KB
testcase_32 AC 424 ms
22,528 KB
testcase_33 AC 183 ms
22,556 KB
testcase_34 AC 170 ms
22,476 KB
testcase_35 WA -
testcase_36 AC 9 ms
21,908 KB
testcase_37 AC 140 ms
22,620 KB
testcase_38 WA -
testcase_39 AC 11 ms
21,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
typedef long long ll;


/**
 * 遅延評価で書かれているStarry Sky Tree
 */
template <int S>
struct StarrySkyTree {
    typedef pair<int, int> D;
    static const int N = 1<<S;
    D seg[2*N][2], lz[2*N][2];
    int sz[2*N];
    StarrySkyTree() {
        for (int i = 2*N-1; i >= N; i--) {
            sz[i] = 1;
        }
        for (int i = N-1; i >= 1; i--) {
            sz[i] = sz[i*2]+sz[i*2+1];
        }
    }
    int base;
    void init(int b) {
    	base = b;
        for (int i = 1; i < 2*N; i++) {
        	seg[i][0] = seg[i][1] = D(0, base);
        }
    }

    void lzdata(int k, D x) {
    	if (x > seg[k][0]) {
    		swap(x, seg[k][0]);
    	}
    	if (x > seg[k][1]) {
    		swap(x, seg[k][1]);
    	}
    }
    void push(int k) {
        assert(1 <= k && k < N);
        if (seg[k][0].first >= 1) {
            lzdata(k*2, seg[k][0]);
            lzdata(k*2+1, seg[k][0]);
            seg[k][0] = D(0, base);
        }
        if (seg[k][1].first >= 1) {
            lzdata(k*2, seg[k][1]);
            lzdata(k*2+1, seg[k][1]);
            seg[k][1] = D(0, base);
        }
    }
    void update(int k) {
        assert(1 <= k && k < N);
    }

    pair<D, D> get(int k) {
        k += N;
        for (int i = S; i > 0; i--) {
            push(k>>i);
        }
        return make_pair(seg[k][0], seg[k][1]);
    }

    void set(int a, int b, D x, int k = 1) {
        if (sz[k] <= a || b <= 0) return;
        if (a <= 0 && sz[k] <= b) {
            lzdata(k, x);
            return;
        }
        push(k);
        set(a, b, x, k*2);
        set(a-sz[k]/2, b-sz[k]/2, x, k*2+1);
        update(k);
    }
};

const int MN = 100100;
int a[MN];

StarrySkyTree<17> st1, st2;

int main() {
	int n;
	cin >> n;
	vector<int> v;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		v.push_back(a[i]);
	}
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	for (int i = 0; i < n; i++) {
		a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin();
	}
	st1.init(-1); st2.init(n);
	int res = 0;
	for (int i = 0; i < n; i++) {
		//up
		auto x = st1.get(a[i]);
		{	
			auto y = x.first;
			y.first++;
			res = max(res, y.first);
			auto u = y.second; y.second = a[i];
			st2.set(0, u, y);
			st2.set(u+1, a[i], y);
		}
		{	
			auto y = x.second;
			y.first++;
			res = max(res, y.first);
			auto u = y.second; y.second = a[i];
			st2.set(0, u, y);
			st2.set(u+1, a[i], y);
		}
		x = st2.get(a[i]);
		{	
			auto y = x.first;
			y.first++;
			res = max(res, y.first);
			auto u = y.second; y.second = a[i];
			st1.set(a[i]+1, u, y);
			st1.set(u+1, n, y);
		}
		{	
			auto y = x.second;
			y.first++;
			res = max(res, y.first);
			auto u = y.second; y.second = a[i];
			st1.set(a[i]+1, u, y);
			st1.set(u+1, n, y);
		}
	}
	if (res <= 2) res = 0;
	cout << res << endl;
    return 0;
}
0