QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#561653 | #1363. Bitonic Ordering | Tenshi | WA | 0ms | 6912kb | C++20 | 1.2kb | 2024-09-13 05:07:57 | 2024-09-13 05:07:57 |
Judging History
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'