# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
59994 | 2018-07-23T11:58:16 Z | baekjoon | 공장 (KOI13_factory) | C++14 | 398 ms | 8468 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 692 KB | Output is correct |
4 | Correct | 3 ms | 1540 KB | Output is correct |
5 | Correct | 5 ms | 2100 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3028 KB | Output is correct |
2 | Correct | 7 ms | 4436 KB | Output is correct |
3 | Correct | 11 ms | 4440 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 4692 KB | Output is correct |
2 | Correct | 50 ms | 4972 KB | Output is correct |
3 | Correct | 53 ms | 5168 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 63 ms | 5356 KB | Output is correct |
2 | Correct | 108 ms | 5768 KB | Output is correct |
3 | Correct | 179 ms | 5996 KB | Output is correct |
4 | Correct | 234 ms | 7052 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 271 ms | 7728 KB | Output is correct |
2 | Correct | 377 ms | 8468 KB | Output is correct |
3 | Correct | 358 ms | 8468 KB | Output is correct |
4 | Correct | 352 ms | 8468 KB | Output is correct |
5 | Correct | 398 ms | 8468 KB | Output is correct |
6 | Correct | 347 ms | 8468 KB | Output is correct |