QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#844647#9922. Mah-jongZawosWA 1291ms6276kbC++234.0kb2025-01-06 09:28:042025-01-06 09:28:06

Judging History

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

  • [2025-01-06 09:28:06]
  • 评测
  • 测评结果:WA
  • 用时:1291ms
  • 内存:6276kb
  • [2025-01-06 09:28:04]
  • 提交

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][100005];
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];
            // if(i == 1) cout <<ans<<'\n';
            bool ok = true;
            for(int j = 1; j <= 8; j++) p1[j] = 0;
            // if(i == 1){
                
            //     for(auto &u: req[i]) cout << u <<" ";
            //     cout <<'\n';
            //     for(auto &u: el[i]) cout << u <<" ";
            //     cout <<'\n';
            // }
            for(int j = 0; j < 8; j++){
                if(req[i][j]  < 0){
                    if(-req[i][j] <= p[j+1]){
                        p1[j+1] = b[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)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(i == 1) cout <<ky<<" ";
                // if(i == 0){
                //     cout <<ky<<" ";
                //     for(auto &u:c[ky]) cout << u <<'\n';
                // }
                if(c[ky].size() > 0){
                    int lo = 0;
                    int hi = (int)c[ky].size()-1;
                    int 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 += (int)c[ky].size()-fn;
                }
                if(p1[a[j]] != -1){
                    p1[a[j]]++;
                    if(p1[a[j]] == p[a[j]]) break;
                }
                mx = max({mx,(ll)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';
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1291ms
memory: 6276kb

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:

50266
61179
4099
970
245156
5366
5947
37222
433713
1224513
15157
140621
298674
959302
221305
677
73952
140903
64390
1
77133
0
36208
16398
83255
0
100605
164285
3
518043
57007
200002
22983
58621
22919
9229
1181
2289
66640
908125
175788
21540
290
88709
1314334
1433
5666
154363
10702
20713
19473
8274
3...

result:

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