QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#747834#9255. Python Programxianjing#AC ✓3ms3828kbC++232.1kb2024-11-14 18:24:552024-11-14 18:24:55

Judging History

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

  • [2024-11-14 18:24:55]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3828kb
  • [2024-11-14 18:24:55]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long

void solve(){
	int l1 = 0, s1 = 1, r1 = 0, s2 = 1, d1 = 1, s3 = 1;
	int l2 = 0, t1 = 1, r2 = 0, t2 = 1, d2 = 1, t3 = 1;
	char a, b;
	string s;
	getline(cin, s);
	getline(cin, s);
	int p = s.find('(') + 1;
	if (s[p] == '-') s1 = -1, p++;
	for (; s[p] != ','; p++) {
		l1 = l1 * 10 + s[p] - '0';
	}
	p++;
	if (s[p] == '-') s2 = -1, p++;
	for (; s[p] != ',' && s[p] != ')'; p++) {
		r1 = r1 * 10 + s[p] - '0';
	}
	if (s[p] != ')') {
		d1 = 0;
		p++;
		if (s[p] == '-') s3 = -1, p++;
		for (;s[p] != ')'; p++) {
			d1 = 10 * d1 + s[p] - '0';
		}
	}
	l1 = s1 * l1, r1 = s2 * r1, d1 = s3 * d1;
	int v1 = 0, v2 = 0, v3 = 0;
	getline(cin, s);
	p = s.find('(') + 1;
	if (s[p] >= '0' && s[p] <= '9' || s[p] == '-') {
		if (s[p] == '-') t1 = -1, p++;
		for (;s[p] != ','; p++) {
			l2 = 10 * l2 + s[p] - '0';
		}
		l2 = t1 * l2;
	}
	else {
		v1 = 1;
		p++;
	}
	p++;
	if (s[p] >= '0' && s[p] <= '9' || s[p] == '-') {
		if (s[p] == '-') t2 = -1, p++;
		for (;s[p] != ',' && s[p] != ')'; p++) {
			r2 = 10 * r2 + s[p] - '0';
		}
		r2 = t2 * r2;
	}
	else {
		v2 = 1;
	}
	if (s[p] != ')') {
		d2 = 0;
		p++;
		if (s[p] == '-') t3 = -1, p++;
		for (;s[p] != ')'; p++) {
			d2 = 10 * d2 + s[p] - '0';
		}
		d2 = t3 * d2;
	}
	int ans = 0;
	const int inf = 1e9;
	if (r1 != l1 && (r1 - l1) * d1 >= 0) {
		if (r1 > l1) {
			for (int i = l1; i < r1; i += d1) {
				if (v1) l2 = i;
				if (v2) r2 = i;
				if (v3) d2 = i;
				if (l2 != r2 && (r2 - l2) * d2 > 0) {
					int L2 = l2, R2 = r2, D2 = d2;
					int cnt = abs(R2 - (R2 > L2 ? 1 : -1) - L2) / abs(D2);
					ans += (cnt + 1) * (L2 + L2 + cnt * D2) / 2;
				}
			}
		}
		else {
			for (int i = l1; i > r1; i += d1) {
				if (v1) l2 = i;
				if (v2) r2 = i;
				if (v3) d2 = i;
				if (l2 != r2 && (r2 - l2) * d2 > 0) {
					int L2 = l2, R2 = r2, D2 = d2;
					int cnt = abs(R2 - 1 - L2) / abs(D2);
					ans += (cnt + 1) * (L2 + L2 + cnt * D2) / 2;
				}
			}
		}
	}
	cout << ans << '\n';
}


signed main(){
	int t = 1;
//	cin >> t;
	while(t --){
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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

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

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