제출 #1299321

#제출 시각아이디문제언어결과실행 시간메모리
1299321quan606303Intercastellar (JOI22_ho_t1)C++20
100 / 100
55 ms6844 KiB
/*
 * @Author: RMQuan 
 * @Date: 2025-12-05 09:56:25 
 * @Last Modified by: RMQuan
 * @Last Modified time: 2025-12-05 10:19:23
 */
/*idea : 



*/
#include <bits/stdc++.h>
bool M1;
#define int long long
#define ll long long
#define INTMAX INT_MAX
#define INTMIN INT_MIN
#define LONGMAX LLONG_MAX
#define LONGMIN LLONG_MIN
#define fi first
#define se second
#define memfull(a,b) memset(a,b,sizeof(a));
#define endl '\n'
#define TASK "TEST"
#define file() if (fopen(TASK".inp","r")){freopen(TASK".inp","r",stdin); freopen(TASK".out","w",stdout);}
using namespace std;
const int MOD=1e9+7;
const int maxn=2e5+7;
int n,q,a[maxn],cnt[maxn],val[maxn]; 
pair<int,int> cal(int x)
{
    int l=0,r=30;
    int ans=0;
    while (l<=r)
    {
        int mid=(l+r)/2;
        int tam=(1LL<<mid);
        if (x%tam==0)
        {
            ans=mid;
            l=mid+1;
        }
        else r=mid-1;
    }
    return {(1LL<<ans), x/(1LL<<ans)};
}
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    file();
    cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    for (int i=1;i<=n;i++)
    {
        pair<int,int> tmp=cal(a[i]);
        cnt[i]=tmp.fi;
        val[i]=tmp.se;
      //  cerr<<cnt[i]<<" "<<val[i]<<endl;
        cnt[i]=cnt[i-1]+cnt[i];
    }   
    cin>>q;
    while (q--)
    {
        int x;
        cin>>x;
        auto it=lower_bound(cnt+1,cnt+n+1,x)-cnt;
        cout<<val[it]<<endl;
    }
   
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int32_t main()':
Main.cpp:25:50: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 | #define file() if (fopen(TASK".inp","r")){freopen(TASK".inp","r",stdin); freopen(TASK".out","w",stdout);}
      |                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:52:5: note: in expansion of macro 'file'
   52 |     file();
      |     ^~~~
Main.cpp:25:81: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 | #define file() if (fopen(TASK".inp","r")){freopen(TASK".inp","r",stdin); freopen(TASK".out","w",stdout);}
      |                                                                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:52:5: note: in expansion of macro 'file'
   52 |     file();
      |     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...