답안 #576228

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
576228 2022-06-12T16:26:57 Z Aldas25 Intercastellar (JOI22_ho_t1) C++14
100 / 100
103 ms 12376 KB
/*
//#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
*/

#include <bits/stdc++.h>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 500100, MAXK = 20;
const ll INF = 1e14;
//const ll MOD = 1e9+7;
const ll MOD = 998244353;

void setIO()
{
    FAST_IO;
}

void setIO(string s)
{
    FAST_IO;
    freopen((s+".in").c_str(), "r", stdin);
    freopen((s+".out").c_str(), "w", stdout);
}

int n, q;
ll a[MAXN];
ll val[MAXN], cnt[MAXN], pref[MAXN];

int main()
{
    setIO();

    cin >> n;
    FOR(i, 1, n) cin >> a[i];

    FOR(i, 1, n) {
        val[i] = a[i];
        while (val[i]%2 == 0) {
            val[i] /= 2;
        }
        cnt[i] = a[i] / val[i];
        pref[i] = pref[i-1] + cnt[i];
    }

    cin >> q;
    while (q--) {
        ll x; cin >> x;
        int le = 1, ri = n;
        while (le < ri) {
            int m = (le+ri)/2;
            if (pref[m] >= x) ri = m;
            else le = m+1;
        }

        cout << val[le] << "\n";
    }

    return 0;
}

Compilation message

Main.cpp: In function 'void setIO(std::string)':
Main.cpp:38:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     freopen((s+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:39:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     freopen((s+".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 22 ms 6996 KB Output is correct
4 Correct 35 ms 3148 KB Output is correct
5 Correct 64 ms 8704 KB Output is correct
6 Correct 29 ms 6640 KB Output is correct
7 Correct 56 ms 8652 KB Output is correct
8 Correct 53 ms 8780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 22 ms 6996 KB Output is correct
4 Correct 35 ms 3148 KB Output is correct
5 Correct 64 ms 8704 KB Output is correct
6 Correct 29 ms 6640 KB Output is correct
7 Correct 56 ms 8652 KB Output is correct
8 Correct 53 ms 8780 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 31 ms 3528 KB Output is correct
24 Correct 45 ms 7452 KB Output is correct
25 Correct 68 ms 11936 KB Output is correct
26 Correct 44 ms 7504 KB Output is correct
27 Correct 43 ms 7796 KB Output is correct
28 Correct 103 ms 12376 KB Output is correct
29 Correct 90 ms 11852 KB Output is correct
30 Correct 45 ms 4172 KB Output is correct
31 Correct 86 ms 12252 KB Output is correct