結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー milanis48663220milanis48663220
提出日時 2022-10-14 23:02:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,350 ms / 6,000 ms
コード長 3,257 bytes
コンパイル時間 3,536 ms
コンパイル使用メモリ 140,136 KB
実行使用メモリ 87,456 KB
最終ジャッジ日時 2023-09-08 23:27:06
合計ジャッジ時間 48,178 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 626 ms
54,272 KB
testcase_04 AC 926 ms
68,048 KB
testcase_05 AC 531 ms
43,812 KB
testcase_06 AC 828 ms
63,972 KB
testcase_07 AC 996 ms
71,816 KB
testcase_08 AC 880 ms
67,024 KB
testcase_09 AC 448 ms
40,116 KB
testcase_10 AC 370 ms
36,356 KB
testcase_11 AC 614 ms
47,912 KB
testcase_12 AC 617 ms
48,092 KB
testcase_13 AC 426 ms
38,092 KB
testcase_14 AC 386 ms
26,908 KB
testcase_15 AC 1,072 ms
76,320 KB
testcase_16 AC 907 ms
69,204 KB
testcase_17 AC 257 ms
23,432 KB
testcase_18 AC 1,316 ms
87,340 KB
testcase_19 AC 1,328 ms
87,272 KB
testcase_20 AC 1,291 ms
87,324 KB
testcase_21 AC 1,262 ms
87,224 KB
testcase_22 AC 1,312 ms
87,100 KB
testcase_23 AC 1,306 ms
87,112 KB
testcase_24 AC 1,316 ms
87,132 KB
testcase_25 AC 1,320 ms
87,112 KB
testcase_26 AC 1,338 ms
87,192 KB
testcase_27 AC 1,290 ms
87,280 KB
testcase_28 AC 1,350 ms
87,396 KB
testcase_29 AC 1,326 ms
87,260 KB
testcase_30 AC 1,346 ms
87,392 KB
testcase_31 AC 1,339 ms
87,132 KB
testcase_32 AC 1,334 ms
87,128 KB
testcase_33 AC 1,245 ms
87,456 KB
testcase_34 AC 1,229 ms
87,352 KB
testcase_35 AC 1,230 ms
87,096 KB
testcase_36 AC 1,223 ms
87,136 KB
testcase_37 AC 1,206 ms
87,392 KB
testcase_38 AC 144 ms
27,988 KB
testcase_39 AC 253 ms
28,016 KB
testcase_40 AC 213 ms
35,920 KB
testcase_41 AC 1 ms
4,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/segtree>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

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

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}


template<typename T>
class Cumsum{
    public:
    Cumsum(vector<T> v): v(v){
        n = v.size();
        v_cumsum = vector<T>(n+1, T(0));
        for(int i = 0; i < n; i++) v_cumsum[i+1] = v_cumsum[i]+v[i];
    }
    /**
     * v[l] + ... + v[r-1]
     */ 
    T sum(int l, int r){
        if(r <= l) return T(0);
        if(r > n) r = n;
        if(l < 0) l = 0;
        return v_cumsum[r]-v_cumsum[l];
    }
    private:
    int n;
    vector<T> v;
    vector<T> v_cumsum;
};

ll op(ll x, ll y){
    return x+y;
}

ll e(){
    return 0;
}

using Seg = atcoder::segtree<ll, op, e>;
using T = tuple<int, int, int>;

const int START_DEC = -10;
const int START_ZERO = -5;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    vector<ll> a(n);
    vector<ll> t(n);
    for(int i = 0; i < n; i++) cin >> a[i] >> t[i];
    map<int, vector<T>> queries;
    int q; cin >> q;
    for(int i = 0; i < q; i++){
        int d, l, r; cin >> d >> l >> r; l--;
        queries[d].push_back(T(l, r, i));
    }
    for(int i = 0; i < n; i++){
        queries[t[i]].push_back(T(START_DEC, i, -1));
        queries[t[i]+a[i]].push_back(T(START_ZERO, i, -1));
    }
    Seg same(a);
    Seg dec(n);
    Seg dec_cnt(n);
    vector<ll> ret(q);
    for(auto [d, qs]: queries){
        sort(qs.begin(), qs.end());
        // cout << "=== " << d << endl;
        for(auto tup: qs){
            if(get<2>(tup) == -1){
                auto [tp, i, _] = tup;
                if(tp == START_DEC){
                    same.set(i, 0);
                    dec.set(i, a[i]+t[i]-1);
                    dec_cnt.set(i, 1);
                }else{
                    dec.set(i, 0);
                    dec_cnt.set(i, 0);
                }
            }else{
                auto [l, r, i] = tup;
                ll ans = same.prod(l, r);
                ans += dec.prod(l, r);
                ans -= dec_cnt.prod(l, r)*d;
                ret[i] = ans;
            }
        }
    }
    print_vector(ret, '\n');
}
0