QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#142363 | #1363. Bitonic Ordering | A3bat_team_f_Masr# | WA | 1ms | 13796kb | C++14 | 2.0kb | 2023-08-19 00:22:01 | 2023-08-19 00:22:04 |
Judging History
answer
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long ll;
#define IO ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define all(x) x.begin(), (x).end()
#define el '\n'
#define sz(v) (int)(v).size()
#define TC \
int tc; \
cin >> tc; \
while (tc--)
#define pi acos(-1.0)
#define oo LONG_LONG_MAX
#define yes cout << "YES" << el
#define no cout << "NO" << el
#define N (int)3e5 + 4
bool isPrime(ll n)
{
if (n == 1 || n == 0)
return false;
if (n % 2 == 0 && n != 2)
return false;
if (n == 2)
return true;
for (ll i = 3; i <= sqrt(n); i += 2)
{
if (n % i == 0)
return false;
}
return true;
}
bool vis[N];
int dx[] = {0, 0, 1, -1, 1, -1, -1, 1};
int dy[] = {-1, 1, 0, 0, 1, -1, 1, -1};
vector<int> adj[N];
int n,a[N],idx[N],tree[4*N];
void update(int me,int l,int r,int idx,int val){
if(l==r){
tree[me]=val;
return;
}
int m=(l+r)>>1;
if(idx<=m) update(2*me,l,m,idx,val);
else update(2*me+1,m+1,r,idx,val);
tree[me]=tree[2*me]+tree[2*me+1];
}
int sum(int me,int l,int r,int st,int en){
if(l>en || r<st) return 0;
if(l>=st && r<=en) return tree[me];
int m=(l+r)>>1;
return sum(2*me,l,m,st,en)+sum(2*me+1,m+1,r,st,en);
}
void solve()
{
map<int,int>rev,mp;
cin>>n;
int mx=0;
for(int i=1;i<=n;i++){
cin>>a[i];
mp[a[i]]=i;
}
int id=0;
for(auto x:mp) rev[x.first]=++id;
for(int i=1;i<=n;i++){
a[i]=rev[a[i]];
idx[a[i]]=i;
if(a[i]>mx) mx=a[i];
}
ll ans=0;
for(int i=1;i<idx[mx];i++){
ans+=sum(1,1,mx,a[i],mx);
update(1,1,mx,a[i],1);
}
for(int i=1;i<=mx;i++) update(1,1,mx,i,0);
for(int i=idx[mx]+1;i<=n;i++){
ans+=sum(1,1,mx,1,a[i]);
update(1,1,mx,a[i],1);
}
cout<<ans;
}
int main()
{
// IO
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 13796kb
input:
13 39 40 32 100 13 16 15 28 27 26 25 24 23
output:
22
result:
wrong answer 1st lines differ - expected: '14', found: '22'