Submission #65509092


Source Code Expand

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <atcoder/all>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repk(i, k, n) for (int i = k; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define mod1 1000000007
#define mod2 998244353
#define mod3 100000007
#define vi vector<int>
#define vs vector<string>
#define vc vector<char>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vvc vector<vector<char>>
#define vvl vector<vector<ll>>
#define vvb vector<vector<bool>>
#define vvvi vector<vector<vector<int>>>
#define vvvl vector<vector<vector<ll>>>
#define pii pair<int, int>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define vvpii vector<vector<pair<int, int>>>
#define vvpll vector<vector<pair<ll, ll>>>

using mint = modint998244353;

template <typename T>
void debug(T e) {
    cerr << e << endl;
}

template <typename T>
void debug(vector<T> &v) {
    rep(i, v.size()) { cerr << v[i] << " "; }
    cerr << endl;
}

template <typename T>
void debug(vector<vector<T>> &v) {
    rep(i, v.size()) {
        rep(j, v[i].size()) { cerr << v[i][j] << " "; }
        cerr << endl;
    }
}

template <typename T>
void debug(vector<pair<T, T>> &v) {
    rep(i, v.size()) { cerr << v[i].first << " " << v[i].second << endl; }
}

template <typename T>
void debug(set<T> &st) {
    for (auto itr = st.begin(); itr != st.end(); itr++) {
        cerr << *itr << " ";
    }
    cerr << endl;
}

template <typename T>
void debug(multiset<T> &ms) {
    for (auto itr = ms.begin(); itr != ms.end(); itr++) {
        cerr << *itr << " ";
    }
    cerr << endl;
}

template <typename T>
void debug(map<T, T> &mp) {
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        cerr << itr->first << " " << itr->second << endl;
    }
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << H << " ";
    debug_out(T...);
}

struct S {
    ll num;
};

S op(S a, S b) {
    return S{a.num + b.num};
}

S e() { return S{0}; }

// index が条件を満たすかどうか
bool isOK(int index, int key, segtree<S, op, e> &seg) {
    ll sm = seg.prod(0, index + 1).num; // [0, index] の区間和を取得
    if (sm >= key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(int key, segtree<S, op, e> &seg) {
    int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int right = 2800000; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
    
    /* どんな二分探索でもここの書き方を変えずにできる! */
    while (right - left > 1) {
        int mid = left + (right - left) / 2;

        if (isOK(mid, key, seg)) right = mid;
        else left = mid;
    }
    
    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}

int main() {
    ll Q;
    cin >> Q;
    ll size = 2800000;
    vector<ll> A(size);
    for (ll i = 0; i < size; i++) {
        A[i] = 1;
    }
    A[0] = 0;


    segtree<S, op, e> seg(size);
    for (ll i = 0; i < size; i++) {
        seg.set(i, S{A[i]});
    }

    ll a, b;
    for (ll i = 0; i < Q; i++) {
        cin >> a >> b;

        if (a >= size || seg.get(a).num == 0){

        }else{
            for (ll j = a; j < size; j+=a){
                seg.set(j, S{0});
            }
        }

        ll ans = binary_search(b, seg);
        cout << ans << endl;

    }


}

Submission Info

Submission Time
Task C - Removal of Multiples
User nikuroll
Language C++ 20 (gcc 12.2)
Score 600
Code Size 4377 Byte
Status AC
Exec Time 2895 ms
Memory 112700 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 1
AC × 40
Set Name Test Cases
Sample 01_sample_01.txt
All 01_sample_01.txt, 02_small_AB_01.txt, 02_small_AB_02.txt, 02_small_AB_03.txt, 02_small_AB_04.txt, 02_small_AB_05.txt, 03_rand_1_01.txt, 03_rand_1_02.txt, 03_rand_1_03.txt, 03_rand_1_04.txt, 03_rand_1_05.txt, 04_rand_2_01.txt, 04_rand_2_02.txt, 04_rand_2_03.txt, 04_rand_2_04.txt, 04_rand_2_05.txt, 05_rand_3_01.txt, 05_rand_3_02.txt, 05_rand_3_03.txt, 05_rand_3_04.txt, 05_rand_3_05.txt, 06_rand_4_01.txt, 06_rand_4_02.txt, 06_rand_4_03.txt, 06_rand_4_04.txt, 06_rand_4_05.txt, 06_rand_4_06.txt, 06_rand_4_07.txt, 06_rand_4_08.txt, 06_rand_4_09.txt, 06_rand_4_10.txt, 06_rand_4_11.txt, 06_rand_4_12.txt, 06_rand_4_13.txt, 06_rand_4_14.txt, 06_rand_4_15.txt, 06_rand_4_16.txt, 07_max_ans_01.txt, 07_max_ans_02.txt, 07_max_ans_03.txt
Case Name Status Exec Time Memory
01_sample_01.txt AC 168 ms 112508 KiB
02_small_AB_01.txt AC 602 ms 112480 KiB
02_small_AB_02.txt AC 620 ms 112596 KiB
02_small_AB_03.txt AC 515 ms 112464 KiB
02_small_AB_04.txt AC 541 ms 112536 KiB
02_small_AB_05.txt AC 551 ms 112452 KiB
03_rand_1_01.txt AC 369 ms 112536 KiB
03_rand_1_02.txt AC 370 ms 112404 KiB
03_rand_1_03.txt AC 374 ms 112512 KiB
03_rand_1_04.txt AC 372 ms 112512 KiB
03_rand_1_05.txt AC 374 ms 112528 KiB
04_rand_2_01.txt AC 560 ms 112448 KiB
04_rand_2_02.txt AC 568 ms 112604 KiB
04_rand_2_03.txt AC 544 ms 112432 KiB
04_rand_2_04.txt AC 537 ms 112612 KiB
04_rand_2_05.txt AC 542 ms 112460 KiB
05_rand_3_01.txt AC 465 ms 112452 KiB
05_rand_3_02.txt AC 487 ms 112536 KiB
05_rand_3_03.txt AC 466 ms 112700 KiB
05_rand_3_04.txt AC 486 ms 112560 KiB
05_rand_3_05.txt AC 475 ms 112460 KiB
06_rand_4_01.txt AC 830 ms 112604 KiB
06_rand_4_02.txt AC 948 ms 112484 KiB
06_rand_4_03.txt AC 803 ms 112448 KiB
06_rand_4_04.txt AC 862 ms 112524 KiB
06_rand_4_05.txt AC 891 ms 112428 KiB
06_rand_4_06.txt AC 952 ms 112532 KiB
06_rand_4_07.txt AC 900 ms 112428 KiB
06_rand_4_08.txt AC 946 ms 112512 KiB
06_rand_4_09.txt AC 804 ms 112532 KiB
06_rand_4_10.txt AC 889 ms 112532 KiB
06_rand_4_11.txt AC 2810 ms 112452 KiB
06_rand_4_12.txt AC 2895 ms 112524 KiB
06_rand_4_13.txt AC 1099 ms 112448 KiB
06_rand_4_14.txt AC 1187 ms 112444 KiB
06_rand_4_15.txt AC 1217 ms 112508 KiB
06_rand_4_16.txt AC 1277 ms 112428 KiB
07_max_ans_01.txt AC 817 ms 112536 KiB
07_max_ans_02.txt AC 804 ms 112700 KiB
07_max_ans_03.txt AC 843 ms 112608 KiB