QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#841073#9922. Mah-jongrqoi031TL 8ms190084kbC++202.1kb2025-01-03 12:09:542025-01-03 12:09:55

Judging History

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

  • [2025-01-03 12:09:55]
  • 评测
  • 测评结果:TL
  • 用时:8ms
  • 内存:190084kb
  • [2025-01-03 12:09:54]
  • 提交

answer

#include<stdio.h>
#include<algorithm>
typedef long long ll;
constexpr int N{100000},L{8},C{729};
constexpr int del[3]{1,1,-2};
int cnt[C+5][L];
int ptr[C+5],vcc[C+5][L],val[C+5],ccc[C+5][(1<<(L<<1))+5];
void init() {
    int tot{0};
    for(int i=0;i!=1<<(L-2<<1);i++) {
        if([&]()->bool {
            for(int j=0;j!=L-2;j++) {
                if((i>>(j<<1)&3)>=3) {
                    return true;
                }
            }
            return false;
        }()) {
            continue;
        }
        ++tot;
        std::fill(cnt[tot],cnt[tot]+L,0);
        for(int j=0;j!=L-2;j++) {
            int c{i>>(j<<1)&3};
            cnt[tot][j]+=c;
            cnt[tot][j+1]+=c;
            cnt[tot][j+2]+=c;
        }
    }
    for(int i=1;i<=C;i++) {
        std::fill(ccc[i],ccc[i]+(1<<(L<<1)),0);
    }
}
int a[N+5],c[N+5][L],v[N+5];
void solve() {
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) {
        scanf("%d",a+i),--a[i];
    }
    ll ans{0};
    std::fill(c[0],c[0]+L,0);
    std::fill(ptr+1,ptr+C+1,0);
    for(int i=1;i<=C;i++) {
        val[i]=0;
        for(int j=0;j!=L;j++) {
            vcc[i][j]=(3-cnt[i][j]%3)%3;
            val[i]|=vcc[i][j]<<(j<<1);
        }
    }
    for(int i=1;i<=n;i++) {
        std::copy(c[i-1],c[i-1]+L,c[i]);
        v[i]=v[i-1]+(del[c[i][a[i]]++%3]<<(a[i]<<1));
        for(int j=1;j<=C;j++) {
            while(ptr[j]<i&&[&]()->bool {
                for(int p=0;p!=L;p++) {
                    if(c[i][p]-c[ptr[j]][p]<cnt[j][p]) {
                        return false;
                    }
                }
                return true;
            }()) {
                ++ccc[j][v[ptr[j]++]];
            }
            val[j]+=del[vcc[j][a[i]]++%3]<<(a[i]<<1);
            ans+=ccc[j][val[j]];
        }
    }
    for(int i=1;i<=C;i++) {
        for(int j=0;j<=n;j++) {
            ccc[i][v[j]]=0;
        }
    }
    printf("%lld\n",ans);
}
int main() {
    init();
    int t;
    scanf("%d",&t);
    while(t--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 190084kb

input:

5
4
1 1 1 1
6
1 2 3 1 2 3
7
6 5 8 7 6 3 2
8
1 2 1 2 1 2 1 3
9
2 2 4 4 1 1 1 3 3

output:

2
5
1
3
2

result:

ok 5 number(s): "2 5 1 3 2"

Test #2:

score: -100
Time Limit Exceeded

input:

100
992
8 1 8 1 2 3 6 6 1 3 1 8 7 7 4 7 7 1 6 6 4 8 3 7 3 5 1 4 4 7 5 7 5 7 4 3 7 5 2 8 7 1 6 3 6 2 4 3 2 3 1 6 3 1 3 2 6 6 7 4 6 1 1 4 6 4 7 7 8 5 6 4 1 5 4 8 2 4 4 2 1 3 5 7 6 8 3 7 6 6 5 6 4 2 5 4 3 7 3 5 5 3 3 2 7 8 2 7 2 4 4 3 4 1 1 3 5 5 4 6 3 3 3 2 6 1 2 6 4 8 8 6 6 8 7 3 1 1 8 8 7 2 5 6 3 5 ...

output:


result: