【卡过我玄关】这是不是C++暴力卡常的极限?

P1908 逆序对

_H17_ @ 2024-08-16 16:00:57

C++20

1~#10最大点75ms,#11~20 TLE

#include<bits/stdc++.h>
#define int unsigned
using namespace std;
constexpr int N=40001;
__inline char gc(){
    static char buf[400051],*p1=buf,*p2=buf;
    return(p1==p2&&(p2=(p1=buf)+fread(buf,1,400050,stdin),p1==p2)?EOF:*p1++);
}
__inline int read(int&x){
    char c;
    x=0;
    while('0'>(c=gc())||c>'9');
    while('0'<=c&&c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=gc();
    return x;
}
__inline void write(int k){
    static char buf[12],cnt=0,i=0,j;
    do{
        buf[cnt++]=(k%10)^48,k>>=1,k/=5;
    }while(k);
    j=cnt-1;
    if(i<j)[[likely]]
        buf[i]^=buf[j]^=buf[i]^=buf[j],++i,--j;
    else[[unlikely]]
        goto g;
    if(i<j)[[likely]]
        buf[i]^=buf[j]^=buf[i]^=buf[j],++i,--j;
    else[[unlikely]]
        goto g;
    if(i<j)[[likely]]
        buf[i]^=buf[j]^=buf[i]^=buf[j],++i,--j;
    else[[unlikely]]
        goto g;
    if(i<j)[[likely]]
        buf[i]^=buf[j]^=buf[i]^=buf[j],++i,--j;
    g:
    fwrite(buf,1,cnt,stdout);
    return;
}
signed main(){
    int n,a[N],cnt=0,i=0,j=0,cnt1=0,cnt2=0,cnt3=0,cnt4=0,cnt5=0,cnt6=0,cnt7=0;
    read(n);
    for(;i<n-7;i+=8)
        read(a[i]),read(a[i+1]),
        read(a[i+2]),read(a[i+3]),
        read(a[i+4]),read(a[i+5]),
        read(a[i+6]),read(a[i+7]);
    for(;i<n;++i)
        read(a[i]);
    for(i=1;i<n;++i){
        for(j=0;j+7<i;j+=8){
            if(a[j]>a[i])[[unlikely]]
                ++cnt;
            if(a[j+1]>a[i])[[unlikely]]
                ++cnt1;
            if(a[j+2]>a[i])[[unlikely]]
                ++cnt2;
            if(a[j+3]>a[i])[[unlikely]]
                ++cnt3;
            if(a[j+4]>a[i])[[unlikely]]
                ++cnt4;
            if(a[j+5]>a[i])[[unlikely]]
                ++cnt5;
            if(a[j+6]>a[i])[[unlikely]]
                ++cnt6;
            if(a[j+7]>a[i])[[unlikely]]
                ++cnt7;
        }
        for(;j<i;++j)
            if(a[j]>a[i])[[unlikely]]
                ++cnt;
    }
    write(cnt+cnt1+cnt2+cnt3+cnt4+cnt5+cnt6+cnt7);
    return 0;
}

必须打纯暴力


by _H17_ @ 2024-08-16 16:01:25

卡过我指#1~#10最大点比我小


by mayisang @ 2024-08-17 16:24:55

看不懂根本看不懂


by Kevin_BangNing @ 2024-08-19 10:27:12

这题不能写暴力


by Kevin_BangNing @ 2024-08-19 10:33:30

@Kevin_BangNing 但我也不知道怎么写


by qwqSW @ 2024-08-19 14:00:21

@Kevin_BangNing 暴力能拿50分已经相当可观了
真正打比赛还是大部分得指着暴力拿分


by qwqSW @ 2024-08-19 14:00:55

哥你真的 %%%


by Kevin_BangNing @ 2024-08-19 14:09:47

@qwqSW 哦


|