QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#142392 | #1363. Bitonic Ordering | Anwar_Gehad_Maghraby# | WA | 1ms | 7616kb | C++23 | 1.6kb | 2023-08-19 01:24:51 | 2023-08-19 01:24:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int T[1 << 20];
void update(int x ,int id=0 , int tl= 0 , int tr = N-1)
{
if(tl == tr)
{
T[id]++ ;
return ;
}
int md= (tl + tr) / 2;
if(x <= md )update(x , 2*id + 1 ,tl , md) ;
else update(x , 2*id +2 ,md +1 ,tr ) ;
T[id] = T[2*id + 1] + T[2*id + 2] ;
}
int get(int l , int r , int id= 0 , int tl= 0 , int tr= N-1)
{
if(l > tr || tl > r) return 0 ;
if(l <= tl && tr <= r) return T[id] ;
int md= (tl + tr) / 2;
return get(l ,r, 2*id + 1, tl , md) + get(l ,r, 2*id + 2, md+1 , tr) ;
}
int main() {
cin.tie(0);cin.sync_with_stdio(0);
cout.tie(0);cout.sync_with_stdio(0);
int n ;
cin >> n;
int a[n] ;
vector<int> all ;
for (int i = 0; i < n; ++i) {
cin >> a[i] ;
all.push_back(a[i]) ;
}
sort(all.begin() , all.end() ) ;
for (int i = 0; i < n; ++i) {
a[i] = lower_bound(all.begin() , all.end() , a[i]) -all.begin() ;
}
long long L[n] , R[n] ;
for(int i= 0 ; i < n ;i++)
{
L[i] = get( a[i] + 1 , N-1) ;
if(i) L[i] += L[i-1] ;
update(a[i]) ;
}
memset(T , 0 ,sizeof T) ;
for(int i= n-1 ; i >=0 ;i--)
{
R[i] = get( a[i] +1 , N-1 ) ;
if(i < n-1)R[i] += R[i+1] ;
update(a[i]) ;
}
long long ans = min( L[n-1] , R[0] ) ;
for(int i =0 ; i < n-1 ; i++)
{
ans = min(ans , L[i] + R[i+1] ) ;
}
cout << ans ;
}
/*
* 4 8 10 1 2 6 9
* 0 0 0 0 1 2 3 --> toMax[i]
*
*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7616kb
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'