WA on test9求调
查看原帖
WA on test9求调
576817
Lyrella楼主2023/10/27 22:25
/*
 * @Author: Nekopedia 
 * @Date: 2023-10-22 21:01:58 
 * @Last Modified by: Nekopedia
 * @Last Modified time: 2023-10-22 22:24:26
 */
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll rd(){
   ll x = 0, f = 1; char c = getchar();
   while(! isdigit(c)){if(c == '-')f = - f; c = getchar();}
   while(isdigit(c)){x = (x << 3) + (x << 1) + (c ^ 48); c = getchar();}
   return x * f;
}

const int N = 3e5 + 5, p = 1e9 + 7;
int T, n;
ll ans;

struct matrix{
    int n; ll a[2][2];
    void clear(){
        for(int i = 0; i < 2; ++i)for(int j = 0; j < 2; ++j)a[i][j] = 0;
    }
    matrix operator * (const matrix &rhs)const {
        matrix res; res.clear(); res.n = 2;
        for(int i = 0; i < 2; ++i)for(int j = 0; j < 2; ++j)for(int k = 0; k < 2; ++k){
            res.a[i][j] += a[i][k] * rhs.a[k][j] % p;
            res.a[i][j] %= p;
        }
        return res;
    }
    bool operator < (const matrix &x)const {
        if(a[0][0] ^ x.a[0][0])return a[0][0] < x.a[0][0];
        if(a[0][1] ^ x.a[0][1])return a[0][1] < x.a[0][1];
        if(a[1][0] ^ x.a[1][0])return a[1][0] < x.a[1][0];
        if(a[1][1] ^ x.a[1][1])return a[1][1] < x.a[1][1];
        return 0;
    }
}c[N][2], s;
map < matrix , ll > mp;
int cnt[N];

signed main(){
    T = rd();
    for(int i = 1; i < N; ++i){
        ll j = i * 114;
        c[i][0].n = c[i][1].n = 2;
        c[i][0].a[0][0] = j, c[i][0].a[0][1] = j + 1;
        c[i][0].a[1][0] = j - 1, c[i][0].a[1][1] = j;
        c[i][1].a[0][0] = j, c[i][1].a[0][1] = p - j - 1;
        c[i][1].a[1][0] = (p + 1 - j) % p, c[i][1].a[1][1] = j;
    } s.n = 2;
    while(T--){
        n = rd(); ans = 0;
        s.a[0][0] = 1, s.a[0][1] = 0, s.a[1][0] = 0, s.a[1][1] = 1;
        mp.clear(); ++mp[s];
        for(int i = 1; i <= n; ++i){
            int x = rd(); ++cnt[x]; s = s * c[x][cnt[x] & 1];
            ans += mp[s]++;
        }
        printf("%lld\n", ans); for(int i = 0; i <= n; ++i)cnt[i] = 0;
    }
    return 0;
}
2023/10/27 22:25
加载中...