QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#658300#9255. Python ProgramVegetog#AC ✓76ms3860kbC++204.3kb2024-10-19 16:36:112024-10-19 16:36:12

Judging History

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

  • [2024-10-19 16:36:12]
  • 评测
  • 测评结果:AC
  • 用时:76ms
  • 内存:3860kb
  • [2024-10-19 16:36:11]
  • 提交

answer

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

void solve()
{
    vector<string> a(12);
    for(int i=1;i<=11;i++){
        cin>>a[i];
    }

    // 5 9
    int ans=0;
    int v=0;
    int l1=-1,r1=-1,t1=1;
    int f1=1;
    for(int i=0;i<a[5].size();i++){
        if(a[5][i]=='-') f1=-1;
        if('0'<=a[5][i]&&a[5][i]<='9'){
            v=v*10+(a[5][i]-'0');
        }else if(a[5][i]==')'||a[5][i]==','){
            if(l1==-1){
                l1=v;
            }else if(r1==-1){
                r1=v;
            }else{
                t1=v*f1;
            }
            v=0;
        }
    }

    v=0;
    int l2=-1,r2=-1,t2=1;
    int f2=1;
    for(int i=0;i<a[9].size();i++){
        if(a[9][i]=='-') f2=-1;
        if('0'<=a[9][i]&&a[9][i]<='9'){
            v=v*10+(a[9][i]-'0');
        }else if(a[9][i]==')'||a[9][i]==','){
            if(l2==-1){
                l2=v;
            }else if(r2==-1){
                r2=v;
            }else{
                t2=v*f2;
            }
            v=0;
        }
    }
    bool va1=0,va2=0,va3=0;
    int nd=0;
    for(int i=6;i<a[9].size();i++){
        if(a[9][i]==',') nd++;
        if(a[3][0]==a[9][i]){
            if(nd==0){
                va1=1;
            }else if(nd==1){
                va2=1;
            }else if(nd==2){
                va3=1;
            }
        }
    }
    if(t1>0){
        while(l1<r1){
            if(va1) l2=l1;
            if(va2) r2=l1;
            if(va3) t2=l1;
            int L,R,T;
            if(t2>0){
                L=l2;
                R=r2-1;
                if(L>R){
                    l1+=t1;
                    continue;
                }
                // T=t2;
                int l=0,r=1e9;
                while(l<r){
                    int mid=(l+r+1)/2;
                    if(L+mid*t2<=R){
                        l=mid;
                    }else{
                        r=mid-1;
                    }
                }
                ans+=(L+L+l*t2)*(l+1)/2;
                // cout<<L<<" "<<L+l*t2<<" "<<l-1<<"\n";
            }else{
                L=r2+1;
                R=l2;
                if(L>R){
                    l1+=t1;
                    continue;
                }
                // T=-t2;
                int l=0,r=1e9;
                while(l<r){
                    int mid=(l+r+1)/2;
                    if(R+mid*t2>=L){
                        l=mid;
                    }else{
                        r=mid-1;
                    }
                }
                ans+=(R+R+l*t2)*(l+1)/2;
                // cout<<R<<" "<<R+l*t2<<" "<<l-1<<"\n";
            }
            // cout<<L<<" "<<R<<"\n";
            l1+=t1;         
        }
    }else{
        while(l1>r1){
            if(va1) l2=l1;
            if(va2) r2=l1;
            if(va3) t2=l1;
            int L,R,T;
            if(t2>0){
                L=l2;
                R=r2-1;
                if(L>R){
                    l1+=t1;
                    continue;
                }
                // T=t2;
                int l=0,r=1e9;
                while(l<r){
                    int mid=(l+r+1)/2;
                    if(L+mid*t2<=R){
                        l=mid;
                    }else{
                        r=mid-1;
                    }
                }
                ans+=(L+L+l*t2)*(l+1)/2;
                // cout<<L<<" "<<L+l*t2<<" "<<l-1<<"\n";
            }else{
                L=r2+1;
                R=l2;
                if(L>R){
                    l1+=t1;
                    continue;
                }
                // T=-t2;
                int l=0,r=1e9;
                while(l<r){
                    int mid=(l+r+1)/2;
                    if(R+mid*t2>=L){
                        l=mid;
                    }else{
                        r=mid-1;
                    }
                }
                ans+=(R+R+l*t2)*(l+1)/2;
                // cout<<R<<" "<<R+l*t2<<" "<<l-1<<"\n";
            }
            l1+=t1;
        }
    }

    cout<<ans<<"\n";
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(nullptr),cout.tie(nullptr);

    int T=1;
    // cin>>T;
    while(T--){
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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

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

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