結果

問題 No.2101 [Cherry Alpha N] ずっとこの数列だったらいいのに
ユーザー hourenhouren
提出日時 2022-10-14 22:28:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 247 ms / 6,000 ms
コード長 1,833 bytes
コンパイル時間 3,278 ms
コンパイル使用メモリ 182,188 KB
実行使用メモリ 20,380 KB
最終ジャッジ日時 2023-09-08 22:38:18
合計ジャッジ時間 17,652 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,500 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 109 ms
11,332 KB
testcase_04 AC 171 ms
15,308 KB
testcase_05 AC 98 ms
10,716 KB
testcase_06 AC 157 ms
14,328 KB
testcase_07 AC 178 ms
16,000 KB
testcase_08 AC 169 ms
15,372 KB
testcase_09 AC 85 ms
9,508 KB
testcase_10 AC 77 ms
9,264 KB
testcase_11 AC 125 ms
12,152 KB
testcase_12 AC 128 ms
12,468 KB
testcase_13 AC 88 ms
9,668 KB
testcase_14 AC 93 ms
9,832 KB
testcase_15 AC 199 ms
17,488 KB
testcase_16 AC 155 ms
14,520 KB
testcase_17 AC 67 ms
7,924 KB
testcase_18 AC 240 ms
20,192 KB
testcase_19 AC 240 ms
20,128 KB
testcase_20 AC 241 ms
20,064 KB
testcase_21 AC 242 ms
20,064 KB
testcase_22 AC 241 ms
20,256 KB
testcase_23 AC 247 ms
20,300 KB
testcase_24 AC 243 ms
20,220 KB
testcase_25 AC 240 ms
20,208 KB
testcase_26 AC 239 ms
20,220 KB
testcase_27 AC 241 ms
20,192 KB
testcase_28 AC 240 ms
20,256 KB
testcase_29 AC 240 ms
20,196 KB
testcase_30 AC 242 ms
20,380 KB
testcase_31 AC 241 ms
20,124 KB
testcase_32 AC 239 ms
20,216 KB
testcase_33 AC 223 ms
20,308 KB
testcase_34 AC 223 ms
20,220 KB
testcase_35 AC 223 ms
20,192 KB
testcase_36 AC 222 ms
20,204 KB
testcase_37 AC 224 ms
20,308 KB
testcase_38 AC 62 ms
10,860 KB
testcase_39 AC 104 ms
11,412 KB
testcase_40 AC 175 ms
20,036 KB
testcase_41 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:57:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   57 |     for(auto [d,l,r,i]:query){
      |              ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using T = tuple<ll,ll,ll,int>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}
template <typename T>
struct BIT{
    int n;
    vector<T> data;
    BIT(int n=0) : n(n), data(n+1){}
    T sum(int i){
        T res = 0;
        for(; i; i -= i&-i){
            res += data[i];
        }
        return res;
    }
    void add(int i, T x){
        for(; i <= n; i += i&-i){
            data[i] += x;
        }
    }
};
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,q;
    cin >> n;
    BIT<ll> bit(n), ok(n);
    vector<P> a(n), t(n);
    rep(i,n){
        cin >> a[i].first >> t[i].first;
        t[i].first--;
        bit.add(i+1, a[i].first);
        a[i].first += t[i].first;
        a[i].second = t[i].second = i+1;
    }
    sort(all(a));
    sort(all(t));
    cin >> q;
    vector<ll> ans(q);
    vector<T> query(q);
    rep(i,q){
        ll d,l,r;
        cin >> d >> l >> r;
        l--;
        query[i] = {d,l,r,i};
    }
    sort(all(query));
    int nb = 0, ne = 0;
    for(auto [d,l,r,i]:query){
        while(nb<n && t[nb].first<d){
            ok.add(t[nb].second, 1);
            bit.add(t[nb].second, t[nb].first);
            nb++;
        }
        while(ne<n && a[ne].first<d){
            ok.add(a[ne].second, -1);
            bit.add(a[ne].second, -a[ne].first);
            ne++;
        }
        ans[i] = (bit.sum(r) - bit.sum(l)) - d * (ok.sum(r) - ok.sum(l));
    }
    rep(i,q) cout << ans[i] << '\n';
    return 0;
}
0