QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#646789#9255. Python Programicpc_zhzx034#AC ✓4ms3624kbC++142.1kb2024-10-17 08:30:022024-10-17 08:30:03

Judging History

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

  • [2024-10-17 08:30:03]
  • 评测
  • 测评结果:AC
  • 用时:4ms
  • 内存:3624kb
  • [2024-10-17 08:30:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <ll,ll> P;
#define _for(x,y,z) for (int x(y),_(z); x<=_; ++x)
#define _rep(x,y,z) for (int x(y),_(z); x>=_; --x)
inline ll read(){ ll x; cin>>x; return x; }
inline void _init(){
	#ifdef LOCAL
		assert(freopen("test.in", "r", stdin));
		assert(freopen("test.out", "w", stdout));
	#endif
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
}


void init() {}
void procedure() {
	string s;
	ll a=0,b=0,c=0,d=0,e=0,f=0,cnt=0;
	ll fa=0,fb=0,fc=0,fd=0,fe=0,ff=0;
	while(cin>>s){
		_for(i,0,s.size()-1){
			if(s[i]=='('){
				if(cnt==2)continue;
				++cnt;
				if(cnt==1){
					int j=i+1;
					while(s[j]!=','){
						if(s[j]=='-')fa=1,++j;
						else a=a*10+s[j]-'0',++j;
					}
					++j;
					while(s[j]!=','&&s[j]!=')'){
						if(s[j]=='-')fb=1,++j;
						else b=b*10+s[j]-'0',++j;
					}				
					if(s[j]==')')c=1;
					else{
						++j;
						while(s[j]!=')'){
							if(s[j]=='-')fc=1,++j;
							else c=c*10+s[j]-'0',++j;
						}
					}
					i=j;
				}
				else{
					int j=i+1;
					while(s[j]!=','){
						if(s[j]<='z'&&s[j]>='a')d=0,++j;
						else if(s[j]=='-')fd=1,++j;
						else d=d*10+s[j]-'0',++j;
					}
					++j;
					while(s[j]!=','&&s[j]!=')'){
						if(s[j]<='z'&&s[j]>='a')e=0,++j;
						else if(s[j]=='-')fe=1,++j;
						else e=e*10+s[j]-'0',++j;
					}			
					if(s[j]==')')f=1;
					else{
						++j;
						while(s[j]!=')'){
							if(s[j]<='z'&&s[j]>='a')f=0,++j;
							else if(s[j]=='-')ff=1,++j;
							else f=f*10+s[j]-'0',++j;
						}
					}
					i=j;
				}
			}
		}
	}
	a=fa?-a:a;
	b=fb?-b:b;
	c=fc?-c:c;
	d=fd?-d:d;
	e=fe?-e:e;
	f=ff?-f:f;
	ll ans=0;
	for(ll i=a;c<0?i>b:i<b;i+=c){
		ll x=!d?i:d;
		ll y=!e?i:e;
		ll z=!f?i:f;
		if(z<0&&x<=y)continue;
		if(z>0&&x>=y)continue;
		if(z<0){
			++y;
			ll lst=x-(x-y)/(-z)*(-z);
			ll num=(x-lst)/(-z)+1;
			ans+=(lst+x)*num/2;
		}
		else{
			--y;
			ll lst=(y-x)/z*z+x;
			ll num=(lst-x)/z+1;
			ans+=(lst+x)*num/2;
		}
	}
	cout<<ans<<'\n';
}

int main() {
	_init(), init();
	int T=1;
	while(T--) procedure();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3608kb

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: 3552kb

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: 4ms
memory: 3624kb

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: 3612kb

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: 3612kb

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