# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
25798 | 2017-06-24T07:34:50 Z | kdh9949 | 즐거운 채소 기르기 (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
# | 결과 | 실행 시간 | 메모리 | 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 |
# | 결과 | 실행 시간 | 메모리 | 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 |
# | 결과 | 실행 시간 | 메모리 | 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 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 5536 KB | Output is correct |
2 | Correct | 33 ms | 5536 KB | Output is correct |
3 | Correct | 49 ms | 5536 KB | Output is correct |
4 | Correct | 69 ms | 5536 KB | Output is correct |
5 | Correct | 43 ms | 5536 KB | Output is correct |
6 | Correct | 33 ms | 5536 KB | Output is correct |
7 | Correct | 49 ms | 5536 KB | Output is correct |
8 | Correct | 153 ms | 5536 KB | Output is correct |
9 | Correct | 89 ms | 5536 KB | Output is correct |
10 | Correct | 99 ms | 5536 KB | Output is correct |