이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;
const int lim=2e5+100;
struct{
int tree[lim];
void update(int p,int val){
p++;
while(p<lim){
tree[p]+=val;
p+=p&-p;
}
}
int query(int p){
p++;
int ans=0;
while(p){
ans+=tree[p];
p-=p&-p;
}
return ans;
}
int query(int l,int r){
if(r<l)return 0;
return query(r)-query(l-1);
}
}fw;
long long count_swaps(std::vector<int> s) {
int ans=0;
int n=s.size();
int p1[n]{},p2[n]{};
vector<int>left[n],right[n];
for(int i=0;i<n;i++){
if(s[i]<0){
if(p1[-s[i]]<right[-s[i]].size()){
int ind=right[-s[i]][p1[-s[i]]];
p1[-s[i]]++;
int k=fw.query(ind+1,i);
ans+=k+i-ind;
fw.update(i+1,-1);
fw.update(ind,1);
}else{
left[-s[i]].push_back(i);
}
}else{
if(p2[s[i]]<left[s[i]].size()){
int ind=left[s[i]][p2[s[i]]];
p2[s[i]]++;
int k=fw.query(ind+1,i);
ans+=k+i-ind-1;
fw.update(i+1,-1);
fw.update(ind+1,1);
}else{
right[s[i]].push_back(i);
}
}
//cerr<<ans<<"\n";
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:39:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | if(p1[-s[i]]<right[-s[i]].size()){
| ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
shoes.cpp:50:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | if(p2[s[i]]<left[s[i]].size()){
| ~~~~~~~~^~~~~~~~~~~~~~~~~~
# | 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... |