# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
59985 | 2018-07-23T11:55:40 Z | baekjoon | 공장 (KOI13_factory) | C++14 | 1000 ms | 22576 KB |
#include <cstdio> #include <vector> #include <algorithm> #include <map> using namespace std; int l; void update(vector<int> &tree, int i, int diff) { while (i <= l) { tree[i] += diff; i += (i & -i); } } int sum(vector<int> &tree, int i) { int ans = 0; while (i > 0) { ans += tree[i]; i -= (i & -i); } return ans; } int sum(vector<int> &tree, int l, int r) { if (l > r) return 0; return sum(tree, r) - sum(tree, l-1); } int main() { int n; scanf("%d",&n); vector<int> a(n); for (int i=0; i<n; i++) { scanf("%d",&a[i]); } map<int,int> position; for (int i=0; i<n; i++) { int num; scanf("%d",&num); position[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, position[a[i]]+1, n); update(tree, position[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 | 484 KB | Output is correct |
4 | Correct | 3 ms | 484 KB | Output is correct |
5 | Correct | 2 ms | 516 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 516 KB | Output is correct |
2 | Correct | 9 ms | 644 KB | Output is correct |
3 | Correct | 16 ms | 1156 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 51 ms | 2192 KB | Output is correct |
2 | Correct | 129 ms | 3392 KB | Output is correct |
3 | Correct | 182 ms | 4428 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 244 ms | 6124 KB | Output is correct |
2 | Correct | 427 ms | 9452 KB | Output is correct |
3 | Correct | 519 ms | 11500 KB | Output is correct |
4 | Correct | 987 ms | 17044 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1072 ms | 22576 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |