이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
vector<int>arr(n);
for (int i = 0;i<n;++i){
cin>>arr[i];
}
auto merge = [&](int left,int mid,int right){
int ans = 0;
int i = left,j = mid + 1,k = 0;
vector<int>temp(right - left + 1);
while(i<=mid && j<=right){
if (arr[i] <= arr[j] + 2){
temp[k++] = arr[i++];
}
else{
ans+= mid - i + 1;
temp[k++] = arr[j++];
}
}
while(i<=mid){
temp[k++] = arr[i++];
}
while(j<=right){
temp[k++] = arr[j++];
}
int p = left;
while(left<=right){
arr[left] = temp[left - p];
left++;
}
return ans;
};
function<int(int left,int right)>merge_sort = [&](int left,int right){
if (left>=right)return 0;
int ans = 0;
int mid = (left + right)>>1;
ans+=merge_sort(left,mid);
ans+=merge_sort(mid + 1,right);
ans+=merge(left,mid,right);
return ans;
};
cout<<merge_sort(0,n - 1)<<'\n';
return 0;
}
| # | 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... |