結果
| 問題 |
No.789 範囲の合計
|
| コンテスト | |
| ユーザー |
YDK1727
|
| 提出日時 | 2019-03-03 11:55:26 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,817 bytes |
| コンパイル時間 | 1,912 ms |
| コンパイル使用メモリ | 180,128 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-23 13:10:05 |
| 合計ジャッジ時間 | 3,449 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 7 WA * 8 |
ソースコード
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr>void dump(Itr begin, Itr end) {
for(;begin != end; ++begin) clog << ' ' << *begin;
clog << LF;
}
struct FenwickTree {
const int N;
vector<i64> dat;
explicit FenwickTree(int n): N(n), dat(N+1, 0) {}
i64 sum(int l, int r) { return sum(r) - sum(l-1); }
i64 sum(int i) { return (i>0)? (sum(i - (i&-i)) + dat[i]) : 0; }
void add(int i, i64 v) { for(; i <= N; i += i&-i) dat[i] += v; }
};
using P = tuple<int, int, int>;
int N;
P query[100100];
vector<int> points;
inline int index(int orgIndex) { return lower_bound(ALL(points), orgIndex) - points.begin(); }
signed main()
{
iostreamBooster();
cin >> N;
for (int i = 0; i < N; ++i) {
int a, b, c; cin >> a >> b >> c;
query[i] = make_tuple(a, b, c);
if (a) {
points.push_back(b);
} else {
points.push_back(b);
points.push_back(c);
}
}
points.push_back(0);
points.push_back(-1);
points.push_back(1'000'000'001);
sort(ALL(points));
points.erase(unique(ALL(points)), points.end());
FenwickTree ft(points.size() + 5);
i64 ans = 0;
for (int i = 0; i < N; ++i) {
int com, a, b;
tie(com, a, b) = query[i];
if (com == 0) {
ft.add(index(a), b);
} else {
const i64 tmp = ft.sum(index(a), index(b));
ans += tmp;
}
}
cout << ans << endl;
return 0;
}
YDK1727