提出 #74667062


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
typedef long long ll;
typedef pair<ll,ll> PII;
typedef array<ll,2> a2;
typedef array<ll,3> a3;
ll n,m,k;
int a[N];
ll L[N],R[N];
ll tr[N];

ll lowbit(ll x){
    return x&-x;
}

void add(int x,int c){
    for(int i=x;i<=n;i+=lowbit(i)) tr[i]+=c;
}

ll query(ll x){
    ll sum=0;
    for(int i=x;i>0;i-=lowbit(i)) sum+=tr[i];
    return sum;
}

void __(){
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>a[i];
    {
        int j=1;
        ll now=0;
        for(int i=1;i<=n;i++){
            ll val=query(n)-query(a[i]);
            add(a[i],1);
            now+=val;
            while(j<=i&&now>m){
                add(a[j],-1);
                now-=query(a[j]);
                j++;
            }
            L[i]=j;
        }
    }
    memset(tr,0,sizeof tr);
    {
        int j=1;
        ll now=0;
        for(int i=1;i<=n;i++){
            ll val=query(n)-query(a[i]);
            add(a[i],1);
            now+=val;
            while(j<=i&&now>=m){
                add(a[j],-1);
                now-=query(a[j]);
                j++;
            }
            R[i]=j;
        }
    }
    ll ans=0;
    for(int i=1;i<=n;i++) ans+=R[i]-L[i];
    cout<<ans<<endl;
}


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _=1;
    // cin>>_;
    while(_--){
        __();
    }
}

提出情報

提出日時
問題 F - Interval Inversion Count
ユーザ zhishengie
言語 C++23 (GCC 15.2.0)
得点 500
コード長 1433 Byte
結果 AC
実行時間 103 ms
メモリ 21380 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 3
AC × 55
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt, 01_random_53.txt, 01_random_54.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 7 ms 11412 KiB
00_sample_01.txt AC 4 ms 11544 KiB
00_sample_02.txt AC 4 ms 11580 KiB
01_random_03.txt AC 46 ms 17588 KiB
01_random_04.txt AC 43 ms 17752 KiB
01_random_05.txt AC 31 ms 15004 KiB
01_random_06.txt AC 25 ms 14748 KiB
01_random_07.txt AC 36 ms 16464 KiB
01_random_08.txt AC 26 ms 15236 KiB
01_random_09.txt AC 33 ms 15284 KiB
01_random_10.txt AC 97 ms 21084 KiB
01_random_11.txt AC 86 ms 21268 KiB
01_random_12.txt AC 97 ms 21308 KiB
01_random_13.txt AC 80 ms 21200 KiB
01_random_14.txt AC 73 ms 21128 KiB
01_random_15.txt AC 93 ms 21252 KiB
01_random_16.txt AC 98 ms 21276 KiB
01_random_17.txt AC 87 ms 21200 KiB
01_random_18.txt AC 71 ms 21268 KiB
01_random_19.txt AC 103 ms 21272 KiB
01_random_20.txt AC 66 ms 21208 KiB
01_random_21.txt AC 70 ms 21128 KiB
01_random_22.txt AC 72 ms 21212 KiB
01_random_23.txt AC 102 ms 21148 KiB
01_random_24.txt AC 41 ms 21380 KiB
01_random_25.txt AC 45 ms 21148 KiB
01_random_26.txt AC 47 ms 21268 KiB
01_random_27.txt AC 39 ms 21240 KiB
01_random_28.txt AC 44 ms 21212 KiB
01_random_29.txt AC 48 ms 21308 KiB
01_random_30.txt AC 41 ms 21268 KiB
01_random_31.txt AC 87 ms 21148 KiB
01_random_32.txt AC 87 ms 21220 KiB
01_random_33.txt AC 87 ms 21224 KiB
01_random_34.txt AC 87 ms 21380 KiB
01_random_35.txt AC 87 ms 21200 KiB
01_random_36.txt AC 4 ms 11540 KiB
01_random_37.txt AC 41 ms 21380 KiB
01_random_38.txt AC 44 ms 21208 KiB
01_random_39.txt AC 39 ms 21260 KiB
01_random_40.txt AC 45 ms 21268 KiB
01_random_41.txt AC 42 ms 21308 KiB
01_random_42.txt AC 39 ms 21380 KiB
01_random_43.txt AC 37 ms 21220 KiB
01_random_44.txt AC 41 ms 21240 KiB
01_random_45.txt AC 46 ms 21268 KiB
01_random_46.txt AC 45 ms 21268 KiB
01_random_47.txt AC 45 ms 21300 KiB
01_random_48.txt AC 46 ms 21300 KiB
01_random_49.txt AC 45 ms 21212 KiB
01_random_50.txt AC 40 ms 19608 KiB
01_random_51.txt AC 32 ms 19604 KiB
01_random_52.txt AC 38 ms 19152 KiB
01_random_53.txt AC 34 ms 19604 KiB
01_random_54.txt AC 43 ms 20060 KiB