QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#550222#9255. Python Programucup-team635#AC ✓3ms2248kbRust3.2kb2024-09-07 10:55:292024-09-07 10:55:29

Judging History

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

  • [2024-09-07 10:55:29]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:2248kb
  • [2024-09-07 10:55:29]
  • 提交

answer

use std::collections::*;
use std::io::Write;

type Map<K, V> = BTreeMap<K, V>;
type Set<T> = BTreeSet<T>;
type Deque<T> = VecDeque<T>;

fn main() {
    read();
    let parse = |s: &[u8]| -> Option<i64> {
        let mut sign = 1;
        let mut x = 0;
        if s[x] == b'-' {
            sign = -1;
            x += 1;
        }
        if !(b'0' <= s[x] && s[x] <= b'9') {
            return None;
        }
        let mut val = 0;
        while x < s.len() {
            assert!(b'0' <= s[x] && s[x] <= b'9');
            val = 10 * val + (s[x] - b'0') as i64;
            x += 1;
        }
        Some(val * sign)
    };
    let for_range = |s: Vec<u8>| -> (Vec<u8>, (i64, Vec<u8>), (i64, Vec<u8>), (i64, Vec<u8>)) {
        let mut p = 0;
        while s[p] == b' ' {
            p += 1;
        }
        while s[p] != b' ' {
            p += 1;
        }
        let l = p + 1;
        p += 1;
        while s[p] != b' ' {
            p += 1;
        }
        let i = Vec::from(&s[l..p]);
        while s[p] != b'(' {
            p += 1;
        }
        let l = p + 1;
        p += 1;
        while s[p] != b',' {
            p += 1;
        }
        let mut a = (0, vec![]);
        if let Some(v) = parse(&s[l..p]) {
            a.0 = v;
        } else {
            a.1 = Vec::from(&s[l..p]);
        }
        let a = a;
        let l = p + 1;
        p += 1;
        while s[p] != b',' && s[p] != b')' {
            p += 1;
        }
        let mut b = (0, vec![]);
        if let Some(v) = parse(&s[l..p]) {
            b.0 = v;
        } else {
            b.1 = Vec::from(&s[l..p]);
        }
        let b = b;
        let mut c = (0, vec![]);
        if s[p] == b')' {
            c.0 = 1;
        } else {
            let l = p + 1;
            p += 1;
            while s[p] != b')' {
                p += 1;
            }
            if let Some(v) = parse(&s[l..p]) {
                c.0 = v;
            } else {
                c.1 = Vec::from(&s[l..p]);
            }
        }
        (i, a, b, c)
    };
    let (i, (a, _), (b, _), (c, _)) = for_range(read().bytes().collect::<Vec<_>>());
    let (_j, d, e, f) = for_range(read().bytes().collect::<Vec<_>>());
    let mut ans = 0;
    let mut x = a;
    while (c > 0 && x < b) || (c < 0 && x > b) {
        let val = |p: &(i64, Vec<u8>)| {
            if p.1.is_empty() {
                p.0
            } else {
                x
            }
        };
        let (d, e, f) = (val(&d), val(&e), val(&f));
        /*
        let mut y = d;
        while (f > 0 && y < e) || (f < 0 && y > e) {
            ans += y;
            y += f;
        }
        */
        if f > 0 {
            if d < e {
                let len = (e - d - 1) / f + 1;
                ans += d * len + len * (len - 1) / 2 * f;
            }
        } else if f < 0 {
            if d > e {
                let len = (d - e - 1) / -f + 1;
                ans += d * len + len * (len - 1) / 2 * f;
            }
        }
        x += c;
    }
    println!("{ans}");
}

fn read() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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: 0ms
memory: 2136kb

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

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