結果
| 問題 |
No.789 範囲の合計
|
| コンテスト | |
| ユーザー |
AC2K
|
| 提出日時 | 2023-03-28 12:38:50 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 69 ms / 1,000 ms |
| コード長 | 2,348 bytes |
| コンパイル時間 | 3,282 ms |
| コンパイル使用メモリ | 257,644 KB |
| 実行使用メモリ | 6,656 KB |
| 最終ジャッジ日時 | 2024-09-20 03:10:47 |
| 合計ジャッジ時間 | 5,087 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 |
ソースコード
#line 1 "test/yuki/No-789_BIT.test.cpp"
#define PROBLEM "https://yukicoder.me/problems/no/789"
#line 2 "template.hpp"
#include<bits/stdc++.h>
using namespace std;
#define rep(i, N) for(int i=0;i<(N);i++)
#define all(x) (x).begin(),(x).end()
#define popcount(x) __builtin_popcount(x)
using i128=__int128_t;
using ll = long long;
using ld = long double;
using graph = vector<vector<int>>;
using P = pair<int, int>;
constexpr int inf = 1e9;
constexpr ll infl = 1e18;
constexpr ld eps = 1e-6;
const long double pi = acos(-1);
constexpr uint64_t MOD = 1e9 + 7;
constexpr uint64_t MOD2 = 998244353;
constexpr int dx[] = { 1,0,-1,0 };
constexpr int dy[] = { 0,1,0,-1 };
template<class T>static constexpr inline void chmax(T&x,T y){if(x<y)x=y;}
template<class T>static constexpr inline void chmin(T&x,T y){if(x>y)x=y;}
#line 1 "data-structure/BIT.hpp"
/// @brief Binary Index Tree
/// @tparam Type 要素の型
/// @tparam SumType "和が" 収まるような型
/// @docs docs/data-structure/BIT.md
template <typename Type, typename SumType = Type>
class BIT {
int _n;
vector<SumType> _dat;
public:
explicit BIT(int _n) : _n(_n), _dat(_n, SumType()) {}
inline void add(int p, Type v) {
p++;
for (; p <= _n; p += p & (-p)) {
_dat[p - 1] += SumType(v);
}
}
inline SumType sum(int p) {
SumType res = 0;
for (; p > 0; p -= p & -p) {
res += _dat[p - 1];
}
return res;
}
inline SumType sum(int l, int r) { return sum(r) - sum(l); }
};
#line 5 "test/yuki/No-789_BIT.test.cpp"
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
ll s = 0;
vector<int> idx;
idx.reserve(2 * n);
vector<tuple<int, int, int>> query(n);
for (auto& [t, a, b] : query) {
cin >> t >> a >> b;
idx.emplace_back(a);
if (t == 1) idx.emplace_back(b);
}
sort(all(idx));
idx.erase(unique(all(idx)), idx.end());
BIT<ll> sg(2 * n + 1);
for (auto& [t, a, b] : query) {
if (t == 0) {
a = lower_bound(all(idx), a) - idx.begin();
sg.add(a, b);
} else {
a = lower_bound(all(idx), a) - idx.begin();
b = lower_bound(all(idx), b) - idx.begin();
s += sg.sum(a, b + 1);
}
}
cout << s << '\n';
}
AC2K