QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#153294#6873. King's RuinsczcML 0ms0kbC++142.5kb2023-08-29 21:01:492023-08-29 21:01:49

Judging History

你现在查看的是最新测评结果

  • [2023-08-29 21:01:49]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2023-08-29 21:01:49]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=50005;
struct date{
    int b[5],val,id;
}a[maxn];
inline bool operator == (date x,date y){
    return x.b[0]==y.b[0] && x.b[1]==y.b[1] && x.b[2]==y.b[2] && x.b[3]==y.b[3] && x.b[4]==y.b[4];
}
inline bool operator <= (date x,date y){
    return x.b[0]<=y.b[0] && x.b[1]<=y.b[1] && x.b[2]<=y.b[2] && x.b[3]<=y.b[3] && x.b[4]<=y.b[4];
}
int czc;
inline bool cmp(date x,date y){
    return x.b[czc]>y.b[czc];
}
inline bool cmp2(date x,date y){
    return x.id<y.id;
}
int MX[maxn/16+5][1<<16],f[maxn];
int pre[maxn][maxn/16+5];
int can[maxn/16+5];
inline void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=0;j<5;j++)
            cin>>a[i].b[j];
        cin>>a[i].val;
        a[i].id=i;
    }
    int block=16,mx=(n-1)/block+1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=mx;j++){
            int l=(j-1)*block+1,r=min(j*block,n);
            pre[i][j]=(1<<(r-l+1))-1;
        }
    }
    for(int k=0;k<5;k++){
        czc=k;
        sort(a+1,a+n+1,cmp);
        for(int j=1;j<=mx;j++){
            int l=(j-1)*block+1,r=min(j*block,n);
            can[j]=(1<<(r-l+1))-1;
        }

        for(int i=1,j=1;i<=n;i=j){
            while(a[j]==a[i]){
                for(int k=1;k<=mx;k++){
                    pre[j][k]&=can[k];
                }
                j++;
            }
            j=i;
            while(a[j]==a[i]){
                for(int k=1;k<=mx;k++){
                    int l=(k-1)*block+1,r=min(k*block,n);
                    if(l<=a[j].id && a[j].id<=r){
                        int s=(( 1<<(a[j].id-l) )-1) | ( ~ ( (1<<(a[j].id-l+1)-1) ) );
                        can[k]&=s;
                    }
                }
                j++;
            }
        }

    }
    sort(a+1,a+n+1,cmp2);
    for(int i=1;i<=mx;i++){
        int l=(i-1)*block+1,r=min(i*block,n);
        for(int j=l;j<=r;j++){
            f[j]=a[j].val;
            for(int k=l;k<j;k++)
                if(a[k]<=a[j]) f[j]=max(f[j],f[k]+a[j].val);
            for(int k=1;k<i;k++)
                f[j]=max(f[j],MX[k][pre[j][k]]);
            cout<<f[j]<<endl;
        }
        if(i==n) continue;
        MX[i][0]=0;
        for(int s=1;s<(1<<block);s++)
            MX[i][s]=max(MX[i][s^(s&-s)],f[l+__builtin_ctz(s)]);
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int T;
    cin>>T;
    while(T--){
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Memory Limit Exceeded

input:

5
50000
29954 49457 38367 14274 40054 329
30630 36548 13832 4639 22667 5831
30320 36380 15092 40037 34720 1641
14924 15618 6335 10644 6739 3669
12197 42170 43527 35301 9465 7322
14180 40399 20609 10068 44940 3818
6559 16341 18973 46831 15552 7395
14667 37690 12809 49774 22576 7592
11896 6627 17112 3...

output:


result: