QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#100358 | #5374. 数圈 | zhouhuanyi | 10 | 94ms | 4408kb | C++23 | 1.7kb | 2023-04-25 17:52:04 | 2023-04-25 17:52:05 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 200000
using namespace std;
int read()
{
char c=0;
int sum=0,f=1;
while (c!='-'&&(c<'0'||c>'9')) c=getchar();
if (c=='-') c=getchar(),f=-1;
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum*f;
}
int T,n,length,a[N+1],s[N+1],p[N+1],st[N+1],c[N+1];
long long ans;
int lowbit(int x)
{
return x&(-x);
}
void add(int x,int d)
{
for (;x<=length;x+=lowbit(x)) c[x]+=d;
return;
}
int query(int x)
{
int res=0;
for (;x>=1;x-=lowbit(x)) res+=c[x];
return res;
}
int F(int x)
{
if (x>0) return x/s[n];
else return -(-x+s[n]-1)/s[n];
}
int main()
{
bool op;
T=read();
while (T--)
{
n=read(),ans=length=0;
for (int i=1;i<=n;++i) a[i]=read(),s[i]=s[i-1]+a[i];
if (s[n]<0)
{
puts("-1");
continue;
}
if (s[n]==0)
{
op=1;
for (int i=1;i<=n;++i) op&=(s[i]==0);
if (!op)
{
puts("-1");
continue;
}
else
{
puts("0");
continue;
}
}
for (int i=1;i<=n;++i) st[++length]=s[i],st[++length]=s[i]%s[n];
sort(st+1,st+length+1),length=unique(st+1,st+length+1)-st-1;
for (int i=1;i<=length;++i) c[i]=0;
for (int i=1;i<=n;++i) ans-=query(lower_bound(st+1,st+length+1,s[i])-st-1),add(lower_bound(st+1,st+length+1,s[i])-st,1);
for (int i=1;i<=n;++i) p[i]=s[i];
sort(p+1,p+n+1);
for (int i=1;i<=n;++i) ans+=1ll*((i-1)-(n-i))*F(p[i]);
for (int i=1;i<=length;++i) c[i]=0;
for (int i=1;i<=n;++i) ans+=query(lower_bound(st+1,st+length+1,p[i]%s[n])-st-1),add(lower_bound(st+1,st+length+1,p[i]%s[n])-st,1);
printf("%lld\n",ans);
}
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: 2ms
memory: 3400kb
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 3 5 2 1 -1 -1
result:
wrong answer 5th lines differ - expected: '1', 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: 94ms
memory: 4408kb
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: 86ms
memory: 4336kb
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 20087956255856 17527620897293 14265416919407 24031156399956 6589950483001 11905651724469 8996300014570 6585293878964
result:
wrong answer 3rd lines differ - expected: '20087854603233', found: '20087956255856'
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
0%