Submission #1518315


Source Code Expand

#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>
using namespace std;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define per0(i,n) for(register int i=(n)-1;i>=0;--i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &a,const T &b){return a<b?a:b;}
template<typename T> il T qmax(const T &a,const T &b){return a>b?a:b;}
template<typename T> il void getmin(T &a,const T &b){if(a>b) a=b;}
template<typename T> il void getmax(T &a,const T &b){if(a<b) a=b;}
il void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;
const int N=1e5+7;

int a[N],b[N],na,nb,n; 

int main(){
	scanf("%d",&n);
	rep(i,1,n){
		int v;
		scanf("%d",&v);
		if(i&1) a[++na]=v;
		else b[++nb]=v; 
	} 
	sort(a+1,a+na+1);
	sort(b+1,b+nb+1);
	ll ans=0;
	int pos=0;
	rep(i,1,nb){
		while(pos<na&&a[pos+1]<b[i]) ++pos;
		ans+=abs(i-pos);
	} 
	int pos=0;
	rep(i,1,na){
		while(pos<nb&&b[pos+1]<a[i]) ++pos;
		ans+=abs(i-1-pos);
	}
	printf("%lld\n",ans); 
	return 0;
}

Submission Info

Submission Time
Task C - BBuBBBlesort!
User zyding
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1908 Byte
Status CE

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:73:6: error: redeclaration of ‘int pos’
  int pos=0;
      ^
./Main.cpp:68:6: note: ‘int pos’ previously declared here
  int pos=0;
      ^
./Main.cpp:58:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
./Main.cpp:61:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&v);
                 ^