# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
25778 | 2017-06-24T06:07:16 Z | khsoo01 | 즐거운 채소 기르기 (JOI14_growing) | C++11 | 233 ms | 30204 KB |
#include<bits/stdc++.h> #define X first #define Y second using namespace std; typedef long long ll; typedef pair<ll,ll> pll; const ll N = 300005, inf = 1e18; ll n, a[N], ans; vector<pll> v; struct segtree { ll val[4*N], lim; void init () { for(lim=1;lim<=n;lim<<=1); for(ll i=1;i<=n;i++) val[lim+i] = 1; for(ll i=lim;--i;) val[i] = val[2*i] + val[2*i+1]; } void upd (ll P, ll V) { P += lim; val[P] = V; P >>= 1; while(P) {val[P] = val[2*P] + val[2*P+1]; P >>= 1;} } ll get (ll S, ll E) { ll R = 0; S += lim; E += lim; while(S<=E) { if(S%2==1) R += val[S++]; if(E%2==0) R += val[E--]; S >>= 1; E >>= 1; } return R; } } seg; int main() { scanf("%lld",&n); for(ll i=1;i<=n;i++) { scanf("%lld",&a[i]); v.push_back({a[i], i}); } sort(v.begin(), v.end()); seg.init(); for(ll i=0;i<v.size();) { vector<ll> I, L, R; do { I.push_back(v[i].Y); seg.upd(v[i].Y, 0); i++; } while(i<v.size() && v[i].X == v[i-1].X); L.push_back(0); for(ll j=0;j<I.size();j++) { L.push_back(L.back() + seg.get(1, I[j])); } R.push_back(0); for(ll j=I.size();j--;) { R.push_back(R.back() + seg.get(I[j], n)); } ll C = inf; for(ll i=0;i<=I.size();i++) { C = min(C, L[i] + R[I.size()-i]); } ans += C; } printf("%lld\n", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 13740 KB | Output is correct |
2 | Correct | 0 ms | 13740 KB | Output is correct |
3 | Correct | 0 ms | 13740 KB | Output is correct |
4 | Correct | 0 ms | 13740 KB | Output is correct |
5 | Correct | 0 ms | 13740 KB | Output is correct |
6 | Correct | 0 ms | 13740 KB | Output is correct |
7 | Correct | 0 ms | 13740 KB | Output is correct |
8 | Correct | 0 ms | 13740 KB | Output is correct |
9 | Correct | 0 ms | 13740 KB | Output is correct |
10 | Correct | 0 ms | 13740 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 13740 KB | Output is correct |
2 | Correct | 0 ms | 13740 KB | Output is correct |
3 | Correct | 0 ms | 13740 KB | Output is correct |
4 | Correct | 0 ms | 13740 KB | Output is correct |
5 | Correct | 0 ms | 13740 KB | Output is correct |
6 | Correct | 0 ms | 13740 KB | Output is correct |
7 | Correct | 0 ms | 13740 KB | Output is correct |
8 | Correct | 0 ms | 13740 KB | Output is correct |
9 | Correct | 0 ms | 13740 KB | Output is correct |
10 | Correct | 0 ms | 13740 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 13740 KB | Output is correct |
2 | Correct | 0 ms | 13880 KB | Output is correct |
3 | Correct | 0 ms | 13880 KB | Output is correct |
4 | Correct | 0 ms | 13880 KB | Output is correct |
5 | Correct | 3 ms | 14012 KB | Output is correct |
6 | Correct | 3 ms | 14012 KB | Output is correct |
7 | Correct | 0 ms | 14140 KB | Output is correct |
8 | Correct | 3 ms | 14012 KB | Output is correct |
9 | Correct | 3 ms | 14012 KB | Output is correct |
10 | Correct | 3 ms | 14012 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 15360 KB | Output is correct |
2 | Correct | 96 ms | 16896 KB | Output is correct |
3 | Correct | 136 ms | 19968 KB | Output is correct |
4 | Correct | 193 ms | 19968 KB | Output is correct |
5 | Correct | 146 ms | 19968 KB | Output is correct |
6 | Correct | 76 ms | 16896 KB | Output is correct |
7 | Correct | 143 ms | 26112 KB | Output is correct |
8 | Correct | 223 ms | 26112 KB | Output is correct |
9 | Correct | 233 ms | 30204 KB | Output is correct |
10 | Correct | 226 ms | 26112 KB | Output is correct |