QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#654888#9231. Random Numbersreal_sigma_team#TL 196ms3820kbC++23880b2024-10-18 22:44:512024-10-18 22:44:54

Judging History

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

  • [2024-10-18 22:44:54]
  • 评测
  • 测评结果:TL
  • 用时:196ms
  • 内存:3820kb
  • [2024-10-18 22:44:51]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr int LOV66 = 2000;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<ll> pref(n + 1);
    pref[0] = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        pref[i + 1] = pref[i] + a[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int j = i;
        while (j >= 0) {
            ll sm = pref[i + 1] - pref[j];
            if (sm == 1ll * (i - j + 1) * (i - j + 1)) {
                ans++;
                j--;
            } else if (sm < 1ll * (i - j + 1) * (i - j + 1)) {
                j--;
            } else {
                j = i - (int)(sqrt(sm - 1));
            }
        }
    }
    cout << ans << '\n';
} 

int32_t main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3544kb

input:

2
3
2 1 3
5
3 4 2 5 1

output:

2
2

result:

ok 2 number(s): "2 2"

Test #2:

score: 0
Accepted
time: 196ms
memory: 3820kb

input:

32
9811
3756 4960 5623 8471 9330 2388 7066 5434 4707 1711 2109 7274 9630 5057 6390 3252 2632 2291 4697 1923 6423 369 2430 2586 549 1344 1518 9170 268 1315 8808 4843 4603 532 2210 275 835 9059 8529 3449 1412 6071 6737 6944 788 8202 6684 6926 1729 7530 6506 9781 5523 5864 7067 9398 3446 2044 2578 2530...

output:

2
1
1
3
1
4
2
2
2
1
3
2
3
4
2
3
1
1
2
2
2
2
2
1
1
2
1
1
3
2
1
1

result:

ok 32 numbers

Test #3:

score: -100
Time Limit Exceeded

input:

30
197277
196178 84300 27937 106346 19833 131659 146010 164112 125344 93600 5183 26597 55011 30797 100914 95876 43674 164981 46730 54589 170497 74527 174820 95270 4993 78003 192129 55163 191465 156865 7654 164216 22085 118048 86126 178144 77067 60852 180286 180626 3165 43878 111790 131714 96251 9864...

output:


result: