QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#706774 | #9255. Python Program | UESTC_DECAYALI# | AC ✓ | 5ms | 4116kb | C++20 | 2.1kb | 2024-11-03 13:24:53 | 2024-11-03 13:24:54 |
Judging History
answer
#include<cstdio>
#include<iostream>
#include<string>
#include<cctype>
#define RI register int
#define CI const int&
using namespace std;
const int INF=1e9;
int a,b,c,d,e,f;
int main()
{
string s; getline(cin,s); getline(cin,s);
int p=0; while (s[p]!='(') ++p; ++p;
while (isdigit(s[p])) a=a*10+s[p++]-'0'; ++p;
while (isdigit(s[p])) b=b*10+s[p++]-'0'; ++p;
if (s[p]==':') c=1; else
{
int flag=1; if (s[p]=='-') ++p,flag=-1;
while (isdigit(s[p])) c=c*10+s[p++]-'0'; ++p;
c*=flag;
}
getline(cin,s); p=0;
while (s[p]!='(') ++p; ++p;
if (isalpha(s[p])) d=INF,p+=2; else
{
while (isdigit(s[p])) d=d*10+s[p++]-'0'; ++p;
}
if (isalpha(s[p])) e=INF,p+=2; else
{
while (isdigit(s[p])) e=e*10+s[p++]-'0'; ++p;
}
if (s[p]==':') f=1; else
if (isalpha(s[p])) f=INF,p+=2; else
{
int flag=1; if (s[p]=='-') ++p,flag=-1;
while (isdigit(s[p])) f=f*10+s[p++]-'0'; ++p;
f*=flag;
}
getline(cin,s); long long ans=0;
// printf("%d %d %d\n%d %d %d\n",a,b,c,d,e,f);
auto calc=[&](CI a,CI b,CI c)
{
// printf("calc(%d,%d,%d) = ",a,b,c);
if (c>0)
{
if (a>=b) return 0LL;
int k=max((b-a-1)/c,0);
// printf("%lld\n",1LL*(2*a+1LL*k*c)*(k+1)/2LL);
return 1LL*(2*a+1LL*k*c)*(k+1)/2LL;
} else
{
if (a<=b) return 0LL;
int k=max((a-b-1)/(-c),0);
// printf("%lld\n",1LL*(2*a+1LL*k*c)*(k+1)/2LL);
return 1LL*(2*a+1LL*k*c)*(k+1)/2LL;
}
};
if (c>0)
{
for (RI i=a;i<b;i+=c)
if (d==INF) ans+=calc(i,e,f); else
if (e==INF) ans+=calc(d,i,f); else
if (f==INF) ans+=calc(d,e,i); else
ans+=calc(d,e,f);
} else
{
for (RI i=a;i>b;i+=c)
if (d==INF) ans+=calc(i,e,f); else
if (e==INF) ans+=calc(d,i,f); else
if (f==INF) ans+=calc(d,e,i); else
ans+=calc(d,e,f);
}
printf("%lld",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3996kb
input:
ans=0 for a in range(1,3): for b in range(5,1,-2): ans+=b print(ans)
output:
16
result:
ok single line: '16'
Test #2:
score: 0
Accepted
time: 0ms
memory: 4116kb
input:
ans=0 for q in range(100,50,-1): for i in range(q,77,20): ans+=i print(ans)
output:
2092
result:
ok single line: '2092'
Test #3:
score: 0
Accepted
time: 5ms
memory: 3768kb
input:
ans=0 for i in range(1,1000000): for j in range(i,1,-1): ans+=j print(ans)
output:
166666666665500001
result:
ok single line: '166666666665500001'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
ans=0 for i in range(31,321983,2): for j in range(313,382193): ans+=j print(ans)
output:
11756963404587200
result:
ok single line: '11756963404587200'
Test #5:
score: 0
Accepted
time: 5ms
memory: 4044kb
input:
ans=0 for i in range(1,1000000): for j in range(i,114514,-1): ans+=j print(ans)
output:
160610445975856765
result:
ok single line: '160610445975856765'
Extra Test:
score: 0
Extra Test Passed