QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#847971#9922. Mah-jongfang_babyWA 2436ms3852kbC++234.8kb2025-01-08 14:13:012025-01-08 14:13:08

Judging History

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

  • [2025-01-08 14:13:08]
  • 评测
  • 测评结果:WA
  • 用时:2436ms
  • 内存:3852kb
  • [2025-01-08 14:13:01]
  • 提交

answer

/*
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@         @@@@@@@@@                  @@@@@@@@@         @@@@@@@@@
@@@@@@@@@         @@@@@@@@@                  @@@@@@@@@         @@@@@@@@@
@@@@@@@@@         @@@@@@@@@                  @@@@@@@@@         @@@@@@@@@
@@@@@@@@@         @@@@@@@@@                  @@@@@@@@@         @@@@@@@@@
@@@@@@@@@         @@@@@@@@@                  @@@@@@@@@         @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@         @@@@@@@@@                  @@@@@@@@@         @@@@@@@@@
@@@@@@@@@         @@@@@@@@@                  @@@@@@@@@         @@@@@@@@@
@@@@@@@@@         @@@@@@@@@                  @@@@@@@@@         @@@@@@@@@
@@@@@@@@@         @@@@@@@@@                  @@@@@@@@@         @@@@@@@@@
@@@@@@@@@         @@@@@@@@@                  @@@@@@@@@         @@@@@@@@@
@@@@@@@@@                  @@@@@@@@@@@@@@@@@@                  @@@@@@@@@
@@@@@@@@@                  @@@@@@@@@@@@@@@@@@                  @@@@@@@@@
@@@@@@@@@                  @@@@@@@@@@@@@@@@@@                  @@@@@@@@@
@@@@@@@@@                  @@@@@@@@@@@@@@@@@@                  @@@@@@@@@
@@@@@@@@@                  @@@@@@@@@@@@@@@@@@                  @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@                                                      @@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define maxn 200005
mt19937_64 rng {std::chrono::steady_clock::now().time_since_epoch().count()};
ll mod = 998244353;
ll MOD = 998244353;
//cout<<"panduan\n";
//auto dfs = [&](auto &self,int x,int f)->void{self(self,x,f);};




void solve(){
	
	int n = 0;
	cin>>n;
	vector<int>arr(n);
	vector<vector<int>>pre(n+1,vector<int>(8));
	vector<int>temp(729);
	for(int i = 0;i<n;i++){
		cin>>arr[i];
		arr[i]--;
		pre[i+1][arr[i]]++;
	}
	for(int i = 1;i<=n;i++){
		for(int j = 0;j<8;j++){
			pre[i][j]+=pre[i-1][j];
		}
	}
	int all[7] = {0};
	//all[0] = 1;
	ll ans = 0;
	for(int i = 0;i<729;i++){
	//int i = 1;	
		int num[8] = {0};
		vector<int>cnt(6561);
		for(int j = 0;j<6;j++){
			if(all[j]){
				num[j]+=all[j];
				num[j+1]+=all[j];
				num[j+2]+=all[j];
			}
		}
		int l = 0,r = 0;
		int numl[8] = {0},numr[8] = {0};
		cnt[0]++;

		for(int j = 0;j<n;j++){
			numr[arr[j]]++;
			r++;
			if(numr[arr[j]]>=3)numr[arr[j]] = 0;
			while(l<r-1){
				int ok = 1;
				for(int k = 0;k<8;k++){
					if(pre[r][k]-pre[l][k]<num[k]){
						ok = 0;
						break;
					}
				}	
				if(ok){
					numl[arr[l]]++;
					if(numl[arr[l]]==3)numl[arr[l]] = 0;
					l++;
					int haha = 0,te = 1;
					for(int k = 0;k<8;k++){
						haha+=te*numl[k];
						te*=3;
					}
					cnt[haha]++;
				}else{
					break;
				}
			}
			
			int haha = 0,te = 1;
			for(int k = 0;k<8;k++){
				haha+=te*((numr[k]-num[k]+6)%3);
				te*=3;
			}
			ans+=cnt[haha];
			//r++;
		}
		
		all[0]++;
		int dex = 0;
		while(dex<=5&&all[dex]>=3){
			all[dex++] = 0;
			all[dex]++;
		}
	}

	cout<<ans<<"\n";

}




int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int t = 1;
	cin>>t;
	while(t--){
		solve();
	}

	return 0;
}













详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3852kb

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
Wrong Answer
time: 2436ms
memory: 3764kb

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:

51703
61489
5147
1962
241677
6276
11226
46176
435247
1219231
17200
139545
299439
960442
217730
1178
87407
141089
69817
1
78897
0
39511
16759
86553
0
100305
161957
4
512159
58622
196943
26117
61642
28883
11512
2066
4396
74624
907393
172782
23956
527
87860
1305337
1415
11787
156374
11754
23220
25192
9...

result:

wrong answer 1st numbers differ - expected: '51699', found: '51703'