結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー
提出日時 2022-10-15 00:13:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 638 ms / 6,000 ms
コード長 7,874 bytes
コンパイル時間 1,363 ms
コンパイル使用メモリ 130,172 KB
実行使用メモリ 39,044 KB
最終ジャッジ日時 2023-09-09 01:07:40
合計ジャッジ時間 25,409 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 245 ms
28,712 KB
testcase_04 AC 421 ms
32,684 KB
testcase_05 AC 234 ms
21,144 KB
testcase_06 AC 378 ms
31,240 KB
testcase_07 AC 442 ms
34,144 KB
testcase_08 AC 414 ms
33,108 KB
testcase_09 AC 198 ms
19,700 KB
testcase_10 AC 186 ms
18,468 KB
testcase_11 AC 310 ms
21,820 KB
testcase_12 AC 311 ms
22,032 KB
testcase_13 AC 212 ms
18,948 KB
testcase_14 AC 233 ms
11,092 KB
testcase_15 AC 480 ms
35,368 KB
testcase_16 AC 374 ms
34,076 KB
testcase_17 AC 168 ms
10,692 KB
testcase_18 AC 600 ms
38,724 KB
testcase_19 AC 614 ms
39,032 KB
testcase_20 AC 605 ms
38,768 KB
testcase_21 AC 612 ms
38,720 KB
testcase_22 AC 600 ms
38,748 KB
testcase_23 AC 615 ms
38,864 KB
testcase_24 AC 621 ms
38,788 KB
testcase_25 AC 635 ms
38,872 KB
testcase_26 AC 611 ms
39,008 KB
testcase_27 AC 604 ms
38,768 KB
testcase_28 AC 604 ms
38,772 KB
testcase_29 AC 627 ms
38,788 KB
testcase_30 AC 638 ms
38,768 KB
testcase_31 AC 620 ms
39,044 KB
testcase_32 AC 598 ms
39,028 KB
testcase_33 AC 523 ms
38,672 KB
testcase_34 AC 518 ms
38,696 KB
testcase_35 AC 513 ms
38,764 KB
testcase_36 AC 500 ms
38,672 KB
testcase_37 AC 512 ms
38,724 KB
testcase_38 AC 158 ms
10,824 KB
testcase_39 AC 231 ms
14,192 KB
testcase_40 AC 434 ms
38,700 KB
testcase_41 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdint>
#include <cmath>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cassert>
using namespace std;
namespace atcoder{};using namespace atcoder;

using ull = uint64_t;
using ll = int64_t;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using ld = long double;
using P = pair<ll,ll>;
using G = vector<vector<int>>;

#ifdef MYDEBUG
template<class C> string join(const C& c){stringstream ss; for(auto it=c.begin(); it!=c.end();it++){ss << *it;if(it!=c.end())ss<<", ";}return ss.str();}
template<class C> ostream &operator<<(ostream &os, const vector<C>& c){for(auto it=c.begin(); it!=c.end();it++){os << *it;if(it!=c.end())os<<", ";}return os;}
#define LO(...) fprintf(stderr, __VA_ARGS__)
#define debug(x) cerr << "\033[33m(line:" << __LINE__ << ") " << #x << ": " << x << "\033[m" << endl
#else
#define LO(...) (void)0
#define debug(x) (void)0
#endif

#define reps(i,a,n) for(ll i##_len = (ll)(n), i = (a); i < i##_len; ++i)
#define rep(i,n) reps(i,0,n)
#define rrep(i,n) reps(i,1,n+1)
#define repd(i,n) for(ll i=n-1;i>=0;i--)
#define rrepd(i,n) for(ll i=n;i>=1;i--)

#define inp(i) ll i; cin >> i;
#define inps(s) string s; cin >> s;
#define inpp(p) cin >> (p).first >> (p).second
#define inpv(v,N) vll v(N);rep(i,N)cin>>v[i];
#define inpg(g,N,M) g.resize(N);rep(i,M){inp(a);inp(b);a--,b--;g[a].push_back(b);g[b].push_back(a);}
#define all(v) begin(v),end(v)
#define YESNO(b) cout<<(b?"YES\n":"NO\n")
#define yesno(b) cout<<(b?"yes\n":"no\n")
#define YesNo(b) cout<<(b?"Yes\n":"No\n")
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define yes cout<<"yes\n"
#define no cout<<"no\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"

#define SP cout << " "
#define ENDL cout << "\n"
#define ou(i) cout << (i)
#define ous(i) cout << (i) << " "
#define oul(i) cout << (i) << "\n"
#define setfp() cout << fixed << setprecision(16)

template<typename C> void ouv(const C &v){for(auto &&e:v){cout << e;if(&e != &v.back()) cout << ' ';}cout << "\n";}
template<typename C> void ouvadd(const C &v){for(auto &&e:v){cout << e+1;if(&e != &v.back()) cout << ' ';}cout << "\n";}

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

inline ll lg(ll __n) { return sizeof(ll) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }

int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};

constexpr ll INF = 1e18;

#ifndef ATCODER_SEGTREE_HPP
#define ATCODER_SEGTREE_HPP 1

#include <algorithm>
#include <cassert>
#include <vector>

#ifndef ATCODER_INTERNAL_BITOP_HPP
#define ATCODER_INTERNAL_BITOP_HPP 1

#ifdef _MSC_VER
#include <intrin.h>
#endif

namespace atcoder {

namespace internal {

// @param n `0 <= n`
// @return minimum non-negative `x` s.t. `n <= 2**x`
int ceil_pow2(int n) {
    int x = 0;
    while ((1U << x) < (unsigned int)(n)) x++;
    return x;
}

// @param n `1 <= n`
// @return minimum non-negative `x` s.t. `(n & (1 << x)) != 0`
constexpr int bsf_constexpr(unsigned int n) {
    int x = 0;
    while (!(n & (1 << x))) x++;
    return x;
}

// @param n `1 <= n`
// @return minimum non-negative `x` s.t. `(n & (1 << x)) != 0`
int bsf(unsigned int n) {
#ifdef _MSC_VER
    unsigned long index;
    _BitScanForward(&index, n);
    return index;
#else
    return __builtin_ctz(n);
#endif
}

}  // namespace internal

}  // namespace atcoder

#endif  // ATCODER_INTERNAL_BITOP_HPP

namespace atcoder {

template <class S, S (*op)(S, S), S (*e)()> struct segtree {
  public:
    segtree() : segtree(0) {}
    explicit segtree(int n) : segtree(std::vector<S>(n, e())) {}
    explicit segtree(const std::vector<S>& v) : _n(int(v.size())) {
        log = internal::ceil_pow2(_n);
        size = 1 << log;
        d = std::vector<S>(2 * size, e());
        for (int i = 0; i < _n; i++) d[size + i] = v[i];
        for (int i = size - 1; i >= 1; i--) {
            update(i);
        }
    }

    void set(int p, S x) {
        assert(0 <= p && p < _n);
        p += size;
        d[p] = x;
        for (int i = 1; i <= log; i++) update(p >> i);
    }

    S get(int p) const {
        assert(0 <= p && p < _n);
        return d[p + size];
    }

    S prod(int l, int r) const {
        assert(0 <= l && l <= r && r <= _n);
        S sml = e(), smr = e();
        l += size;
        r += size;

        while (l < r) {
            if (l & 1) sml = op(sml, d[l++]);
            if (r & 1) smr = op(d[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return op(sml, smr);
    }

    S all_prod() const { return d[1]; }

    template <bool (*f)(S)> int max_right(int l) const {
        return max_right(l, [](S x) { return f(x); });
    }
    template <class F> int max_right(int l, F f) const {
        assert(0 <= l && l <= _n);
        assert(f(e()));
        if (l == _n) return _n;
        l += size;
        S sm = e();
        do {
            while (l % 2 == 0) l >>= 1;
            if (!f(op(sm, d[l]))) {
                while (l < size) {
                    l = (2 * l);
                    if (f(op(sm, d[l]))) {
                        sm = op(sm, d[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = op(sm, d[l]);
            l++;
        } while ((l & -l) != l);
        return _n;
    }

    template <bool (*f)(S)> int min_left(int r) const {
        return min_left(r, [](S x) { return f(x); });
    }
    template <class F> int min_left(int r, F f) const {
        assert(0 <= r && r <= _n);
        assert(f(e()));
        if (r == 0) return 0;
        r += size;
        S sm = e();
        do {
            r--;
            while (r > 1 && (r % 2)) r >>= 1;
            if (!f(op(d[r], sm))) {
                while (r < size) {
                    r = (2 * r + 1);
                    if (f(op(d[r], sm))) {
                        sm = op(d[r], sm);
                        r--;
                    }
                }
                return r + 1 - size;
            }
            sm = op(d[r], sm);
        } while ((r & -r) != r);
        return 0;
    }

  private:
    int _n, size, log;
    std::vector<S> d;

    void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
};

}  // namespace atcoder

#endif  // ATCODER_SEGTREE_HPP
ll op(ll a, ll b){return a+b;}
ll e(){return 0;}
using SEG = atcoder::segtree<ll,op,e>;

int main(){
    inp(N);
    vll A(N),T(N);
    rep(i,N)cin>>A[i]>>T[i];

    inp(Q);
    vector<pair<P,P>> q(Q+N*2);
    rep(i,Q){
        cin >> q[i].first.first >> q[i].second.first >> q[i].second.second;
        q[i].second.first--;
        q[i].first.second = i;
    }
    rep(i,N){
        q[Q+i].first.first = T[i];
        q[Q+i].first.second = -3;
        q[Q+i].second.first = i;
        q[Q+N+i].first.first = T[i] + A[i];
        q[Q+N+i].first.second = -2;
        q[Q+N+i].second.first = i;
    }
    sort(all(q));

    SEG fi(N),se(N),ti(N);
    rep(i,N){
        fi.set(i,A[i]);
    }

    ll prev_time = 0;
    vll ans(Q);
    rep(i,N+N+Q){
        auto [a,b] = q[i].first;
        auto [c,d] = q[i].second;

        if(b == -3){
            se.set(c, 1);
            ti.set(c, a);
        }else if(b == -2){
            se.set(c, 0);
            ti.set(c, 0);
            fi.set(c, 0);
        }else{
            ll tot = fi.prod(c, d);
            ll count = se.prod(c, d);
            ll timetot = ti.prod(c, d);
            debug(a);
            debug(tot);
            debug(count);
            debug(timetot);
            ans[b] = tot + (timetot - count * (a+1));
        }
    }
    rep(i,Q){
        oul(ans[i]);
    }


    return 0;
}
0