結果

問題 No.610 区間賞(Section Award)
ユーザー Lepton_sLepton_s
提出日時 2017-12-10 12:42:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 2,494 bytes
コンパイル時間 1,303 ms
コンパイル使用メモリ 97,056 KB
実行使用メモリ 12,188 KB
最終ジャッジ日時 2023-08-20 09:51:27
合計ジャッジ時間 4,850 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,512 KB
testcase_01 AC 3 ms
7,564 KB
testcase_02 AC 2 ms
7,528 KB
testcase_03 AC 2 ms
7,480 KB
testcase_04 AC 3 ms
7,624 KB
testcase_05 AC 3 ms
7,544 KB
testcase_06 AC 3 ms
7,540 KB
testcase_07 AC 3 ms
7,548 KB
testcase_08 AC 3 ms
7,580 KB
testcase_09 AC 3 ms
7,576 KB
testcase_10 AC 3 ms
7,624 KB
testcase_11 AC 3 ms
7,588 KB
testcase_12 AC 3 ms
7,560 KB
testcase_13 AC 3 ms
7,544 KB
testcase_14 AC 4 ms
7,580 KB
testcase_15 AC 3 ms
7,500 KB
testcase_16 AC 3 ms
7,612 KB
testcase_17 AC 2 ms
7,648 KB
testcase_18 AC 3 ms
7,640 KB
testcase_19 AC 16 ms
8,148 KB
testcase_20 AC 75 ms
12,080 KB
testcase_21 AC 11 ms
7,884 KB
testcase_22 AC 46 ms
10,928 KB
testcase_23 AC 8 ms
7,872 KB
testcase_24 AC 18 ms
8,232 KB
testcase_25 AC 5 ms
7,684 KB
testcase_26 AC 33 ms
10,836 KB
testcase_27 AC 74 ms
12,088 KB
testcase_28 AC 66 ms
12,020 KB
testcase_29 AC 43 ms
10,828 KB
testcase_30 AC 60 ms
11,964 KB
testcase_31 AC 30 ms
10,820 KB
testcase_32 AC 69 ms
12,004 KB
testcase_33 AC 10 ms
7,828 KB
testcase_34 AC 74 ms
12,068 KB
testcase_35 AC 33 ms
10,816 KB
testcase_36 AC 72 ms
12,048 KB
testcase_37 AC 60 ms
11,980 KB
testcase_38 AC 16 ms
8,220 KB
testcase_39 AC 78 ms
12,060 KB
testcase_40 AC 77 ms
12,148 KB
testcase_41 AC 76 ms
12,188 KB
testcase_42 AC 78 ms
12,092 KB
testcase_43 AC 77 ms
12,056 KB
testcase_44 AC 59 ms
11,916 KB
testcase_45 AC 70 ms
11,976 KB
testcase_46 AC 71 ms
12,012 KB
testcase_47 AC 63 ms
11,928 KB
testcase_48 AC 58 ms
11,976 KB
testcase_49 AC 64 ms
12,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 200010
int a[N], b[N], c[N], c2[N];

ll data[2*N], datb[2*N], seg_n;
void init(int n){
	seg_n = 1;
	while(seg_n<n) seg_n<<=1;
	rep(i, 2*seg_n-1) data[i] = 0;
	rep(i, 2*seg_n-1) datb[i] = 0;
}

// v[a]+=x; v[a+1]+=x;...; v[b-1]+=x;
void add(int a, int b, ll x, int k, int l, int r){
	if(r <= a || b <= l) return;
	if(a <= l && r <= b){
		data[k] += x;
	} else {
		datb[k] += (min(b, r) - max(a, l))*x;
		add(a, b, x, k*2+1, l, (l+r)/2);
		add(a, b, x, k*2+2, (l+r)/2, r);
	}
}

// sum(v[a], v[a+1],..., v[b-1])
// to use: sum(a, b, 0, 0, seg_n);
ll sum(int a, int b, int k, int l, int r){
	if(r <= a || b <= l) return 0;
	if(a <= l && r <= b) return data[k]*(r-l) + datb[k];
	ll res = (min(b, r) - max(a, l))*data[k];
	res += sum(a, b, k*2+1, l, (l+r)/2) + sum(a, b, k*2+2, (l+r)/2, r);
	return res;
}


int main(){
	int n; scanf("%d", &n);
	rep(i, n) scanf("%d", a+i);
	rep(i, n) scanf("%d", b+i);
	rep(i, n) c[i] = a[i];
	rep(i, n) c2[a[i]] = i;
	//rep(i, n) a[i] = i;
	rep(i, n) b[i] = c2[b[i]];
	vector<int> res; res.reserve(n);
	init(n);
	rep(i, n){
		//cerr<<b[i]<<endl;
		if(sum(b[i], b[i]+1, 0, 0, seg_n)==0) res.push_back(c[b[i]]);
		//cerr<<b[i]<<" "<<sum(b[i], b[i]+1, 0, 0, seg_n)<<endl;
		add(0, b[i]+1, 1, 0, 0, seg_n);
		//cerr<<b[i]<<" "<<sum(b[i], b[i]+1, 0, 0, seg_n)<<endl;
	}
	sort(all(res));
	for(auto x: res) printf("%d\n", x);
		
	return 0;
}
0