結果

問題 No.3101 Range Eratosthenes Query
コンテスト
ユーザー detteiuu
提出日時 2025-10-26 19:36:13
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 215 ms / 3,000 ms
コード長 2,405 bytes
コンパイル時間 5,501 ms
コンパイル使用メモリ 334,060 KB
実行使用メモリ 18,788 KB
最終ジャッジ日時 2025-10-26 19:36:27
合計ジャッジ時間 13,463 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

#define pass (void)0
#define INF (1<<30)-1
#define INFLL (1LL<<60)-1
#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 rep2(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define repr2(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define YesNo(cond) cout << ((cond) ? "Yes\n" : "No\n")
#define YESNO(cond) cout << ((cond) ? "YES\n" : "NO\n")

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;

template <typename T> void print(const T& value) { cout << value << "\n"; }
template <typename T> void print(const vector<T>& vec) { for (auto& v : vec) cout << v << " "; cout << "\n"; }
template <typename T> void input(vector<T>& vec) { for (auto& v : vec) cin >> v; };
template <typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }

#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using vm = vector<mint>;

bool compare(tuple<int, int, int> left, tuple<int, int, int> right) {
    return get<1>(left) < get<1>(right);
}

int op(int left, int right) { return left+right; }
int e() { return 0; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);

    int Q;
    cin >> Q;
    vector<tuple<int, int, int>> query;
    rep (i, Q) {
        int L, R;
        cin >> L >> R;
        query.push_back({i, L, R});
    }
    sort(rall(query), compare);

    vi B(1000001, 1);
    segtree<int, op, e> seg(B);
    vi ans(Q, -1);
    int idx = 1000000;
    rep (i, Q) {
        int qidx, L, R;
        qidx = get<0>(query[i]);
        L = get<1>(query[i]);
        R = get<2>(query[i]);
        while (L <= idx) {
            int j = idx*2;
            while (j <= 1000000) {
                if (seg.get(j) == 1) seg.set(j, 0);
                j += idx;
            }
            idx --;
        }
        ans[qidx] = seg.prod(L, R+1);
    }

    for (auto a : ans) print(a);
}
0