QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#553846#9255. Python Program333zhanAC ✓55ms4012kbC++204.4kb2024-09-08 21:12:582024-09-08 21:12:58

Judging History

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

  • [2024-09-08 21:12:58]
  • 评测
  • 测评结果:AC
  • 用时:55ms
  • 内存:4012kb
  • [2024-09-08 21:12:58]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define db double
#define ll unsigned long long
#define lson (rt << 1)
#define rson (rt << 1 | 1)

using namespace std;
 
inline int read () {
    int w = 1, s = 0; char ch = getchar();
    for (; ! isdigit(ch); ch = getchar()) if (ch == '-') w = -1;
    for (; isdigit(ch); ch = getchar()) s = (s << 1) + (s << 3) + (ch ^ 48);
    return s * w;
}

void solve () {
	array <string, 6> s;
    for (int i = 1; i <= 5; i ++) {
        getline (cin, s[i]);
    }

    char c1 = s[2][4], c2 = s[3][4];//i, j
    
    int sum2 = count (s[2].begin (), s[2].end (), ',');
    int sum3 = count (s[3].begin (), s[3].end (), ',');

   // cerr << sum2 << " " << sum3 << '\n';

    int a1 = 0, a2 = 0, a3 = 1;//第一层循环
    int b1 = 0, b2 = 0, b3 = 1;//第二层循环
    bool ok1 = 0, ok2 = 0, ok3 = 0;//判断第二层循环是字母还是数字
    
//======================================================================
//第一层循环的处理
    int id21 = s[2].find ('('), id22 = s[2].find (',', id21);
    for (int i = id21 + 1; i < id22; i ++) {
        a1 = a1 * 10 + s[2][i] - '0';
    }
    int id23 = s[2].find (',', id22 + 1);
    if (id23 == -1) {
        int id24 = s[2].find (')', id22);
        for (int i = id22 + 1; i < id24; i ++) {
            a2 = a2 * 10 + s[2][i] - '0';
        }
    } else {
        for (int i = id22 + 1; i < id23; i ++) {
            a2 = a2 * 10 + s[2][i] - '0';
        }
        a3 = 0;
        int w = 1;
        int id24 = s[2].find (')', id22);
        if (s[2][id23 + 1] == '-') w = -1, id23 ++;
        for (int i = id23 + 1; i < id24; i ++) {
            a3 = a3 * 10 + s[2][i] - '0';
        }
        a3 *= w;
    }
//=============================================================================
//第二层循环的处理
    int id31 = s[3].find ('('), id32 = s[3].find (',', id31);
    if (id32 - id31 == 2 && s[3][id31 + 1] == c1) {
        ok1 = 1;
    } else {
        for (int i = id31 + 1; i < id32; i ++) {
            b1 = b1 * 10 + s[3][i] - '0';
        }
    }
    int id33 = s[3].find (',', id32 + 1);
    if (id33 == -1) {
        int id34 = s[3].find (')', id32);
        if (id34 - id32 == 2 && s[3][id32 + 1] == c1) {
            ok2 = 1;
        } else {
            for (int i = id32 + 1; i < id34; i ++) {
                b2 = b2 * 10 + s[3][i] - '0';
            }
        }
    } else {
        if (id33 - id32 == 2 && s[3][id32 + 1] == c1) {
            ok2 = 1;
        } else {
             for (int i = id32 + 1; i < id33; i ++) {
                b2 = b2 * 10 + s[3][i] - '0';
            }
        }

        b3 = 0;
        int id34 = s[3].find (')', id32);
        if (id34 - id33 == 2 && s[3][id33 + 1] == c1) {
            ok3 = 1;
        } else {
            int w = 1;
            if (s[3][id33 + 1] == '-') w = -1, id33 ++;
            for (int i = id33 + 1; i < id34; i ++) {
                b3 = b3 * 10 + s[3][i] - '0';
            }
            b3 *= w;
        }
    }

    auto work = [&] (int x, int y, int z) -> int {
        if (x >= y && z > 0) return 0;
        if (x <= y && z < 0) return 0;
        int l = 0, r = 1e6;
        auto check = [&] (int t) -> bool {
            if (x > y) {
                return x + t * z > y;
            } else {
                return x + t * z < y;
            }
        };
        while (l < r) {
            int mid = l + r + 1 >> 1;
            if (check (mid)) l = mid;
            else r = mid - 1;
        }
        int n = l + 1;
        //cerr << n << "\n";
        int a1 = x, d = z;
        return n * a1 + n * (n - 1) * d / 2; 
    };

    int ans = 0;
    if (a3 > 0) {
        for (int i = a1; i < a2; i += a3) {
            int c1 = b1, c2 = b2, c3 = b3;
            if (ok1) c1 = i;
            if (ok2) c2 = i;
            if (ok3) c3 = i;
            ans += work (c1, c2, c3);
        }
    } else {
        for (int i = a1; i > a2; i += a3) {
            int c1 = b1, c2 = b2, c3 = b3;
            if (ok1) c1 = i;
            if (ok2) c2 = i;
            if (ok3) c3 = i;
            ans += work (c1, c2, c3);
        }
    }

    printf ("%lld\n", ans);
}

signed main () {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
	int TT = 1; 
//	TT = read ();
	while (TT --) solve ();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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: 55ms
memory: 3732kb

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: 6ms
memory: 3988kb

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: 45ms
memory: 3728kb

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