Submission #25744

# Submission time Handle Problem Language Result Execution time Memory
25744 2017-06-24T04:11:50 Z 김현수(#1080) 즐거운 채소 기르기 (JOI14_growing) C++11
0 / 100
29 ms 15360 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;

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(auto &T : v) {
		ll A = T.Y;
		ans += min(seg.get(1, A-1), seg.get(A+1, n));
		seg.upd(A, 0);
	}
	printf("%lld\n", ans);
}

Compilation message

growing.cpp: In function 'int main()':
growing.cpp:36:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&n);
                  ^
growing.cpp:38:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&a[i]);
                      ^
# Verdict Execution time Memory 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 Incorrect 0 ms 13740 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13740 KB Output is correct
2 Incorrect 0 ms 13740 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13740 KB Output is correct
2 Incorrect 0 ms 13880 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 15360 KB Output isn't correct
2 Halted 0 ms 0 KB -