QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#860318#9922. Mah-jonghos_lyricRE 1ms4096kbC++143.0kb2025-01-18 12:27:182025-01-18 12:27:20

Judging History

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

  • [2025-01-18 12:27:20]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:4096kb
  • [2025-01-18 12:27:18]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


constexpr int K = 8;
constexpr int U = 6561;
constexpr int Q = U / 9;

int thr[K + 1];
int us[Q], need[Q][K];
int add[U][K];

int N;
vector<int> A;

int main() {
  thr[0] = 1;
  for (int k = 1; k <= K; ++k) thr[k] = thr[k - 1] * 3;
  for (int q = 0; q < Q; ++q) {
    for (int j = 0; j < K - 2; ++j) {
      const int t = q / thr[j] % 3;
      for (int k = j; k < j + 3; ++k) {
        us[q] += t * thr[k];
        need[q][k] += t;
      }
    }
  }
  for (int u = 0; u < U; ++u) {
    for (int k = 0; k < K; ++k) {
      add[u][k] = (u / thr[k] % 3 == 2) ? (u - 2 * thr[k]) : (u + thr[k]);
    }
  }
  
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    scanf("%d", &N);
    A.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%d", &A[i]);
      --A[i];
    }
    
    vector<int> pre(N + 1, 0);
    for (int i = 0; i < N; ++i) {
      pre[i + 1] = add[pre[i]][A[i]];
    }
    
    Int ans = 0;
    for (int q = 0; q < Q; ++q) {
      int freq[U] = {};
      for (int i = 0; i <= N; ++i) ++freq[pre[i]];
      int r = 0;
      int now[K] = {};
      for (int k = 0; k < K; ++k) {
        for (; now[k] < need[q][k]; ++r) {
          if (r == N) goto failed;
          --freq[pre[r]];
          ++now[A[r]];
        }
      }
      for (int tar = us[q], l = 0; l < N; ++l) {
        ans += freq[tar];
        tar = add[tar][A[l]];
        --now[A[l]];
        for (; now[A[l]] < need[q][A[l]]; ++r) {
          if (r == N) goto failed;
          --freq[pre[r]];
          ++now[A[r]];
        }
      }
     failed:{}
    }
    ans -= N;
    printf("%lld\n", ans);
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 4096kb

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
Runtime Error

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:


result: