QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#561653#1363. Bitonic OrderingTenshiWA 0ms6912kbC++201.2kb2024-09-13 05:07:572024-09-13 05:07:57

Judging History

你现在查看的是最新测评结果

  • [2024-09-13 05:07:57]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:6912kb
  • [2024-09-13 05:07:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
 
#define debug(x) cerr << #x << ": " << (x) << endl
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define dwn(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define all(x) (x).begin(), (x).end()
 
#define x first
#define y second
using pii = pair<int, int>;
using ll = long long;
 
inline void read(int &x){
    int s=0; x=1;
    char ch=getchar();
    while(ch<'0' || ch>'9') {if(ch=='-')x=-1;ch=getchar();}
    while(ch>='0' && ch<='9') s=(s<<3)+(s<<1)+ch-'0',ch=getchar();
    x*=s;
}

const int N=3e5+5;

int n;
int w[N];
vector<int> d;

int find(int x){
	return lower_bound(all(d), x)-begin(d)+1;
}

ll f[N], g[N];

int tr[N];
int lowbit(int x){
	return x&-x;
}

void add(int x){
	for(; x; x-=lowbit(x)) tr[x]++;
}

int query(int x){
	int res=0;
	for(; x<N; x+=lowbit(x)) res+=tr[x];
	return res;
}

signed main(){
	cin>>n;
	rep(i, 1, n) read(w[i]), d.pb(w[i]);
	sort(all(d));
	
	rep(i, 1, n) w[i]=find(w[i]);
	
	rep(i, 1, n){
		f[i]=f[i-1]+query(w[i]);
		add(w[i]);	
	}
	memset(tr, 0, sizeof tr);
	dwn(i, n, 1){
		g[i]=g[i+1]+query(w[i]);
		add(w[i]);
	}
	
	ll res=1e18;
	rep(i, 0, n) res=min(res, f[i]+g[i+1]);
	cout<<res<<endl;
	
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 6912kb

input:

13
39
40
32
100
13
16
15
28
27
26
25
24
23

output:

15

result:

wrong answer 1st lines differ - expected: '14', found: '15'