/ SeriousOJ /

Record Detail

System Error


  
# Status Time Cost Memory Cost
#1 System Error terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc 2ms 720.0 KiB
#2 System Error terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc 1ms 556.0 KiB
#3 System Error terminate called after throwing an instance of 'std::length_error' what(): cannot create std::vector larger than max_size() 1ms 652.0 KiB
#4 Memory Exceeded ≥150ms ≥250.016 MiB
#5 System Error terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc 1ms 560.0 KiB
#6 System Error terminate called after throwing an instance of 'std::length_error' what(): cannot create std::vector larger than max_size() 2ms 560.0 KiB
#7 System Error terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc 1ms 556.0 KiB
#8 System Error terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc 1ms 540.0 KiB
#9 System Error terminate called after throwing an instance of 'std::length_error' what(): cannot create std::vector larger than max_size() 1ms 552.0 KiB
#10 System Error terminate called after throwing an instance of 'std::length_error' what(): cannot create std::vector larger than max_size() 1ms 556.0 KiB
#11 Memory Exceeded ≥155ms ≥250.016 MiB
#12 System Error terminate called after throwing an instance of 'std::length_error' what(): cannot create std::vector larger than max_size() 1ms 560.0 KiB

Code

/*
 *   Copyright (c) 2024 Emon Thakur
 *   All rights reserved.
 */

#include<bits/stdc++.h>
using namespace std;
ofstream file("output11.txt");
bool cmp(int a,int b) {return a>b;}
bool cmp2(pair<int,int>a,pair<int,int>b)
{
    if(a.first==b.first) return a.second<b.second;
    return a>b;
}
void solve1()
{
    int n; cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a.begin(),a.end(),cmp);

    int m; cin>>m;
    vector<pair<int,int>>b(m);
    for(int i=0;i<m;i++) cin>>b[i].first, b[i].second=i;
    sort(b.begin(),b.end(),cmp2);
    //for(auto e:b) cout<<e.first<<" "<<e.second<<endl;
    int lo=0,hi=n-1,mid,ind;
    int ans[m];
    for(int i=0;i<m;i++)
    {
        int num = b[i].first;
        lo = 0,hi=n-1,ind=0;
        while(lo<=hi)
        {
            mid=(lo+hi)/2;
            if(a[mid]>=num)
            {
                ind=mid+1;
                lo=mid+1;
            }
            else hi=mid-1;
        }
        ans[b[i].second] = ind+1+i;
    }
    for(int i=0;i<m;i++) file<<ans[i]<<" ";
}

void solve2()
{
    int n,x; cin>>n;
    vector<pair<int,int>>v;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        v.push_back({x,-1});
    }

    int m; cin>>m;
    for(int i=0;i<m;i++)
    {
        cin>>x;
        v.push_back({x,i});
    }

    sort(v.begin(),v.end(),cmp2);
    int ans[m];
    for(int i=0;i<n+m;i++)
    {
        if(v[i].second!=-1) ans[v[i].second]=i+1;
    }
    for(int i=0;i<m;i++) file<<ans[i]<<" ";
}

int main()
{
    freopen("input11.txt","r",stdin);
    solve1();
}

Information

Submit By
Type
Submission
Problem
P1049 Combined scoreboard
Language
C++20 (G++ 13.2.0)
Submit At
2024-04-07 21:36:35
Judged At
2024-04-07 21:36:35
Judged By
Score
0
Total Time
155ms
Peak Memory
250.016 MiB