QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#567431#5374. 数圈carbon_monoxideCompile Error//C++14999b2024-09-16 11:54:412024-09-16 11:54:42

Judging History

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

  • [2024-09-16 11:54:42]
  • 评测
  • [2024-09-16 11:54:41]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;int n,m,a[200010],sum[200010],tree[200010],b[200010],qwq,z;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(){cin>>qwq;while(qwq--){cin>>n;
for(int i=1;i<=n;i++) cin>>a[i],sum[i]=sum[i-1]+a[i];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;}

詳細信息

answer.code: In function ‘int main()’:
answer.code:5:63: error: ‘ans’ was not declared in this scope; did you mean ‘abs’?
    5 | for(int i=1;i<=n;i++) cin>>a[i],sum[i]=sum[i-1]+a[i];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;}
      |                                                               ^~~
      |                                                               abs