Submission #1087076

# Submission time Handle Problem Language Result Execution time Memory
1087076 2024-09-12T07:39:25 Z Dennis_Jason Intercastellar (JOI22_ho_t1) C++14
25 / 100
155 ms 64040 KB
#include <bitset>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <system_error>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#define pb push_back
#define MOD 1000000007
#define NMAX 200001
#define MAX 1000000
#define nl '\n'
#define pii1 pair<int, pair<int,int>>  (1,(1,2));
#define pii pair<int,int>
#define tpl tuple<int,int,int>
#define int long long
using namespace std;
ifstream fin("data.in");
ofstream fout("data.out");
const int INF=1e12;
/*
    ====================DEMONSTRATION======================


    =========================END===========================

 */
int n;
vector<int>v;
int q;
map<int,int>mp;
int greatestOddFactor(int n)
{
    int pow_2 = (int)(log(n));
    int i = 1;
    while (i <= pow_2)
    {
        int fac_2 = (2 * i);
        if (n % fac_2 == 0)
        {
            if ((n / fac_2) % 2 == 1)
            {
                return (fac_2);
            }
        }
        i++;
    }
    return -1;
}
void prec()
{
    for(int i=2;i<=MAX;i+=2)
    {
        mp[i]= greatestOddFactor(i);
    }
}
signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    prec();
    cin>>n;
    v.resize(n+1);
    vector<int>aux(n+1);
    vector<int>div(n+1);
    for(int i=1;i<=n;++i)
    {
        cin>>v[i];
        if(v[i]%2==0) {
            if(mp[v[i]]==-1)
                mp[v[i]]=v[i];
            aux[i] = mp[v[i]];
            div[i] = v[i] / mp[v[i]];
        }
        else
        {
            aux[i]=1;
            div[i]=v[i];
        }
    }
    cin>>q;
    for(int i=1;i<=n;++i)
    {
//        cout<<div[i]<<" ";
        aux[i]+=aux[i-1];
    }
    for(int i=1;i<=q;++i)
    {
        int x;
        cin>>x;
        int st=1;
        int dr=n;
        int res;
        while(st<=dr)
        {
            int mid=(st+dr)/2;
            if(aux[mid]>=x && aux[mid-1]<x)
            {
                res=mid;
                break;
            }
            if(aux[mid]<x)
                st=mid+1;
            else
                dr=mid-1;
        }
        cout<<div[res]<<nl;

    }





    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:122:22: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
  122 |         cout<<div[res]<<nl;
      |                      ^
# Verdict Execution time Memory Grader output
1 Correct 96 ms 31720 KB Output is correct
2 Correct 103 ms 31572 KB Output is correct
3 Correct 128 ms 36944 KB Output is correct
4 Correct 118 ms 34132 KB Output is correct
5 Correct 139 ms 38484 KB Output is correct
6 Correct 131 ms 36712 KB Output is correct
7 Correct 148 ms 38552 KB Output is correct
8 Correct 155 ms 38484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 31616 KB Output is correct
2 Correct 100 ms 31736 KB Output is correct
3 Runtime error 106 ms 64040 KB Execution killed with signal 8
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 96 ms 31720 KB Output is correct
2 Correct 103 ms 31572 KB Output is correct
3 Correct 128 ms 36944 KB Output is correct
4 Correct 118 ms 34132 KB Output is correct
5 Correct 139 ms 38484 KB Output is correct
6 Correct 131 ms 36712 KB Output is correct
7 Correct 148 ms 38552 KB Output is correct
8 Correct 155 ms 38484 KB Output is correct
9 Correct 97 ms 31616 KB Output is correct
10 Correct 100 ms 31736 KB Output is correct
11 Runtime error 106 ms 64040 KB Execution killed with signal 8
12 Halted 0 ms 0 KB -