이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
const long long maxn=400001,p=200000,N=(1<<(long long)log2(maxn)+1);
long long Tree[N*2+1],arr[maxn+1],l,r;
vector <long long> v[maxn];
bool left(long long i){
if(i-p>=0) return 0;
else return 1;
}
long long solve(long long l1,long long r1,long long i){
if(l1>r||r1<l) return 0;
if(l1>=l&&r1<=r) return Tree[i];
return solve(l1,(l1+r1)/2,i*2)+solve(((l1+r1)/2)+1,r1,i*2+1);
}
void update(long long i){
arr[i]=0;
i+=N;
Tree[i]=0;
i/=2;
while(i!=0){
Tree[i]=Tree[i*2]+Tree[i*2+1];
i/=2;
}
return;
}
long long count_swaps(vector<int> s){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n=s.size(),ans=0;
for(long long i=0;i<n;i++){
arr[i]=s[i];
Tree[i+N]=1;
arr[i]+=p;
}
for(long long i=n-1;i>=0;i--){
v[arr[i]].push_back(i);
}
for(long long i=N-1;i>=1;i--) Tree[i]=Tree[i*2]+Tree[i*2+1];
for(long long i=0;i<n;i++){
if(arr[i]==0) continue;
l=i+1;
long long inv=((arr[i]-p)*-1)+p;
v[arr[i]].pop_back();
if(left(arr[i])==1){
r=v[inv].back();
v[inv].pop_back();
ans+=solve(0,N-1,1)-1;
}
else{
r=v[inv].back();
v[inv].pop_back();
ans+=solve(0,N-1,1);
}
update(l-1);
update(r);
}
return ans;
}
// signed main()
// {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
// cout.tie(NULL);
// long long n;
// cin>>n;
// vector <int> s(n);
// for(long long i=0;i<n;i++) cin>>s[i];
// cout<<count_swaps(s);
// }
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp:11:65: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
11 | const long long maxn=400001,p=200000,N=(1<<(long long)log2(maxn)+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... |