提出 #65508200


ソースコード 拡げる

#line 2 "/Users/korogi/Desktop/cp-cpp/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using i32 = int;
using i64 = long long;
using i128 = __int128;
using u32 = unsigned int;
using u64 = unsigned long long;
using u128 = unsigned __int128;
using f32 = double;
using f64 = long double;
using f128 = __float128;

#define DMP(x) cout << "[" << __LINE__ << "]" << " " << #x << ":" << " " << x << endl;

#define FOR1(n)          for(int _ =  0 , n_ = (n); _ < n_; _++)
#define FOR2(i, n)       for(int i =  0 , n_ = (n); i < n_; i++)
#define FOR3(i, s, t)    for(int i = (s), t_ = (t); i < t_; i++)
#define FOR4(i, s, t, d) for(int i = (s), t_ = (t), d_ = (d); i < t_; i += d_)
#define OVERLOAD4(a, b, c, d, e, ...) e
#define FOR(...) OVERLOAD4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)

#define REV1(n)          for(int _ = (n) - 1; _ >=  0 ; _--)
#define REV2(i, n)       for(int i = (n) - 1; i >=  0 ; i--)
#define REV3(i, s, t)    for(int i = (t) - 1, s_ = (s); i >= s_; i--)
#define REV4(i, s, t, d) for(int i = (t) - 1, s_ = (s), d_ = (d); i >= s_; i -= d_)
#define OVERLOAD3(a, b, c, d, ...) d
#define REV(...) OVERLOAD4(__VA_ARGS__, REV4, REV3, REV2, REV1)(__VA_ARGS__)

#define FOR_SUBSET(T, S) for(int S_ = (S), T = S_; T >= 0; T = (T == 0 ? -1 : (T - 1) & S_))

#define MULTI for(int testcase_ = in(), testcase = 0; testcase < testcase_; testcase++) [&]

template < class T > using heap_max = priority_queue< T, vector< T >, less< T > >;
template < class T > using heap_min = priority_queue< T, vector< T >, greater< T >>;

template < class T, class U > bool chmin(T& a, const U& b) { return a > b ? a = b, 1 : 0; }
template < class T, class U > bool chmax(T& a, const U& b) { return a < b ? a = b, 1 : 0; }

i64 floor_div(const i64 n, const i64 d) { assert(d != 0); return n / d - ((n ^ d) <  0 && n % d != 0); }
i64  ceil_div(const i64 n, const i64 d) { assert(d != 0); return n / d + ((n ^ d) >= 0 && n % d != 0); }

template < class T, class F > T bin_search(T ok, T ng, F check) { while(abs(ok - ng) > 1) { T mid = (ok + ng) / 2; (check(mid) ? ok : ng) = mid; } return ok; }
template < class T, class F > T bin_search_real(T ok, T ng, F check, int step = 100) { FOR(step) { T mid = (ok + ng) / 2; (check(mid) ? ok : ng) = mid; } return ok; }

template < class T, class U > T accum(const vector< U >& a) { return accumulate(a.begin(), a.end(), T(0)); }
template < class T > pair< T, int > min(const vector< T >& a) { auto itr = min_element(a.begin(), a.end()); return {*itr, itr - a.begin()}; }
template < class T > pair< T, int > max(const vector< T >& a) { auto itr = max_element(a.begin(), a.end()); return {*itr, itr - a.begin()}; }
template < class T > void sort(vector< T >& a) { sort(a.begin(), a.end()); }
template < class T > void rsort(vector< T >& a) { sort(a.rbegin(), a.rend()); }
template < class T > void reverse(vector< T >& a) { reverse(a.begin(), a.end()); }
void sort(string& s) { sort(s.begin(), s.end()); }
void rsort(string& s) { sort(s.rbegin(), s.rend()); }
void reverse(string& s) { reverse(s.begin(), s.end()); }
template < class T, class Cmp > void sort(vector< T >& a, Cmp cmp) { sort(a.begin(), a.end(), cmp); }
template < class T > int LB(vector< T >& a, T x) { return distance(a.begin(), lower_bound(a.begin(), a.end(), x)); }
template < class T > int UB(vector< T >& a, T x) { return distance(a.begin(), upper_bound(a.begin(), a.end(), x)); }
template < class T > void unique(vector< T >& a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }
vector<int> iota(int n) { vector<int> a(n); iota(a.begin(), a.end(), 0); return a; }

istream& operator >> (istream& is, i128& x) {
    string s; is >> s;
    int m = (s[0] == '-');
    x = 0;
    FOR(i, m, ssize(s)) x = x * 10 + (s[i] - '0');
    if(m) x *= -1;
    return is;
}
ostream& operator << (ostream& os, const i128& x) {
    if(x == 0) return os << '0';
    i128 y = x; if(y < 0) { os << '-'; y *= -1; }
    vector<int> ny;
    while(y) ny.push_back(y % 10), y /= 10;
    REV(i, ssize(ny)) os << ny[i];
    return os;
}
namespace scan {
struct x0 { template < class T > operator T() { T x; cin >> x; return x; } };
struct x1 { int n; x1(int n) : n(n) {} template < class T > operator vector< T >() { vector< T > a(n); for(T& x : a) cin >> x; return a; } };
struct x2 { int h, w; x2(int h, int w) : h(h), w(w) {} template < class T > operator vector< vector< T > >() { vector m(h, vector< T >(w)); for(vector< T >& a : m) for(T& x : a) cin >> x; return m; } };
struct cppio { cppio() { cin.tie(0); ios::sync_with_stdio(0); } } cppio_instance;
}
scan::x0 in() { return scan::x0(); }
scan::x1 in(int n) { return scan::x1(n); }
scan::x2 in(int h, int w) { return scan::x2(h, w); }

template < class T > ostream& operator << (ostream& os, const vector< T > a) {
    const int n = a.size();
    FOR(i, n) { os << a[i]; if(i + 1 != n) os << ' '; }
    return os;
}
template < class T > int print_n(const vector< T > a) { for(T x : a) cout << x << '\n'; return 0; }
int print() { cout << '\n'; return 0; }
template < class Head, class... Tail > int print(Head&& h, Tail&&... t) { cout << h; if(sizeof...(Tail)) cout << ' '; return print(forward<Tail>(t)...); }
namespace printer {
    void prec(int n) { cout << fixed << setprecision(n); }
    void flush() { cout.flush(); }
}

constexpr pair<int, int> dir4[] = {{-1, 0}, {0, -1}, {+1, 0}, {0, +1}};

vector<int>& operator ++ (vector<int>& a) { for(auto& e : a) e++; return a; }
vector<int>& operator -- (vector<int>& a) { for(auto& e : a) e--; return a; }
vector<int>  operator ++ (vector<int>& a, int) { vector<int> b = a; ++a; return b; }
vector<int>  operator -- (vector<int>& a, int) { vector<int> b = a; --a; return b; }

template < class T > vector<pair< T, int>> RLE(const vector< T >& a) { vector<pair< T, int>> v; for(const T& x : a) { if(not v.empty() and v.back().first == x) v.back().second++; else v.emplace_back(x, 1); } return v; }
vector<pair<char, int>> RLE(const string& s) { vector<pair<char, int>> v; for(const char& c : s) { if(not v.empty() and v.back().first == c) v.back().second++; else v.emplace_back(c, 1); } return v; }
template < class String, class Same > vector<String> RLE(const String& a, const Same same) { vector<String> v; for(const auto& x : a) { if(not v.empty() and same(v.back().back(), x)) v.back().push_back(x); else v.push_back({x}); } return v; }

int YESNO(bool yes) { return print(yes ? "YES" : "NO"); }
int YesNo(bool yes) { return print(yes ? "Yes" : "No"); }

constexpr i32 INF32 = 1e9;
constexpr i64 INF64 = 1e18;
#line 2 "a.cpp"

// https://nyaannyaan.github.io/library/data-structure/binary-indexed-tree.hpp.html
template <typename T>
struct BinaryIndexedTree {
  int N;
  vector<T> data;

  BinaryIndexedTree() = default;

  BinaryIndexedTree(int size) { init(size); }

  void init(int size) {
    N = size + 2;
    data.assign(N + 1, {});
  }

  // get sum of [0,k]
  T sum(int k) const {
    if (k < 0) return T{};  // return 0 if k < 0
    T ret{};
    for (++k; k > 0; k -= k & -k) ret += data[k];
    return ret;
  }

  // getsum of [l,r]
  inline T sum(int l, int r) const { return sum(r) - sum(l - 1); }

  // get value of k
  inline T operator[](int k) const { return sum(k) - sum(k - 1); }

