제출 #1286868

#제출 시각아이디문제언어결과실행 시간메모리
1286868kerem즐거운 채소 기르기 (JOI14_growing)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;
//~ #define int int64_t
#define pb push_back
#define emb emplace_back
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define sp << " " <<
#define N 300000
#define inf (int)1e9
typedef pair<int,int> ii;
typedef tuple<int,int,int> iii;

int n,ft[N+5];
void update(int x){
	for(int i=x;i<=n;i+=-i&i)
		ft[i]++;
}
int get(int x){
	int ans=0;
	for(int i=x;i>0;i-=-i&i)
		ans+=ft[i];
	return ans;
}
void solve(){
	cin >> n;
	int a[n];
	vector<pii> zip;
	for(int i=0;i<n;i++){
		cin >> a[i];
		zip.emb(a[i],i);
	}
	sort(all(zip));
	int say=1;
	for(int i=0;i<n;i++){
		if(i && zip[i].fr!=zip[i-1].fr)
			say++;
		a[zip[i].sc]=say;
	}
	int l[n],r[n];
	memset(ft,0,sizeof(ft));
	for(int i=0;i<n;i++){
		l[i]=(i!=0?l[i-1]:0);
		l[i]+=i-get(a[i]);
		update(a[i]);
	}
	memset(ft,0,sizeof(ft));
	for(int i=n-1;i>=0;i--){
		r[i]=(i!=n-1?r[i+1]:0);
		r[i]+=(n-i-1)-get(a[i]);
		update(a[i]);
	}
	int64_t ans=n*n;
	for(int i=1;i<n;i++)
		ans=min(ans,(int64_t)l[i-1]+r[i]);
	cout << ans << endl;
}
int32_t main(){
	//~ freopen("hopscotch.in","r",stdin);
	//~ freopen("hopscotch.out","w",stdout);
	
	cout << fixed << setprecision(0);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	int test=1;
	//~ cin >> test;
	while(test--) solve();
}


컴파일 시 표준 에러 (stderr) 메시지

growing.cpp: In function 'void solve()':
growing.cpp:29:16: error: 'pii' was not declared in this scope; did you mean 'iii'?
   29 |         vector<pii> zip;
      |                ^~~
      |                iii
growing.cpp:29:19: error: template argument 1 is invalid
   29 |         vector<pii> zip;
      |                   ^
growing.cpp:29:19: error: template argument 2 is invalid
growing.cpp:5:13: error: request for member 'emplace_back' in 'zip', which is of non-class type 'int'
    5 | #define emb emplace_back
      |             ^~~~~~~~~~~~
growing.cpp:32:21: note: in expansion of macro 'emb'
   32 |                 zip.emb(a[i],i);
      |                     ^~~
growing.cpp:8:18: error: request for member 'begin' in 'zip', which is of non-class type 'int'
    8 | #define all(x) x.begin(),x.end()
      |                  ^~~~~
growing.cpp:34:14: note: in expansion of macro 'all'
   34 |         sort(all(zip));
      |              ^~~
growing.cpp:8:28: error: request for member 'end' in 'zip', which is of non-class type 'int'
    8 | #define all(x) x.begin(),x.end()
      |                            ^~~
growing.cpp:34:14: note: in expansion of macro 'all'
   34 |         sort(all(zip));
      |              ^~~
growing.cpp:37:28: error: invalid types 'int[int]' for array subscript
   37 |                 if(i && zip[i].fr!=zip[i-1].fr)
      |                            ^
growing.cpp:37:39: error: invalid types 'int[int]' for array subscript
   37 |                 if(i && zip[i].fr!=zip[i-1].fr)
      |                                       ^
growing.cpp:39:22: error: invalid types 'int[int]' for array subscript
   39 |                 a[zip[i].sc]=say;
      |                      ^