QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#86574 | #5374. 数圈 | tricyzhkx | 10 | 62ms | 4348kb | C++14 | 1.2kb | 2023-03-10 10:17:01 | 2023-03-10 10:17:04 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100010],b[100010],id[100010],rr[100010],r[100010];
struct BIT
{
int n,s[100010];
void init(int _n){n=_n;memset(s+1,0,sizeof(int)*n);}
void update(int x){for(int i=x;i<=n;i+=i&(-i)) s[i]++;}
int query(int x)
{
int ans=0;
for(int i=x;i;i-=i&(-i)) ans+=s[i];
return ans;
}
}B;
int main()
{
int T;
cin>>T;
while(T--)
{
int n,S=0;
ll ans=0,sum=0;
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]),a[i]+=a[i-1];
S=a[n];
if(S<0){puts("-1");continue;}
else if(!S)
{
bool ok=1;
for(int i=1;i<=n;i++) ok&=(!a[i]);
puts(ok?"0":"-1");
continue;
}
iota(id+1,id+n+1,1);
sort(id+1,id+n+1,[](int i,int j){return a[i]<a[j] || (a[i]==a[j] && i>j);});
B.init(n);
for(int i=1;i<=n;i++) ans-=B.query(id[i]),B.update(id[i]);
for(int i=1;i<=n;i++) rr[i]=r[i]=a[i]%S,b[i]=a[i]/S;
sort(rr+1,rr+n+1);
int len=unique(rr+1,rr+n+1)-rr-1;
for(int i=1;i<=n;i++) r[i]=lower_bound(rr+1,rr+len+1,r[i])-rr;
B.init(len);
for(int i=1;i<=n;i++) sum+=b[id[i]],ans+=(ll)i*b[id[i]]-sum+B.query(r[id[i]]-1),B.update(r[id[i]]);
printf("%lld\n",ans);
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3812kb
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 3 2 1 -1 -1
result:
wrong answer 6th lines differ - expected: '4', found: '3'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 10
Accepted
Test #4:
score: 10
Accepted
time: 50ms
memory: 4288kb
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:
121860198793245 46938573692959 57703965834328 59944493006183 81807878531011 49309954483988 78546660217267 113040545520897 33896072757379 62212580026212
result:
ok 10 lines
Subtask #5:
score: 0
Wrong Answer
Dependency #4:
100%
Accepted
Test #5:
score: 0
Wrong Answer
time: 62ms
memory: 4348kb
input:
10 30000 -2595 -3716 4165 858 -5266 -3829 811 -2088 3328 3550 4682 -4106 1810 -1775 -470 189 2599 -4024 2125 1382 2756 3173 1951 975 3411 389 4564 3431 -4952 4333 -2522 2676 2205 -105 -3087 -1781 4430 2299 4505 1113 -826 312 1429 52 -985 2395 2056 -2832 1613 -3243 3271 2772 -2816 -3652 4580 1365 123...
output:
-1 66307718106454 20087854603233 17527601965981 14265265860848 24031019205016 6589819255335 11905464735155 8996146482029 6585097292548
result:
wrong answer 4th lines differ - expected: '17527604892002', found: '17527601965981'
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%