跳到正文

个人记录

题解代码:P14131 【MX-X22-T2】「TPOI-4B」K Problem

zheqing约 3 分钟
原文
文章信息与版本

文章信息

发布
2025年10月2日
收录
2025年12月12日
更新
2026年11月12日
篇幅
约 3 分钟

版本

  1. v2当前
  2. v1
C++
#include<bits/stdc++.h>
#define x first
#define y second
#define int long long
#define i128 __int128
#define pb push_back
#define all(n) n.begin(),n.end()
#define ppb pop_back
#define eb emplace_back
#define PII pair<int,int>
#define YES "YES"
#define NO "NO"
#define endl '\n'
#define lson p<<1
#define rson p<<1|1

using namespace std;
mt19937_64 mrand(random_device{}());
const int N = 1e5 + 10,mod = 1e9 + 7;
int qmi(int a,int b){
    int res = 1;
    while(b){
        if(b&1) res = res * a % mod;
        b>>=1;
        a = a * a % mod;
    }
    return res;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cout.flags(ios::fixed);
    cout.precision(10);
    auto solve = [&](){
        int n;
        cin>>n;
        vector<vector<int> > g(n + 1);
        vector<int> a(n + 1),sa(n + 1),saf(n + 1);
        for(int i = 1;i<=n;i++){
            cin>>a[i];
            sa[i] = sa[i - 1] + a[i];
            saf[i] = saf[i - 1] + a[i] * a[i];
        }
        int res = 0;
        for(int i = 1,j = 1;i<=n;j++,i += j){
            int sum = 0,sumf = 0;
            for(int w = 1;w <= j;w++) sum += w*w,sumf += w * w * w;

            for(int l = 1;l + i - 1<= n;l++){
                if(sa[l + i - 1] - sa[l - 1] == sum && saf[l + i - 1] - saf[l - 1] == sumf) {
                    res = max(res,j);
                    break;
                }
            }
        }
        cout<<res<<endl;
    };
    int t = 1;
    cin>>t;
    while(t--) solve();

    return 0;
}
原文