Submission #140672

#TimeUsernameProblemLanguageResultExecution timeMemory
140672khrbuddy03공장 (KOI13_factory)C++14
20 / 20
555 ms28780 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...