Submission #59978

# Submission time Handle Problem Language Result Execution time Memory
59978 2018-07-23T11:54:12 Z baekjoon 공장 (KOI13_factory) C++14
20 / 20
390 ms 8560 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);
         ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 552 KB Output is correct
4 Correct 3 ms 1448 KB Output is correct
5 Correct 4 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2976 KB Output is correct
2 Correct 13 ms 4428 KB Output is correct
3 Correct 12 ms 4556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 4820 KB Output is correct
2 Correct 43 ms 4844 KB Output is correct
3 Correct 58 ms 5064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 5300 KB Output is correct
2 Correct 140 ms 5800 KB Output is correct
3 Correct 151 ms 6072 KB Output is correct
4 Correct 219 ms 6764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 255 ms 7532 KB Output is correct
2 Correct 364 ms 8520 KB Output is correct
3 Correct 328 ms 8520 KB Output is correct
4 Correct 371 ms 8520 KB Output is correct
5 Correct 382 ms 8520 KB Output is correct
6 Correct 390 ms 8560 KB Output is correct