답안 #875444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
875444 2023-11-19T17:33:38 Z imarn Vudu (COCI15_vudu) C++14
140 / 140
160 ms 21124 KB
#include<bits/stdc++.h>
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second
#define vi vector<int>
#define vpii vector<pii>
#define ll long long
using namespace std;
const int N=1e6+5;
ll a[N]{0};
ll cnt=0;
void dac(int l,int r){
    if(l>=r)return;
    int m=(l+r)>>1;
    dac(l,m);dac(m+1,r);
    int sz1=m-l+1,sz2=r-m;
    ll le[sz1],re[sz2];
    for(int i=0;i<sz1;i++)le[i]=a[i+l];
    for(int i=0;i<sz2;i++)re[i]=a[m+1+i];
    int li=0,ri=0,mi=l;
    while(li<sz1&&ri<sz2){
        if(le[li]<=re[ri])cnt+=sz2-ri,a[mi++]=le[li++];
        else a[mi++]=re[ri++];
    }while(li<sz1)a[mi++]=le[li++];
    while(ri<sz2)a[mi++]=re[ri++];
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int n;cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    ll p;cin>>p;
    for(int i=1;i<=n;i++)a[i]+=a[i-1]-p;
    dac(0,n);cout<<cnt;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 156 ms 20412 KB Output is correct
5 Correct 99 ms 11816 KB Output is correct
6 Correct 139 ms 18280 KB Output is correct
7 Correct 140 ms 18808 KB Output is correct
8 Correct 120 ms 16724 KB Output is correct
9 Correct 160 ms 21124 KB Output is correct
10 Correct 136 ms 18264 KB Output is correct