QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#557977 | #5374. 数圈 | carbon_monoxide | 30 | 1ms | 3716kb | C++14 | 1.3kb | 2024-09-11 13:09:30 | 2024-09-11 13:09:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m,a[1010],sum[1010],tree[1010],b[1010];
void add(int x,int y){for(;x<=m;x+=x&-x) tree[x]+=y;}
int query(int x){
int res=0;
for(;x;x&=x-1) res+=tree[x];
return res;
}
signed main(){
int qwq;cin>>qwq;
while(qwq--){cin>>n;
for(int i=1;i<=n;i++) cin>>a[i],sum[i]=sum[i-1]+a[i];
int z=sum[n],ans=0;
if(z<0){cout<<"-1\n";continue;}
if(!z){
int f=0;
for(int i=1;i<=n;i++){
if(a[i]){
cout<<"-1\n";
f=1;break;
}
}
if(!f) cout<<"0\n";
continue;
}
for(int i=1;i<=n;i++){
b[++m]=sum[i];
b[++m]=(sum[i]%z+z)%z;
}
sort(b+1,b+m+1);
m=unique(b+1,b+m+1)-b-1;
memset(tree,0,sizeof(tree));
for(int i=1;i<=n;i++){
ans-=query(lower_bound(b+1,b+m+1,sum[i])-b-1);
add(lower_bound(b+1,b+m+1,sum[i])-b,1);
}
sort(sum+1,sum+n+1);
memset(tree,0,sizeof(tree));
for(int i=1;i<=n;i++){
ans+=(i*2-1ll-n)*(sum[i]>0?sum[i]/z:(sum[i]-z+1)/z)+query(lower_bound(b+1,b+m+1,(sum[i]%z+z)%z)-b-1);
add(lower_bound(b+1,b+m+1,(sum[i]%z+z)%z)-b,1);
}
cout<<ans<<"\n";
memset(sum,0,sizeof(sum));
m=0;
}
return 0;
}
详细
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 1ms
memory: 3716kb
input:
10 3 2 -9 -4 3 4 6 0 3 3 -10 0 3 7 -6 3 3 -6 7 10 3 -3 9 -2 3 6 1 -2 3 5 2 -2 3 -9 -5 7 3 -4 -5 6
output:
-1 0 -1 3 1 4 2 1 -1 -1
result:
ok 10 lines
Subtask #2:
score: 20
Accepted
Dependency #1:
100%
Accepted
Test #2:
score: 20
Accepted
time: 0ms
memory: 3628kb
input:
10 50 -5 -5 3 8 0 0 3 8 5 -7 6 -9 5 5 2 7 -9 1 -7 5 0 10 -6 -2 -6 -8 9 7 4 3 -9 9 5 9 8 1 7 0 0 -5 -1 -3 5 -7 5 -4 6 8 -1 1 50 -6 4 3 -6 -9 -8 -5 -2 -10 7 -4 1 -1 -5 2 1 -10 8 8 7 -8 -5 3 -6 10 3 2 -1 10 0 4 -6 9 3 -6 3 9 -4 4 -2 -3 4 -9 -7 7 1 5 2 -4 5 50 2 -10 5 3 -1 1 9 -1 -5 3 -2 -10 7 0 5 -5 -1...
output:
161 -1 249 -1 21873 -1 452 -1 -1 314
result:
ok 10 lines
Subtask #3:
score: 0
Runtime Error
Dependency #2:
100%
Accepted
Test #3:
score: 0
Runtime Error
input:
10 2000 -4438 -448 2902 3873 -5348 1821 -5284 2787 -1369 -4712 3298 2808 1651 -4568 4377 870 2217 -2683 1217 120 -3854 1156 -2129 -3757 -2704 3026 -1745 -5327 -1315 405 3944 340 -1510 2213 -24 -32 -5414 -2330 760 3715 -4871 2831 1917 3148 1360 -3662 -4281 -1248 788 1334 -3401 2050 4174 3163 -2456 33...
output:
0 -1
result:
Subtask #4:
score: 0
Runtime Error
Test #4:
score: 0
Runtime Error
input:
10 30000 -3879 -556 4570 1863 2815 -4010 2471 -270 2835 3071 -3331 -1251 -2243 4221 -5249 -4134 3376 1978 858 2545 -4207 386 3875 2029 1706 1119 3065 -3097 4399 4385 -3021 2473 2506 2157 3946 -886 3929 1478 2728 -4239 4091 -151 -4762 -2136 -1424 2162 -669 267 190 -1180 2640 -757 -2078 -1409 3165 216...
output:
-1 -1 40132 -1
result:
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%