이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "shoes.h"
using namespace std;
typedef long long ll;
struct segtree{
vector<int> tree;
int init(int l,int r,int n=1){
if (l==r)
return tree[n]=1;
int m=(l+r)>>1;
return tree[n]=init(l,m,n<<1)+init(m+1,r,n<<1|1);
}
segtree(int n){
tree.resize(1<<(int)ceil(log2(n))+1);
init(1,n);
}
int update(int x,int v,int l,int r,int n=1){
if (r<x||x<l)
return tree[n];
if (l==r)
return tree[n]+=v;
int m=(l+r)>>1;
return tree[n]=update(x,v,l,m,n<<1)+update(x,v,m+1,r,n<<1|1);
}
int query(int lx,int rx,int l,int r,int n=1){
if (r<lx||rx<l||lx>rx)
return 0;
if (lx<=l&&r<=rx)
return tree[n];
int m=(l+r)>>1;
return query(lx,rx,l,m,n<<1)+query(lx,rx,m+1,r,n<<1|1);
}
};
int N;
int S[200001],Idx[200001];
bool Used[200001];
queue<int> A[100001];
int my_abs(int x){
if (x<0)
return -x;
return x;
}
ll count_swaps(vector<int> s){
ll ans=0;
N=(int)s.size();
segtree *ST=new segtree(N);
for (int i=1; i<=N; i++)
S[i]=s[i-1];
for (int i=1; i<=N; i++){
int x=my_abs(S[i]);
if (!A[x].empty()&&S[A[x].front()]+S[i]==0){
Idx[A[x].front()]=i;
A[x].pop();
}
else
A[x].push(i);
}
for (int i=1; i<=N; i++){
if (!ST->query(i,i,1,N))
continue;
ans+=ST->query(i+1,Idx[i]-1,1,N);
if (S[i]>S[Idx[i]])
ans++;
ST->update(i,-1,1,N);
ST->update(Idx[i],-1,1,N);
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In constructor 'segtree::segtree(int)':
shoes.cpp:14:42: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
14 | tree.resize(1<<(int)ceil(log2(n))+1);
| ~~~~~~~~~~~~~~~~~~^~
# | 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... |