結果

問題 No.789 範囲の合計
ユーザー yuruhiyayuruhiya
提出日時 2020-01-15 22:51:04
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 1,000 ms
コード長 1,352 bytes
コンパイル時間 1,127 ms
コンパイル使用メモリ 79,592 KB
実行使用メモリ 5,000 KB
最終ジャッジ日時 2023-09-02 21:38:23
合計ジャッジ時間 2,710 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 31 ms
4,764 KB
testcase_03 AC 17 ms
4,552 KB
testcase_04 AC 29 ms
4,940 KB
testcase_05 AC 20 ms
4,936 KB
testcase_06 AC 23 ms
4,744 KB
testcase_07 AC 13 ms
4,744 KB
testcase_08 AC 23 ms
4,892 KB
testcase_09 AC 20 ms
4,948 KB
testcase_10 AC 31 ms
4,612 KB
testcase_11 AC 17 ms
5,000 KB
testcase_12 AC 17 ms
4,940 KB
testcase_13 AC 2 ms
4,372 KB
testcase_14 AC 1 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
inline int gc()noexcept { return getchar_unlocked(); }
inline int input()noexcept {
	int v = 0; char c = gc();
	for (; isdigit(c); c = gc()) {
		v *= 10;
		v += c - '0';
    }
	return v;
}
using LL = long long;

const int MAX_N = 100005;
int m, bit[MAX_N];
inline void add(int i, int x)noexcept {
    while(i <= m) {
        bit[i] += x;
        i += i & -i;
    }
}
inline int sum(int i)noexcept {
    int res = 0;
    while (i > 0) {
        res += bit[i];
        i -= i & -i;
    }
    return res;
}

bool f[MAX_N];
int a[MAX_N], b[MAX_N], v[MAX_N];

int main() {
    int n = input();
    rep(i, n) {
        f[i] = gc() == '1'; gc();
        a[i] = input();
        b[i] = input();
    }
    
    rep(i, n)if (!f[i]) {
        v[m++] = a[i];
    }
    sort(v, v + m);
    m = unique(v, v + m) - v;
    
    LL ans = 0;
    rep(i, n) {
        if (!f[i]) {
            int pos = lower_bound(v, v + m, a[i]) - v;
            add(pos + 1, b[i]);
        } else {
            int l = lower_bound(v, v + m, a[i]) - v;
            int r = upper_bound(v, v + m, b[i]) - v;
            ans += sum(r) - sum(l);
        }
    }
    printf("%lld\n", ans);
}
0