Submission #59974

# Submission time Handle Problem Language Result Execution time Memory
59974 2018-07-23T11:52:48 Z baekjoon 공장 (KOI13_factory) C++14
20 / 20
407 ms 60164 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 376 KB Output is correct
3 Correct 4 ms 704 KB Output is correct
4 Correct 3 ms 1540 KB Output is correct
5 Correct 5 ms 2028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2980 KB Output is correct
2 Correct 8 ms 4592 KB Output is correct
3 Correct 11 ms 4768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 5388 KB Output is correct
2 Correct 34 ms 6176 KB Output is correct
3 Correct 59 ms 7492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 8956 KB Output is correct
2 Correct 127 ms 11496 KB Output is correct
3 Correct 178 ms 14524 KB Output is correct
4 Correct 205 ms 19436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 286 ms 25620 KB Output is correct
2 Correct 355 ms 33184 KB Output is correct
3 Correct 371 ms 39928 KB Output is correct
4 Correct 345 ms 46672 KB Output is correct
5 Correct 407 ms 53416 KB Output is correct
6 Correct 397 ms 60164 KB Output is correct