  // data[k] += x
  void add(int k, T x) {
    for (++k; k < N; k += k & -k) data[k] += x;
  }

  // range add x to [l,r]
  void imos(int l, int r, T x) {
    add(l, x);
    add(r + 1, -x);
  }

  // minimize i s.t. sum(i) >= w
  int lower_bound(T w) {
    if (w <= 0) return 0;
    int x = 0;
    for (int k = 1 << __lg(N); k; k >>= 1) {
      if (x + k <= N - 1 && data[x + k] < w) {
        w -= data[x + k];
        x += k;
      }
    }
    return x;
  }

  // minimize i s.t. sum(i) > w
  int upper_bound(T w) {
    if (w < 0) return 0;
    int x = 0;
    for (int k = 1 << __lg(N); k; k >>= 1) {
      if (x + k <= N - 1 && data[x + k] <= w) {
        w -= data[x + k];
        x += k;
      }
    }
    return x;
  }
};

const int M = 3'000'000;

int main() {
    vector<int> alive(M + 1, 1);
    BinaryIndexedTree<int> S(M + 1);
    for(int x = 1; x <= M; x++) S.add(x, +1);

    int Q = in();
    FOR(Q) {
        int a = in(), b = in();
        if(a <= M and alive[a]) {
            for(int x = a; x <= M; x += a) {
                if(alive[x]) {
                    S.add(x, -1);
                    alive[x] = 0;
                }
            }
        }
        print(S.lower_bound(b));
    }
}

提出情報

提出日時
問題 C - Removal of Multiples
ユーザ Rogi
言語 C++ 20 (gcc 12.2)
得点 600
コード長 8652 Byte
結果 AC
実行時間 225 ms
メモリ 26640 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 1
AC × 40
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
01_sample_01.txt AC 51 ms 26472 KiB
02_small_AB_01.txt AC 121 ms 26460 KiB
02_small_AB_02.txt AC 118 ms 26504 KiB
02_small_AB_03.txt AC 108 ms 26528 KiB
02_small_AB_04.txt AC 113 ms 26640 KiB
02_small_AB_05.txt AC 113 ms 26616 KiB
03_rand_1_01.txt AC 62 ms 26512 KiB
03_rand_1_02.txt AC 62 ms 26524 KiB
03_rand_1_03.txt AC 63 ms 26548 KiB
03_rand_1_04.txt AC 62 ms 26612 KiB
03_rand_1_05.txt AC 64 ms 26548 KiB
04_rand_2_01.txt AC 107 ms 26420 KiB
04_rand_2_02.txt AC 112 ms 26620 KiB
04_rand_2_03.txt AC 105 ms 26436 KiB
04_rand_2_04.txt AC 103 ms 26456 KiB
04_rand_2_05.txt AC 110 ms 26532 KiB
05_rand_3_01.txt AC 88 ms 26552 KiB
05_rand_3_02.txt AC 89 ms 26476 KiB
05_rand_3_03.txt AC 91 ms 26404 KiB
05_rand_3_04.txt AC 86 ms 26528 KiB
05_rand_3_05.txt AC 88 ms 26456 KiB
06_rand_4_01.txt AC 113 ms 26564 KiB
06_rand_4_02.txt AC 129 ms 26504 KiB
06_rand_4_03.txt AC 143 ms 26604 KiB
06_rand_4_04.txt AC 148 ms 26600 KiB
06_rand_4_05.txt AC 136 ms 26448 KiB
06_rand_4_06.txt AC 152 ms 26504 KiB
06_rand_4_07.txt AC 138 ms 26548 KiB
06_rand_4_08.txt AC 154 ms 26548 KiB
06_rand_4_09.txt AC 108 ms 26504 KiB
06_rand_4_10.txt AC 125 ms 26596 KiB
06_rand_4_11.txt AC 220 ms 26468 KiB
06_rand_4_12.txt AC 225 ms 26476 KiB
06_rand_4_13.txt AC 159 ms 26424 KiB
06_rand_4_14.txt AC 176 ms 26408 KiB
06_rand_4_15.txt AC 176 ms 26452 KiB
06_rand_4_16.txt AC 190 ms 26436 KiB
07_max_ans_01.txt AC 112 ms 26480 KiB
07_max_ans_02.txt AC 140 ms 26528 KiB
07_max_ans_03.txt AC 144 ms 26464 KiB