# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
25796 | 2017-06-24T07:32:27 Z | 김동현(#1079) | 즐거운 채소 기르기 (JOI14_growing) | C++14 | 153 ms | 5536 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct Dat{ int x, i; bool operator<(const Dat &oth) const { return x < oth.x; } }; int n; Dat a[300010]; ll ans; struct BIT{ int dat[300010]; void upd(int x, int v){ for(; x <= n; x += x & -x) dat[x] += v; } int get(int x){ int ret = 0; for(; x; x -= x & -x) ret += dat[x]; return ret; } int get(int s, int e){ return get(e) - get(s - 1); } } B; int main(){ scanf("%d", &n); for(int i = 1, x; i <= n; i++){ scanf("%d", &x); B.upd(i, 1); a[i] = {x, i}; } sort(a + 1, a + n + 1); for(int i = 1, j; i <= n; i = j){ for(j = i; j <= n && a[j].x == a[i].x; j++){ B.upd(a[j].i, -1); } for(int k = i; k < j; k++){ ans += min(B.get(1, a[k].i), B.get(a[k].i, n)); } } printf("%lld\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 5536 KB | Output is correct |
2 | Correct | 0 ms | 5536 KB | Output is correct |
3 | Correct | 0 ms | 5536 KB | Output is correct |
4 | Correct | 0 ms | 5536 KB | Output is correct |
5 | Correct | 0 ms | 5536 KB | Output is correct |
6 | Correct | 0 ms | 5536 KB | Output is correct |
7 | Correct | 0 ms | 5536 KB | Output is correct |
8 | Correct | 0 ms | 5536 KB | Output is correct |
9 | Correct | 0 ms | 5536 KB | Output is correct |
10 | Correct | 0 ms | 5536 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 5536 KB | Output is correct |
2 | Correct | 0 ms | 5536 KB | Output is correct |
3 | Correct | 0 ms | 5536 KB | Output is correct |
4 | Correct | 0 ms | 5536 KB | Output is correct |
5 | Correct | 0 ms | 5536 KB | Output is correct |
6 | Correct | 0 ms | 5536 KB | Output is correct |
7 | Correct | 0 ms | 5536 KB | Output is correct |
8 | Correct | 0 ms | 5536 KB | Output is correct |
9 | Correct | 0 ms | 5536 KB | Output is correct |
10 | Correct | 0 ms | 5536 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 5536 KB | Output is correct |
2 | Correct | 0 ms | 5536 KB | Output is correct |
3 | Correct | 0 ms | 5536 KB | Output is correct |
4 | Correct | 0 ms | 5536 KB | Output is correct |
5 | Correct | 0 ms | 5536 KB | Output is correct |
6 | Correct | 0 ms | 5536 KB | Output is correct |
7 | Correct | 0 ms | 5536 KB | Output is correct |
8 | Correct | 0 ms | 5536 KB | Output is correct |
9 | Correct | 0 ms | 5536 KB | Output is correct |
10 | Correct | 0 ms | 5536 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 5536 KB | Output is correct |
2 | Correct | 36 ms | 5536 KB | Output is correct |
3 | Correct | 63 ms | 5536 KB | Output is correct |
4 | Correct | 86 ms | 5536 KB | Output is correct |
5 | Correct | 69 ms | 5536 KB | Output is correct |
6 | Correct | 23 ms | 5536 KB | Output is correct |
7 | Correct | 73 ms | 5536 KB | Output is correct |
8 | Correct | 106 ms | 5536 KB | Output is correct |
9 | Correct | 126 ms | 5536 KB | Output is correct |
10 | Correct | 153 ms | 5536 KB | Output is correct |