QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#885936#9922. Mah-jongshanganzeTL 58ms12348kbC++231.8kb2025-02-06 19:40:442025-02-06 19:40:54

Judging History

This is the latest submission verdict.

  • [2025-02-06 19:40:54]
  • Judged
  • Verdict: TL
  • Time: 58ms
  • Memory: 12348kb
  • [2025-02-06 19:40:44]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N],s[N][10],t[10],h[N][20],z[10],e[10],n;
int sum[N];
long long ans;
int cnt,Pow[10],p;
vector<int>f[N],Ask[N];
void dfs(int i){
	if(i==7){
		cnt++;
		for(int q=1;q<=6;q++){h[cnt][q]+=z[q];h[cnt][q+1]+=z[q];h[cnt][q+2]+=z[q];}
		return ;
	}
	z[i]=0;dfs(i+1);
	z[i]=1;dfs(i+1);
	z[i]=2;dfs(i+1);
}
inline int read(){
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-48;ch=getchar();}
	return x*f;
}
bool v[N];
int main(){
	Pow[0]=1;for(int q=1;q<=8;q++)Pow[q]=Pow[q-1]*3;
	int T;T=read();
	dfs(1);
	while(T--){
		ans=0;n=read();
		for(int q=1;q<=n;++q)a[q]=read();
		for(int id=1;id<=cnt;++id){
			for(int q=0;q<=6561;++q){
				sum[q]=0;
				f[q].clear();f[q].push_back(0);	
			}
			for(int q=1;q<=8;q++)t[q]=e[q]=0;
			int l=0,o=0,opt=0;
			for(int q=1;q<=8;q++)if(h[id][q]==0)opt++;
			for(int r=1;r<=n;++r){
				for(int j=1;j<=8;j++)s[r][j]=s[r-1][j];
				s[r][a[r]]++;if(s[r][a[r]]==h[id][a[r]])opt++;
				o=o-t[a[r]]*Pow[8-a[r]];
				t[a[r]]=s[r][a[r]]%3;
				o=o+t[a[r]]*Pow[8-a[r]];
				e[a[r]]++;
				while(l<r&&opt==8){
					if(e[a[l+1]]>h[id][a[l+1]])e[a[l+1]]--,l++;
					else break;
				}
				if(opt==8){
					int k=0;for(int i=1;i<=8;i++)k=k*3+(s[r][i]-h[id][i])%3;
					int j=f[k][upper_bound(f[k].begin(),f[k].end(),l)-f[k].begin()-1];
					Ask[j].push_back(k);
				}
				f[o].push_back(r);v[o]=1;
			}
			for(int j=0;j<=8;j++)t[j]=0;
			o=0;int kk=0;
			for(int j=0;j<=n;++j){
				if(j!=0)o-=t[a[j]]*Pow[8-a[j]];
				t[a[j]]=(t[a[j]]+1)%3;
				if(j!=0)o+=t[a[j]]*Pow[8-a[j]];
				++sum[o];
				for(int k:Ask[j])ans+=sum[k];
				Ask[j].clear();
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 58ms
memory: 12348kb

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: