답안 #25746

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25746 2017-06-24T04:14:07 Z 도토리(#1084) 즐거운 채소 기르기 (JOI14_growing) C++14
100 / 100
193 ms 28484 KB
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int bit[530000];
void update(int p, int v) {
	for (; p <= IT_MAX; p += p & (-p)) bit[p] += v;
}
int getsum(int p) {
	int rv = 0;
	for (; p; p -= p & (-p)) rv += bit[p];
	return rv;
}

int in[300050];
vector <int> Vp[300050];
vector <int> Vx;

ll u[300050];
ll sum[300050];
int main() {
	int N, i, j;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", &in[i]);
		Vx.push_back(in[i]);
	}
	sort(all(Vx));
	Vx.erase(unique(all(Vx)), Vx.end());
	for (i = 1; i <= N; i++) {
		int p = lower_bound(all(Vx), in[i]) - Vx.begin();
		Vp[p].push_back(i);
	}

	ll ans = 0;
	for (i = 1; i <= N; i++) update(i, 1);
	for (i = 0; i < Vx.size(); i++) {
		int X = Vp[i].size();
		vector <int> Vu;
		for (j = 0; j < X; j++) u[j + 1] = getsum(Vp[i][j]);

		int N2 = getsum(N);
		for (j = 1; j <= X; j++) sum[j] = sum[j - 1] + u[j];

		ll mn = LL_INF;
		for (j = 0; j <= X; j++) {
			ll v = sum[j] - (ll)j * (j + 1) / 2;
			v += (ll)(X - j) * (2 * N2 - X + j + 1) / 2;
			v -= sum[X] - sum[j];
			mn = min(mn, v);
		}
		ans += mn;

		for (auto it : Vp[i]) update(it, -1);
	}
	return !printf("%lld\n", ans);
}

Compilation message

growing.cpp:23:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable:4996)  
 ^
growing.cpp:24:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/STACK:336777216")  
 ^
growing.cpp: In function 'int main()':
growing.cpp:85:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i = 0; i < Vx.size(); i++) {
                ^
growing.cpp:71:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
                 ^
growing.cpp:73:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &in[i]);
                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16984 KB Output is correct
2 Correct 3 ms 16984 KB Output is correct
3 Correct 3 ms 16984 KB Output is correct
4 Correct 0 ms 16984 KB Output is correct
5 Correct 3 ms 16984 KB Output is correct
6 Correct 0 ms 16984 KB Output is correct
7 Correct 3 ms 16984 KB Output is correct
8 Correct 0 ms 16984 KB Output is correct
9 Correct 0 ms 16984 KB Output is correct
10 Correct 0 ms 16984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 16984 KB Output is correct
2 Correct 0 ms 16984 KB Output is correct
3 Correct 0 ms 16984 KB Output is correct
4 Correct 0 ms 16984 KB Output is correct
5 Correct 3 ms 16984 KB Output is correct
6 Correct 0 ms 16984 KB Output is correct
7 Correct 0 ms 16984 KB Output is correct
8 Correct 0 ms 16984 KB Output is correct
9 Correct 3 ms 16984 KB Output is correct
10 Correct 6 ms 16984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16984 KB Output is correct
2 Correct 0 ms 17116 KB Output is correct
3 Correct 6 ms 17116 KB Output is correct
4 Correct 0 ms 17116 KB Output is correct
5 Correct 6 ms 17124 KB Output is correct
6 Correct 3 ms 17124 KB Output is correct
7 Correct 6 ms 17124 KB Output is correct
8 Correct 6 ms 17124 KB Output is correct
9 Correct 3 ms 17124 KB Output is correct
10 Correct 0 ms 17124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 17716 KB Output is correct
2 Correct 93 ms 20612 KB Output is correct
3 Correct 126 ms 22200 KB Output is correct
4 Correct 186 ms 23600 KB Output is correct
5 Correct 73 ms 24292 KB Output is correct
6 Correct 49 ms 20612 KB Output is correct
7 Correct 73 ms 21224 KB Output is correct
8 Correct 166 ms 28484 KB Output is correct
9 Correct 176 ms 24724 KB Output is correct
10 Correct 193 ms 28484 KB Output is correct