이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vii;
typedef pair<int,int> pii;
#define pb push_back
#define F first
#define S second
map<int,set<int>>s;
ll sz=1;
struct segtree{
vii node;
void init(ll x){
sz=1;
while(sz<x)
sz*=2;
node.clear();
node.resize(2*sz);
}
void update(ll i,ll x=0,ll lx=0,ll rx=sz){
if(rx-lx==1){
node[x]++;
return;
}
int mid=((lx+rx)>>1);
if(i<mid)
update(i,x*2+1,lx,mid);
else
update(i,x*2+2,mid,rx);
node[x]=node[x*2+1]+node[x*2+2];
}
int query(ll l,ll x=0,ll lx=0,ll rx=0){
if(lx>=l)
return node[x];
if(rx<=l)
return 0;
int mid=((lx+rx)>>1);
return query(l,x*2+1,lx,mid)+query(l,x*2+2,mid,rx);
}
}seg;
bool vis[300010];
ll count_swaps(vector<int>a) {
s.clear();
seg.init(a.size());
for(int i=0;i<a.size();i++)
s[a[i]].insert(i),vis[i]=0;
ll ans=0;
for(int i=0;i<a.size();i++){
if(vis[i])
continue;
auto it=s[-a[i]].upper_bound(i);
assert(it!=s[-a[i]].end());
ll ind=*it+seg.query(*it);
ll ii=i+seg.query(i);
vis[*it]=vis[i]=1;
seg.update(*it);
s[-a[i]].erase(it);
ans+=ind-ii-1;
if(a[i]>0)
ans++;
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:46:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for(int i=0;i<a.size();i++)
| ~^~~~~~~~~
shoes.cpp:49:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int i=0;i<a.size();i++){
| ~^~~~~~~~~
# | 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... |