QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#835744 | #9922. Mah-jong | ucup-team055# | TL | 1568ms | 4444kb | C++20 | 3.7kb | 2024-12-28 14:23:16 | 2024-12-28 14:23:18 |
Judging History
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[i % 3] += rem[i];
ch_3[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);
}
}
for (auto x : G) if (!x.empty()) ans += (ll)(x.size()) * (ll)(x.size() - 1) / 2;
cout << ans << "\n";
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 4072kb
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: 1568ms
memory: 4444kb
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...