QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#844678 | #9922. Mah-jong | Zawos | TL | 1596ms | 6072kb | C++23 | 3.5kb | 2025-01-06 09:52:55 | 2025-01-06 09:52:56 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
using namespace __gnu_pbds;
using ll=long long;
using ld=long double;
using vi=vector<int>;
template<class T> using oset =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update> ;
//上
const int N = 100005;
int a[N];
int b[9][N];
int p[9];
int p1[9];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
vector<vector<int>> el;
vector<vector<int>> req;
for(int i = 0; i < 3*3*3*3*3*3*3*3;i++){
int x = i;
vector<int> M(8);
vector<int> A;
for(int j = 1; j <= 8; j++){
M[j-1] = x%3;
x /= 3;
}
A = M;
for(int j = 1; j <= 6; j++){
int r = (M[j-1]%3+3)%3;
M[j-1] -= r;
M[j]-=r;
M[j+1]-=r;
}
if((M[6]%3+3)%3 == (M[7]%3+3)%3 &&
(M[5]%3+3)%3 == (M[7]%3+3)%3 ){
req.push_back(M);
el.push_back(A);
}
}
int t;
cin >> t;
while(t--){
vector<vector<int>> c(3*3*3*3*3*3*3*3+1);
int n;
cin >> n;
FOR(i,0,n) cin >> a[i];
for(int i = 1; i <=8;i++) p[i] = 0;
for(int i = 1; i <= 8;i++){
for(int j = 0; j < n; j++){
if(a[j] == i) b[i][p[i]++] = j;
}
}
vector<int> count(9);
for(int i = 0; i < n; i++){
count[a[i]]++;
if(count[a[i]]>=3) count[a[i]]-=3;
int x = 0;
int y = 1;
for(int j = 1; j <= 8; j++){
x += count[j]*y;
y*=3;
}
c[x].push_back(i);
}
ll ans = 0;
for(int i = 0; i < el.size();i++){
vector<int> aux = el[i];
bool ok = true;
for(int j = 1; j <= 8; j++) p1[j] = 0;
for(int j = 0; j < 8; j++){
if(req[i][j] < 0){
if(-req[i][j] <= p[j+1]){
p1[j+1] = -req[i][j]-1;
}else ok = false;
}else p1[j+1] = -1;
}
if(!ok) continue;
ll mx = 0;
for(int j = 1; j <= 8; j++) mx = max(mx,(ll)b[j][p1[j]]);
for(int j = 0; j < n; j++){
int ky = 0;
int y = 1;
for(int k = 0; k < 8; k++){
ky += y*aux[k];
y*=3;
}
if(c[ky].size() > 0){
int lo = 0;
int hi = (int)c[ky].size()-1;
ll fn = hi;
while(lo <= hi){
int mid=(lo+hi)>>1;
if(c[ky][mid] >= mx){
hi = mid -1;
fn = mid;
}else lo = mid +1;
}
if(c[ky][fn] >= mx) ans += (ll)c[ky].size()-fn;
}
if(p1[a[j]] != -1){
p1[a[j]]++;
if(p1[a[j]] == p[a[j]]) break;
}
mx = max({mx,(ll)b[a[j]][p1[a[j]]],(ll)j+1});
aux[a[j]-1]++;
if(aux[a[j]-1] == 3) aux[a[j]-1] = 0;
// if(i == 1) cout <<j<<" "<<ans<<'\n';
}
}
cout << ans <<'\n';
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 6040kb
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: 0
Accepted
time: 1596ms
memory: 6072kb
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:
51699 61486 5146 1960 241675 6274 11224 46170 435241 1219228 17198 139542 299436 960439 217729 1174 87401 141087 69813 1 78895 0 39510 16757 86551 0 100302 161956 3 512157 58619 196941 26116 61635 28879 11511 2061 4394 74620 907389 172780 23952 524 87857 1305332 1413 11784 156368 11746 23217 25189 9...
result:
ok 100 numbers
Test #3:
score: -100
Time Limit Exceeded
input:
1 100000 7 6 3 7 1 2 5 2 4 5 3 2 6 2 2 2 5 6 5 8 6 2 1 8 2 2 1 1 4 8 2 6 4 1 8 6 6 7 8 4 4 5 4 7 8 6 2 3 3 7 5 7 1 1 3 5 2 8 5 6 3 6 2 3 3 8 4 5 7 8 1 5 6 1 3 4 5 7 1 5 4 4 4 6 6 4 2 3 5 2 7 3 5 8 7 1 5 4 5 4 1 5 8 7 2 2 8 2 4 3 5 7 6 6 1 6 6 3 1 1 3 1 7 8 1 7 3 7 8 3 6 3 5 7 5 1 8 7 4 7 5 4 8 1 3 4...
output:
555222305