QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#836654#9922. Mah-jongucup-team1134#TL 2713ms4688kbC++232.7kb2024-12-29 03:19:002024-12-29 03:19:04

Judging History

This is the latest submission verdict.

  • [2024-12-29 03:19:04]
  • Judged
  • Verdict: TL
  • Time: 2713ms
  • Memory: 4688kb
  • [2024-12-29 03:19:00]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define vvii vector<vector<pair<int,int>>>
#define vvll vector<vector<pair<ll,ll>>>
#define vst vector<string>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define mkunique(x) sort(all(x));(x).erase(unique(all(x)),(x).end())
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=15<<26;

vvi chi;
vi S(8);

void DFS(int u){
    if(u==6){
        chi.pb(S);
        return;
    }
    for(int a=0;a<=2;a++){
        S[u]+=a;
        S[u+1]+=a;
        S[u+2]+=a;
        DFS(u+1);
        S[u]-=a;
        S[u+1]-=a;
        S[u+2]-=a;
    }
}

vi MA[6666];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    DFS(0);
    //cout<<si(chi)<<endl;
    
    int Q;cin>>Q;
    while(Q--){
        int N;cin>>N;
        vi A(N);
        for(int i=0;i<N;i++){
            cin>>A[i];A[i]--;
        }
        vvi Z(N+1,vi(8));
        for(int i=0;i<N;i++){
            Z[i+1]=Z[i];
            Z[i+1][A[i]]++;
        }
        ll ans=0;
        
        for(auto T:chi){
            vi used;
            for(int i=0;i<=N;i++){
                vi U(8);
                int ddd=0;
                for(int j=0;j<8;j++){
                    U[j]=(Z[i][j]-T[j]+333)%3;
                    ddd*=3;
                    ddd+=U[j];
                }
                {
                    int l=-1,r=si(MA[ddd]);
                    while(r-l>1){
                        int m=(l+r)/2;
                        bool ok=true;
                        for(int j=0;j<8;j++){
                            if(Z[i][j]-Z[MA[ddd][m]][j]<T[j]) ok=false;
                        }
                        if(ok) l=m;
                        else r=m;
                    }
                    ans+=l+1;
                }
                ddd=0;
                for(int j=0;j<8;j++){
                    U[j]=(Z[i][j])%3;
                    ddd*=3;
                    ddd+=U[j];
                }
                MA[ddd].pb(i);
                used.pb(ddd);
            }
            for(int a:used) MA[a].clear();
        }
        
        cout<<ans<<"\n";
    }
}



详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3680kb

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: 2713ms
memory: 4688kb

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:


result: