# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
59982 | 2018-07-23T11:55:03 Z | baekjoon | 공장 (KOI13_factory) | C++14 | 426 ms | 8436 KB |
#include <cstdio> #include <vector> #include <algorithm> using namespace std; int l; void update(vector<int> &a, int i, int diff) { while (i <= l) { a[i] += diff; i += (i & -i); } } int sum(vector<int> &a, int i) { int ans = 0; while (i > 0) { ans += a[i]; i -= (i & -i); } return ans; } int sum(vector<int> &a, int l, int r) { if (l > r) return 0; return sum(a, r) - sum(a, l-1); } int d[1000001]; int main() { int n; scanf("%d",&n); vector<int> a(n); for (int i=0; i<n; i++) { scanf("%d",&a[i]); } for (int i=0; i<n; i++) { int num; scanf("%d",&num); d[num] = i+1; } long long ans = 0; vector<int> tree(n+1); l = n; for (int i=0; i<n; i++) { ans += (long long)sum(tree, d[a[i]]+1, n); update(tree, d[a[i]], 1); } printf("%lld\n",ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 356 KB | Output is correct |
3 | Correct | 3 ms | 688 KB | Output is correct |
4 | Correct | 3 ms | 1532 KB | Output is correct |
5 | Correct | 4 ms | 2044 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3104 KB | Output is correct |
2 | Correct | 9 ms | 4412 KB | Output is correct |
3 | Correct | 13 ms | 4540 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 4668 KB | Output is correct |
2 | Correct | 42 ms | 4796 KB | Output is correct |
3 | Correct | 70 ms | 4924 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 71 ms | 5180 KB | Output is correct |
2 | Correct | 129 ms | 5692 KB | Output is correct |
3 | Correct | 136 ms | 5948 KB | Output is correct |
4 | Correct | 223 ms | 6972 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 301 ms | 7620 KB | Output is correct |
2 | Correct | 324 ms | 8412 KB | Output is correct |
3 | Correct | 400 ms | 8412 KB | Output is correct |
4 | Correct | 347 ms | 8412 KB | Output is correct |
5 | Correct | 389 ms | 8432 KB | Output is correct |
6 | Correct | 426 ms | 8436 KB | Output is correct |