#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |