# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
59975 | 2018-07-23T11:53:08 Z | baekjoon | 공장 (KOI13_factory) | C++14 | 359 ms | 8572 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 | 484 KB | Output is correct |
3 | Correct | 2 ms | 536 KB | Output is correct |
4 | Correct | 2 ms | 1460 KB | Output is correct |
5 | Correct | 5 ms | 2020 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 2968 KB | Output is correct |
2 | Correct | 8 ms | 4400 KB | Output is correct |
3 | Correct | 14 ms | 4560 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 4640 KB | Output is correct |
2 | Correct | 46 ms | 4812 KB | Output is correct |
3 | Correct | 59 ms | 5072 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 73 ms | 5228 KB | Output is correct |
2 | Correct | 117 ms | 5744 KB | Output is correct |
3 | Correct | 152 ms | 6124 KB | Output is correct |
4 | Correct | 231 ms | 6764 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 312 ms | 7532 KB | Output is correct |
2 | Correct | 356 ms | 8428 KB | Output is correct |
3 | Correct | 313 ms | 8444 KB | Output is correct |
4 | Correct | 324 ms | 8572 KB | Output is correct |
5 | Correct | 341 ms | 8572 KB | Output is correct |
6 | Correct | 359 ms | 8572 KB | Output is correct |