QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#550030#9255. Python Programucup-team4757#AC ✓5ms3780kbC++142.3kb2024-09-07 09:02:152024-09-07 09:02:16

Judging History

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

  • [2024-09-07 09:02:16]
  • 评测
  • 测评结果:AC
  • 用时:5ms
  • 内存:3780kb
  • [2024-09-07 09:02:15]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
char _1;
stack<int> st;
#define ll long long
int read(){
	int res=0,op=1;
	while(cin.peek()!='-'&&(cin.peek()>'9'||cin.peek()<'0'))cin.ignore();
	if(cin.peek()=='-')op=-1,cin.ignore();
	while(cin.peek()<='9'&&cin.peek()>='0')res=res*10+op*(cin.peek()-'0'),cin.ignore();
	return res;
}
const int SIG=1e9;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	while(cin.peek()!='f')cin.ignore();
	cin.ignore();//f
	cin.ignore();//o
	cin.ignore();//r
	cin.ignore();// 
	_1=cin.peek();cin.ignore();//?
	cin.ignore();// 
	cin.ignore();//i
	cin.ignore();//n
	cin.ignore();// 
	cin.ignore();//r
	cin.ignore();//a
	cin.ignore();//n
	cin.ignore();//g
	cin.ignore();//e
	cin.ignore();//(
	int dot=0;
	while(cin.peek()!=')'){
		st.push(cin.peek());
		dot+=(cin.peek()==',');
		cin.ignore();
	}
	while(!st.empty())cin.putback(st.top()),st.pop();
	int a=read(),b=read(),c=dot==1?1:read();
	while(cin.peek()!='f')cin.ignore();
	cin.ignore();//f
	cin.ignore();//o
	cin.ignore();//r
	cin.ignore();//	
	cin.ignore();//?
	cin.ignore();// 
	cin.ignore();//i
	cin.ignore();//n
	cin.ignore();// 
	cin.ignore();//r
	cin.ignore();//a
	cin.ignore();//n
	cin.ignore();//g
	cin.ignore();//e
	cin.ignore();//(
	dot=0;
	while(cin.peek()!=')'){
		st.push(cin.peek());
		dot+=(cin.peek()==',');
		cin.ignore();
	}
	while(!st.empty())cin.putback(st.top()),st.pop();
	int d,e,f;
	if(cin.peek()==_1){
		d=SIG;
		while(cin.peek()!=','&&cin.peek()!=')')cin.ignore();
		cin.ignore();
	}else d=read();
	if(cin.peek()==_1){
		e=SIG;
		while(cin.peek()!=','&&cin.peek()!=')')cin.ignore();
		cin.ignore();
	}else e=read();
	if(cin.peek()==')')f=1;
	else if(cin.peek()==_1){
		f=SIG;
		while(cin.peek()!=','&&cin.peek()!=')')cin.ignore();
		cin.ignore();
	}else f=read();
	if((a>=b&&c>=0)||(a<=b&&c<=0))return cout<<0,0;
	ll ans=0;
	// cout<<a<<" "<<b<<" "<<c<<"\n";
	for(int i=a;(c>0?i<b:i>b);i+=c){
		int di=(d==SIG?i:d),ei=(e==SIG?i:e),fi=(f==SIG?i:f);
		// cout<<i<<" "<<di<<" "<<ei<<" "<<fi<<"\n";
		if((di>=ei&&fi>=0)||(di<=ei&&fi<=0))continue;
		if(di>ei){
			fi=-fi;
			int X=(di-ei-1)/fi+1;
			ans+=1ll*(di+(di-1ll*(X-1)*fi))*X/2;
		}else{
			int X=(ei-di-1)/fi+1;
			ans+=1ll*(di+(di+1ll*(X-1)*fi))*X/2;
		}
	}
	cout<<ans;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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

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

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