QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#557978 | #5374. 数圈 | carbon_monoxide | 0 | 96ms | 11816kb | C++14 | 1.2kb | 2024-09-11 13:10:51 | 2024-09-11 13:10:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m,a[300010],sum[300010],tree[300010],b[300010];
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(){
while(cin>>n&&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;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 11816kb
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:
20 0
result:
wrong answer 1st lines differ - expected: '-1', found: '20'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #4:
score: 0
Wrong Answer
time: 96ms
memory: 9828kb
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:
8 28264326 296043 0 -1 0 0 2402286 14090 2031362 0 0 0 -1 0 3591893 0 0 0 1225881 0 -1 -1 0 407548 -1 0 -1 2653338 0 352126 0 -1 -1 -1 2352230 -1 0 1237307 -1 2173841 10896 0 975268 -1 0 2758708 0 129360 -1 0 -1 0 0 -1 0 0 0 -1 0 -1 0 0 0 -1 3948442 0 0 0 0 680342 0 -1 0 -1 -1 121889 -1 3331917 0 67...
result:
wrong answer 1st lines differ - expected: '121860198793245', found: '8'
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%