제출 #1330737

#제출 시각아이디문제언어결과실행 시간메모리
1330737tegshzayaArranging Shoes (IOI19_shoes)C++20
0 / 100
1 ms344 KiB
#include "shoes.h"
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
using namespace std;
ll t[800005];
void build(ll node,ll l,ll r,ll L,ll val){
	if(L>r||L<l) return;
	if (l==r) {t[node]=val;return;}
	ll mid=(l+r)/2;
	build(node*2,l,mid,L,val);
	build(node*2+1,mid+1,r,L,val);
	t[node]=t[node*2+1]+t[node*2];
}
ll query(ll node,ll l,ll r,ll L,ll R){
	if(R<l||L>r) return 0;
	if (l>=L&&r<=R) {return t[node];}
	ll mid=(l+r)/2;
	ll y=query(node*2,l,mid,L,R);
	ll x=query(node*2+1,mid+1,r,L,R);
	return(x+y);
}
bool bo[200005];
ll count_swaps(vector<int> s) {ll n=s.size();
	ll ans=0;
	vector<pair<ll,ll> > v;
	for (int i=0; i<n; i++)
	{build(1,1,n,i+1,1);
	v.pb({s[i],i+1});
	}
	sort(v.begin(),v.end());
	for(int i=0; i<n; i++) {
		if(bo[i]) {
			continue;
		}
		ll x=s[i]*-1;
		pair<ll,ll> p= {x,i};
		ll o=lower_bound(v.begin(),v.end(),p)-v.begin();
		ll k=query(1,1,n,(i+1)*2,v[o].ss-1);
		build(1,1,n,o+1,0);
		bo[v[o].ss-1]=1;
		v[o].ss=-1;
		sort(v.begin(),v.end());
		if(x<0) {
			k++;
		}
		ans+=k;
	}
	cout<<ans;
}

컴파일 시 표준 에러 (stderr) 메시지

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:52:1: warning: no return statement in function returning non-void [-Wreturn-type]
   52 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...