답안 #59999

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
59999 2018-07-23T11:59:45 Z baekjoon 공장 (KOI13_factory) C++14
20 / 20
390 ms 8548 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

factory.cpp: In function 'int main()':
factory.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
factory.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
         ~~~~~^~~~~~~~~~~~
factory.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&num);
         ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 3 ms 536 KB Output is correct
4 Correct 3 ms 1504 KB Output is correct
5 Correct 4 ms 1996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2888 KB Output is correct
2 Correct 8 ms 4356 KB Output is correct
3 Correct 13 ms 4484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 4664 KB Output is correct
2 Correct 38 ms 4792 KB Output is correct
3 Correct 55 ms 4920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 5304 KB Output is correct
2 Correct 118 ms 5672 KB Output is correct
3 Correct 156 ms 5944 KB Output is correct
4 Correct 232 ms 6840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 329 ms 7688 KB Output is correct
2 Correct 390 ms 8472 KB Output is correct
3 Correct 323 ms 8500 KB Output is correct
4 Correct 327 ms 8500 KB Output is correct
5 Correct 323 ms 8500 KB Output is correct
6 Correct 362 ms 8548 KB Output is correct