QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#835739#9922. Mah-jongucup-team055#WA 1574ms4252kbC++203.7kb2024-12-28 14:20:302024-12-28 14:20:31

Judging History

This is the latest submission verdict.

  • [2024-12-28 14:20:31]
  • Judged
  • Verdict: WA
  • Time: 1574ms
  • Memory: 4252kb
  • [2024-12-28 14:20:30]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
const ll ILL=2167167167167167167;
const int INF=2100000000;
#define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,T b){if(b<a){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
bool yneos(bool a,bool upp=0){if(a){cout<<(upp?"YES\n":"Yes\n");}else{cout<<(upp?"NO\n":"No\n");}return a;}
template<class T> void vec_out(vector<T> &p,int ty=0){
    if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'<<p[i]<<'"';}cout<<"}\n";}
    else{if(ty==1){cout<<p.size()<<"\n";}for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}}
template<class T> T vec_min(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;}
template<class T> T vec_max(vector<T> &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;}
template<class T> T vec_sum(vector<T> &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;}
int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;}



void solve();
// CITRUS CURIO CITY / FREDERIC
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    cin >> t;
    rep(i, 0, t) solve();
}

void solve(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, 0, N) cin >> A[i], A[i]--;
    const int M = 8;
    vector sum(N + 1, vector<int>(M));
    rep(i, 0, N){
        sum[i + 1] = sum[i];
        sum[i + 1][A[i]]++;
    }
    int X = 1;
    rep(i, 0, M) X *= 3;
    vector<vector<int>> G(X);
    rep(i, 0, N + 1){
        int tmp = 0;
        for (int j = M - 1; j >= 0; j--){
            tmp *= 3;
            tmp += sum[i][j] % 3;
        }
        G[tmp].push_back(i);
    }
    ll ans = 0;
    rep(rp, 1, X){
        vector<int> rem(M);
        vector<int> ch_3(3);
        int tmp = rp;
        rep(i, 0 ,M){
            rem[i] = tmp % 3;
            tmp /= 3;
            ch_3[rem[i] % 3] += rem[i];
            ch_3[rem[i] % 3] %= 3;
        }
        if (vec_max(ch_3) != vec_min(ch_3)) continue;
        vector<int> lim(M);
        vector<int> jikken = rem;
        int ng = 0;
        rep(i, 0, M - 2){
            while (jikken[i] % 3){
                rep(j, 0, 3){
                    jikken[j + i] += 2;
                    lim[j + i]++;
                }
            }
        }
        rep(i, 0, M) if (lim[i]) ng++;
        auto upd = [&](int a, int c) -> void {
            if (lim[a] > 0) ng--;
            lim[a] -= c;
            if (lim[a] > 0) ng++;
        };
        int l = 0;
        rep(r, 0, N){
            upd(A[r], 1);
            while (ng == 0 && l <= r){
                upd(A[l], -1);
                if (ng){
                    upd(A[l], 1);
                    break;
                }
                l++;
            }
            if (ng != 0) continue;
            int val = 0;
            for (int j = M - 1; j >= 0; j--){
                val *= 3;
                val += (sum[r + 1][j] - rem[j] + 3) % 3;
            }
            ans += UB(G[val], l);
            if (rp == 0) ans--;
        }
    }
    for (auto x : G) ans += (ll)(x.size()) * (ll)(x.size() - 1) / 2;
    cout << ans << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1574ms
memory: 4252kb

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:

51299
61305
5199
1853
240996
6221
10932
46121
434573
1217800
16968
138479
299215
957973
216575
1230
86602
139535
69259
1
78283
0
38841
16546
85554
0
99876
160939
1
511645
58745
197144
25722
61719
29094
11401
1928
4172
74273
905384
172859
23608
491
87106
1301599
1297
11627
155162
11368
22959
24734
93...

result:

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