QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#551417#9255. Python Programucup-team3699#AC ✓59ms3824kbC++202.7kb2024-09-07 16:49:032024-09-07 16:49:06

Judging History

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

  • [2024-09-07 16:49:06]
  • 评测
  • 测评结果:AC
  • 用时:59ms
  • 内存:3824kb
  • [2024-09-07 16:49:03]
  • 提交

answer

#include<iostream>
#include<vector>
#include<queue>
#include<set>
using namespace std;
#define int long long
#define INF 1e18
void parse(string s, int &a, int &b, int &c){
    int cnt = 0;
    bool oka = 0, okb = 0, okc = 0;
    int now = 1;
    for (int i = 1; i < s.size(); i++){
        if(s[i] == ',' || s[i] == ')'){
            int val;
            if(i - 1 == now && !('0' <= s[i - 1] && s[i - 1] <= '9'))
                val = INF;
            else
                val = stoi(s.substr(now, i - now));
            if(!oka)
                a = val, oka = 1;
            else if(!okb)
                b = val, okb = 1;
            else
                c = val, okc = 1;
            now = i + 1;
        }
    }
    if(!okc)
        c = 1;
}
int sum(int a, int b, int c){
    // cout << a << " " << b << " " << c << " ";
    int n = 0;
    if(c > 0){
        if(a >= b)
            return 0;
        for (int j = 1e9; j; j >>= 1){
            while(a + c * (n + j) < b)
                n += j;
        }
        // cout << n << "\n";
    }
    else{
        if(a <= b)
            return 0;
        for (int j = 1e9; j; j >>= 1){
            while(a + c * (n + j) > b)
                n += j;
        }
        // cout << n << "\n";        
    }
    n++;
    return (2 * a + (n - 1) * c) * n / 2;
}
void solve(){
    string s;
    cin >> s;
    cin.ignore();
    getline(cin, s);
    char f1 = s[4];
    int l, r;
    for (int i = 0; i < s.size(); i++){
        if(s[i] == '(')
            l = i;
        if(s[i] == ')')
            r = i;
    }
    s = s.substr(l, r - l + 1);
    int a, b, c;
    parse(s, a, b, c);
    // cout << a << " " << b << " " << c << "\n";
    getline(cin, s);
    for (int i = 0; i < s.size(); i++){
        if(s[i] == '(')
            l = i;
        if(s[i] == ')')
            r = i;
    }
    s = s.substr(l, r - l + 1);
    int d, e, f;
    parse(s, d, e, f);
    // cout << d << " " << e << " " << f << "\n";
    int ans = 0;
    if(c < 0){
        for (int i = a; i > b; i += c){
            int nd = (d == INF ? i : d);
            int ne = (e == INF ? i : e);
            int nf = (f == INF ? i : f);
            ans += sum(nd, ne, nf);
            // cout << ans << "\n";
        }
    }
    else{
        for (int i = a; i < b; i += c){
            int nd = (d == INF ? i : d);
            int ne = (e == INF ? i : e);
            int nf = (f == INF ? i : f);
            ans += sum(nd, ne, nf);
        }
    }
    cout << ans << "\n";
}
signed main(){
    ios_base::sync_with_stdio(0), cin.tie(0);
    int t = 1;
    // cin >> t;
    while(t--)
        solve();
    return 0;
}

詳細信息

Test #1:

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

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

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: 59ms
memory: 3816kb

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

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: 53ms
memory: 3820kb

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