QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#551972 | #9255. Python Program | ucup-team4504# | AC ✓ | 3ms | 3860kb | C++14 | 2.7kb | 2024-09-07 19:28:26 | 2024-09-07 19:28:31 |
Judging History
answer
//#pragma GCC optimize("Ofast","inline","-ffast-math")
//#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define INF 1000000007
using namespace __gnu_pbds;
using namespace std;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
inline int calc(string s)
{
int r=0,flag=1;
for(int i=0;i<(int)s.size();i++){
if(s[i]=='-') flag=-1;
else r=r*10+(s[i]-'0');
}
r*=flag;
return r;
}
signed main()
{
ios::sync_with_stdio(false);cin.tie(0);
string tmp;getline(cin,tmp);
getline(cin,tmp);
int pos=15;
string nw="";
while(pos<(int)tmp.size()&&tmp[pos]!=','&&tmp[pos]!=')'){
nw+=tmp[pos];pos++;
}
int a=calc(nw);
pos++;nw="";
while(pos<(int)tmp.size()&&tmp[pos]!=','&&tmp[pos]!=')'){
nw+=tmp[pos];pos++;
}
int b=calc(nw);
int c;
if(tmp[pos]==')') c=1;
else{
pos++;nw="";
while(pos<(int)tmp.size()&&tmp[pos]!=','&&tmp[pos]!=')'){
nw+=tmp[pos];pos++;
}
c=calc(nw);
}
getline(cin,tmp);
pos=19;
nw="";
while(pos<(int)tmp.size()&&tmp[pos]!=','&&tmp[pos]!=')'){
nw+=tmp[pos];pos++;
}
int d=-INF;
if((nw[0]>='0'&&nw[0]<='9')||nw[0]=='-') d=calc(nw);
pos++;nw="";
while(pos<(int)tmp.size()&&tmp[pos]!=','&&tmp[pos]!=')'){
nw+=tmp[pos];pos++;
}
int e=-INF;
if((nw[0]>='0'&&nw[0]<='9')||nw[0]=='-') e=calc(nw);
int f;
if(tmp[pos]==')') f=1;
else{
pos++;nw="";
while(pos<(int)tmp.size()&&tmp[pos]!=','&&tmp[pos]!=')'){
nw+=tmp[pos];pos++;
}
f=-INF;
if((nw[0]>='0'&&nw[0]<='9')||nw[0]=='-') f=calc(nw);
}
long long ans=0ll;
if(c>0&&a<b){
for(int i=a;i<b;i+=c){
int D=d,E=e,F=f;
if(d==-INF) D=i;
if(e==-INF) E=i;
if(f==-INF) F=i;
if(F>0&&D<E){
E--;
int o=(E-D)/F+1;
ans+=1ll*(D+D+(o-1)*F)*o/2ll;
}
else if(F<0&&D>E){
E++;F=-F;
int o=(D-E)/F+1;
ans+=1ll*(D+D-(o-1)*F)*o/2ll;
}
}
}
else if(c<0&&a>b){
for(int i=a;i>b;i+=c){
int D=d,E=e,F=f;
if(d==-INF) D=i;
if(e==-INF) E=i;
if(f==-INF) F=i;
if(F>0&&D<E){
E--;
int o=(E-D)/F+1;
ans+=1ll*(D+D+(o-1)*F)*o/2ll;
}
else if(F<0&&D>E){
E++;F=-F;
int o=(D-E)/F+1;
ans+=1ll*(D+D-(o-1)*F)*o/2ll;
}
}
}
cout<<ans<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
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: 3820kb
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: 3ms
memory: 3860kb
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: 1ms
memory: 3564kb
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: 3ms
memory: 3792kb
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