Submission #140672

# Submission time Handle Problem Language Result Execution time Memory
140672 2019-08-04T11:56:46 Z khrbuddy03 공장 (KOI13_factory) C++14
20 / 20
555 ms 28780 KB
#include <bits/stdc++.h>

using namespace std;

using lint = long long;

const int siz = 5e5 + 9;

struct seg {
	lint tree[siz * 4];
	seg() {
		fill(&tree[0], &tree[siz * 4], 0LL);
	}
	lint query(int left, int right, int node, int low, int high) {
		if (right < low || high < left) return 0LL;
		if (left <= low && high <= right) return tree[node] * 1LL;
		int mid = (low + high) / 2;
		return query(left, right, node * 2, low, mid) * 1LL + query(left, right, node * 2 + 1, mid + 1, high) * 1LL;
	}
	lint update(int idx, int val, int node, int low, int high) {
		if (idx < low || high < idx) return tree[node] * 1LL;
		if (low == high) return tree[node] = val * 1LL;
		int mid = (low + high) / 2;
		return tree[node] = update(idx, val, node * 2, low, mid) * 1LL + update(idx, val, node * 2 + 1, mid + 1, high) * 1LL;
	}
} seg;

int A[(int)1e6 + 9], B[siz];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int N; cin >> N;
	for (int i = 0; i < N; i++) {
		int NUM; cin >> NUM;
		A[NUM] = i;
	}
	for (int i = 0; i < N; i++) cin >> B[i];
	lint ANS = 0;
	for (int i = 0; i < N; i++) {
		seg.update(A[B[i]], 1, 1, 0, N - 1);
		ANS += seg.query(A[B[i]] + 1, N - 1, 1, 0, N - 1) * 1LL;
	}
	cout << ANS << '\n';
}

# Verdict Execution time Memory Grader output
1 Correct 15 ms 16120 KB Output is correct
2 Correct 14 ms 15992 KB Output is correct
3 Correct 15 ms 16248 KB Output is correct
4 Correct 16 ms 17144 KB Output is correct
5 Correct 16 ms 17528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 18680 KB Output is correct
2 Correct 20 ms 19960 KB Output is correct
3 Correct 24 ms 20088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 20600 KB Output is correct
2 Correct 53 ms 20828 KB Output is correct
3 Correct 71 ms 21112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 21728 KB Output is correct
2 Correct 152 ms 22776 KB Output is correct
3 Correct 186 ms 23320 KB Output is correct
4 Correct 280 ms 25336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 380 ms 26900 KB Output is correct
2 Correct 341 ms 28656 KB Output is correct
3 Correct 341 ms 28780 KB Output is correct
4 Correct 473 ms 28676 KB Output is correct
5 Correct 555 ms 28720 KB Output is correct
6 Correct 521 ms 28664 KB Output is correct