結果

問題 No.610 区間賞(Section Award)
ユーザー FF256grhyFF256grhy
提出日時 2017-12-10 00:20:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 3,417 bytes
コンパイル時間 2,814 ms
コンパイル使用メモリ 169,496 KB
実行使用メモリ 6,216 KB
最終ジャッジ日時 2023-08-20 05:39:27
合計ジャッジ時間 6,654 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 16 ms
4,384 KB
testcase_20 AC 71 ms
5,880 KB
testcase_21 AC 10 ms
4,384 KB
testcase_22 AC 46 ms
4,832 KB
testcase_23 AC 7 ms
4,380 KB
testcase_24 AC 18 ms
4,384 KB
testcase_25 AC 5 ms
4,380 KB
testcase_26 AC 33 ms
4,672 KB
testcase_27 AC 69 ms
5,924 KB
testcase_28 AC 61 ms
5,708 KB
testcase_29 AC 44 ms
4,764 KB
testcase_30 AC 57 ms
5,628 KB
testcase_31 AC 30 ms
4,432 KB
testcase_32 AC 66 ms
5,716 KB
testcase_33 AC 10 ms
4,380 KB
testcase_34 AC 72 ms
5,876 KB
testcase_35 AC 33 ms
4,572 KB
testcase_36 AC 66 ms
5,884 KB
testcase_37 AC 55 ms
5,584 KB
testcase_38 AC 15 ms
4,380 KB
testcase_39 AC 70 ms
6,024 KB
testcase_40 AC 68 ms
6,036 KB
testcase_41 AC 69 ms
6,020 KB
testcase_42 AC 69 ms
5,900 KB
testcase_43 AC 70 ms
5,964 KB
testcase_44 AC 69 ms
5,928 KB
testcase_45 AC 81 ms
6,216 KB
testcase_46 AC 82 ms
6,212 KB
testcase_47 AC 57 ms
5,620 KB
testcase_48 AC 54 ms
5,576 KB
testcase_49 AC 58 ms
5,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

template<typename T> class SegTree {
private:
	T * a = NULL;
	int M, S;
	T (*F)(T, T);
	T I;

public:
	// [0, size) が使用可能になる、func が演算、id は単位元
	void init(int size, T (*func)(T, T), T id) {
		assert(size > 0);
		M = size;
		F = func;
		I = id;
		S = 1;
		while(S < size) { S *= 2; }
		delete[] a;
		a = new T[S * 2];
		inc(i, S * 2) { a[i] = I; }
	}
	
	// 参照(値を変更した後は calc() を呼ぶこと)
	T & operator[](int p) {
		assert(inID(p, 0, M));
		p += S;
		return a[p];
	}
	
	// テーブルの再計算
	void calc() {
		decID(i, 1, S) {
			a[i] = F(a[i * 2], a[i * 2 + 1]);
		}
	}
	
	// a[p] を v に変更し再計算
	void update(int p, T v) {
		assert(inID(p, 0, M));
		p += S;
		a[p] = v;
		while(p != 1) {
			p /= 2;
			a[p] = F(a[p * 2], a[p * 2 + 1]);
		}
	}
	
	// [l, r) に f を適用した結果を返す
	T range(int l, int r) {
		assert(inII(l, 0, M));
		assert(inII(r, 0, M));
		// if(l > r) { return F(range(l, M), range(0, r)); }
		assert(l <= r);
		l += S;
		r += S;
		
		T v = I, w = I;
		while(l < r) {
			if(l + 1 == r) { v = F(v, a[l]); break; }
			
			if(l % 2 == 1) { v = F(v, a[l]); }
			if(r % 2 == 1) { w = F(a[r - 1], w); }
			
			l = (l + 1) / 2;
			r = r / 2;
		}
		
		return F(v, w);
	}
};

template<typename T> T  MIN(T x, T y) { return min(x, y); }
template<typename T> T  MAX(T x, T y) { return max(x, y); }

// ---- ---- ---- ----

int n, a[100000], b[100000], ia[100000], ib[100000];

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i]; a[i]--; }
	inc(i, n) { cin >> b[i]; b[i]--; }
	
	inc(i, n) { ia[a[i]] = i; }
	inc(i, n) { ib[b[i]] = i; }
	
	SegTree<int> st;
	st.init(n, MAX, -1);
	
	inc(i, n) { st[ib[a[i]]] = i; }
	st.calc();
	
	vector<int> ans;
	inc(i, n) {
		if(st.range(0, ib[a[i]]) < i) { ans.PB(a[i] + 1); }
	}
	sort(ALL(ans));
	
	inc(i, ans.size()) { cout << ans[i] << "\n"; }
	
	return 0;
}
0