이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <bits/stdc++.h>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
#define pll vector<pair<ll,ll>>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
template<class S,class T>
bool chmin(S &a,const T &b) {
return a>b?(a=b)==b:false;
}
template<class S,class T>
bool chmax(S &a,const T &b) {
return a<b?(a=b)==b:false;
}
ll count_swaps(vector<int> S) {
vll s;
for(auto i : S)s.pb(i);
ll i,j,n=s.sz;
vector<deque<ll>> v(2*n+1);
ordered_set st;
for(i=0;i<n;i++){
st.ins(i);
if(s[i]>0) s[i]+=n/2;
else s[i]=abs(s[i]);
v[s[i]].pb(i);
}
ll ans=0;
while(st.sz){
ll x=*st.begin(),y;
st.erase(st.begin());
v[s[x]].pof;
if(s[x]<=n/2){
y=v[s[x]+n/2][0];
v[s[x]+n/2].pof;
}else{
y=v[s[x]-n/2][0];
v[s[x]-n/2].pof;
ans++;
}
ans+=st.order_of_key(y);
st.erase(st.find_by_order(st.order_of_key(y)));
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:39:10: warning: unused variable 'j' [-Wunused-variable]
39 | ll i,j,n=s.sz;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |