# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
59993 | 2018-07-23T11:58:01 Z | baekjoon | 공장 (KOI13_factory) | C++14 | 500 ms | 8428 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 | 324 KB | Output is correct |
2 | Correct | 2 ms | 380 KB | Output is correct |
3 | Correct | 2 ms | 624 KB | Output is correct |
4 | Correct | 3 ms | 1472 KB | Output is correct |
5 | Correct | 4 ms | 2032 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 2928 KB | Output is correct |
2 | Correct | 7 ms | 4412 KB | Output is correct |
3 | Correct | 9 ms | 4412 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 4668 KB | Output is correct |
2 | Correct | 37 ms | 4844 KB | Output is correct |
3 | Correct | 55 ms | 5228 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 65 ms | 5228 KB | Output is correct |
2 | Correct | 130 ms | 5808 KB | Output is correct |
3 | Correct | 140 ms | 6024 KB | Output is correct |
4 | Correct | 218 ms | 6972 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 314 ms | 7672 KB | Output is correct |
2 | Correct | 296 ms | 8428 KB | Output is correct |
3 | Correct | 323 ms | 8428 KB | Output is correct |
4 | Correct | 365 ms | 8428 KB | Output is correct |
5 | Correct | 413 ms | 8428 KB | Output is correct |
6 | Correct | 500 ms | 8428 KB | Output is correct |