結果
| 問題 |
No.789 範囲の合計
|
| コンテスト | |
| ユーザー |
emthrm
|
| 提出日時 | 2019-03-11 01:43:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,412 bytes |
| コンパイル時間 | 1,514 ms |
| コンパイル使用メモリ | 128,076 KB |
| 最終ジャッジ日時 | 2025-01-06 22:02:33 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 TLE * 7 |
ソースコード
#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
const int INF = 0x3f3f3f3f, MOD = 1000000007;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*-----------------------------------------*/
template <typename T>
vector<T> compress(vector<T> &x) {
int sz = x.size();
vector<T> xs;
REP(i, sz) xs.emplace_back(x[i]);
sort(ALL(xs));
xs.erase(unique(ALL(xs)), xs.end());
return xs;
}
template <typename Abelian, const Abelian UNITY>
struct BIT {
BIT(int sz_) {
sz = sz_ + 1;
dat.assign(sz, 0);
}
void add(int idx, Abelian value) {
while (idx < sz) {
dat[idx] += value;
idx += idx & -idx;
}
}
Abelian sum(int idx) {
Abelian res = 0;
while (idx > 0) {
res += dat[idx];
idx -= idx & -idx;
}
return res;
}
int lower_bound(Abelian value) {
if (value <= 0) return 0;
int res = 0, exponent = 1;
while (exponent < sz) exponent <<= 1;
for (int mask = exponent >> 1; mask > 0; mask >>= 1) {
if (res + mask < sz && dat[res + mask] < value) {
value -= dat[res + mask];
res += mask;
}
}
return res + 1;
}
private:
int sz;
vector<Abelian> dat;
};
int main() {
cin.tie(0); ios::sync_with_stdio(false);
// freopen("input.txt", "r", stdin);
int n; cin >> n;
vector<int> q(n), l(n), r(n), coordinates;
REP(i, n) {
cin >> q[i] >> l[i] >> r[i];
coordinates.emplace_back(l[i]);
if (q[i] == 1) coordinates.emplace_back(r[i]);
}
vector<int> x = compress(coordinates);
BIT<long long, 0> bit(x.size());
long long ans = 0;
REP(i, n) {
l[i] = lower_bound(ALL(x), l[i]) - x.begin();
if (q[i] == 0) {
bit.add(l[i], r[i]);
} else {
r[i] = lower_bound(ALL(x), r[i]) - x.begin();
ans += bit.sum(r[i]) - (l[i] > 0 ? bit.sum(l[i] - 1) : 0);
}
}
cout << ans << '\n';
return 0;
}
emthrm