QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#656055 | #9231. Random Numbers | woodie_0064# | TL | 0ms | 3640kb | C++20 | 811b | 2024-10-19 11:06:09 | 2024-10-19 11:06:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
int T;
int n, num;
typedef long long ll;
void work(){
cin >> n;
vector <ll> a(n + 1),sum(n + 1);
for(int i = 1;i <= n;i++) {
cin >> a[i];
sum[i] = a[i];
sum[i] += sum[i - 1];
}
auto calc = [&] (ll now) {
ll x = sqrt(now);
if(x * x != now) x++;
return x;
};
ll ans = 0;
for(int i = 1;i <= n;i++) {
ll len = 0;
while(true) {
len = max(len + 1,calc(sum[i] - sum[i - len]));
if(len > i) break;
// cout << i << ' ' << len << ' ' << sum[i] << '\n';
if(sum[i] - sum[i - len] == len * len) ans++;
}
}
cout << ans << '\n';
}
int main(){
// freopen("test.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0);
cin >> T;
while(T--){
work();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
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: -100
Time Limit Exceeded
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...