QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#747961#9255. Python ProgramYehhhhAC ✓9ms3620kbC++203.9kb2024-11-14 18:51:482024-11-14 18:51:48

Judging History

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

  • [2024-11-14 18:51:48]
  • 评测
  • 测评结果:AC
  • 用时:9ms
  • 内存:3620kb
  • [2024-11-14 18:51:48]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

inline void print(__int128 x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    if (x > 9)
        print(x / 10);
    putchar(x % 10 + '0');
}

void getnum(string s, __int128& a, __int128& b, __int128& c) {
    int flag = 0;
    int num = 0;
    int flag2 = 0;
    for (int i = 6; s[i] != ')'; i++) {
        if (s[i] == ',') {
            if (flag2 == 1) {
                flag2 = 0;
                num = -num;
            }
            if (flag == 0) {
                a = num;
            } else if (flag == 1) {
                b = num;
            } else {
                c = num;
            }
            flag++;
            num = 0;
        } else if (s[i] == '-') {
            flag2 = 1;
        } else if (s[i] >= '0' && s[i] <= '9') {
            num = num * 10 + (s[i] - '0');
        } else {
            num = 1e6 + 5;
        }
    }
    if (flag2 == 1) {
        flag2 = 0;
        num = -num;
    }
    if (flag == 0) {
        a = num;
    } else if (flag == 1) {
        b = num;
    } else {
        c = num;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;  // ans=0
    cin >> s;  // for
    cin >> s;  // i
    char letter1 = s[0];
    cin >> s;  // in
    cin >> s;  // range(a,b,c):
    __int128 a = 1, b = 1, c = 1;
    getnum(s, a, b, c);
    cin >> s;  // for
    cin >> s;  // j
    char letter2 = s[0];
    cin >> s;  // in
    cin >> s;  // range(d,e,f):
    __int128 d = 1, e = 1, f = 1;
    getnum(s, d, e, f);
    cin >> s;  // ans+=b
    char letter3 = s[5];
    cin >> s;  // print(ans)
    // cerr << letter1 << " " << a << " " << b << " " << c << "\n";
    // cerr << letter2 << " " << d << " " << e << " " << f << "\n";
    // cerr << letter3 << "\n";
    int fd = 0, fe = 0, ff = 0;
    if (d == 1e6 + 5) {
        fd = 1;
    }
    if (e == 1e6 + 5) {
        fe = 1;
    }
    if (f == 1e6 + 5) {
        ff = 1;
    }
    __int128 ans = 0;
    if (c > 0) {
        for (__int128 i = a; i < b; i += c) {
            if (fd) {
                d = i;
            }
            if (fe) {
                e = i;
            }
            if (ff) {
                f = i;
            }
            if (f < 0) {
                if (d <= e) {
                    continue;
                }
                if (letter3 == letter2) {
                    ans += (d + d - (d - (e + 1)) / (-f) * (-f)) * ((d - (e + 1)) / (-f) + 1) / 2;
                } else {
                    ans += ((e + 1) - d) * i;
                }
            } else {
                if (d >= e) {
                    continue;
                }
                if (letter3 == letter2) {
                    ans += (d + ((e - 1) - d) / f * f + d) * (((e - 1) - d) / f + 1) / 2;
                } else {
                    ans += ((e - 1) - d) * i;
                }
            }
        }
    } else {
        for (__int128 i = a; i > b; i += c) {
            if (fd) {
                d = i;
            }
            if (fe) {
                e = i;
            }
            if (ff) {
                f = i;
            }
            if (f < 0) {
                if (d <= e) {
                    continue;
                }
                if (letter3 == letter2) {
                    ans += (d + d - (d - (e + 1)) / (-f) * (-f)) * ((d - (e + 1)) / (-f) + 1) / 2;
                } else {
                    ans += ((e + 1) - d) * i;
                }
            } else {
                if (d >= e) {
                    continue;
                }
                if (letter3 == letter2) {
                    ans += (d + ((e - 1) - d) / f * f + d) * (((e - 1) - d) / f + 1) / 2;
                } else {
                    ans += ((e - 1) - d) * i;
                }
            }
        }
    }
    print(ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 9ms
memory: 3596kb

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: 2ms
memory: 3620kb

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: 8ms
memory: 3488kb

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