結果
問題 | No.789 範囲の合計 |
ユーザー |
![]() |
提出日時 | 2019-02-08 22:43:13 |
言語 | C++14 (gcc 11.2.0 + boost 1.78.0) |
結果 |
AC
|
実行時間 | 48 ms / 1,000 ms |
コード長 | 1,422 bytes |
コンパイル時間 | 1,328 ms |
使用メモリ | 6,144 KB |
最終ジャッジ日時 | 2023-02-01 16:57:10 |
合計ジャッジ時間 | 2,992 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,156 KB |
testcase_01 | AC | 2 ms
4,904 KB |
testcase_02 | AC | 45 ms
5,948 KB |
testcase_03 | AC | 42 ms
5,352 KB |
testcase_04 | AC | 41 ms
6,064 KB |
testcase_05 | AC | 40 ms
5,884 KB |
testcase_06 | AC | 43 ms
5,992 KB |
testcase_07 | AC | 38 ms
5,156 KB |
testcase_08 | AC | 40 ms
5,548 KB |
testcase_09 | AC | 38 ms
5,780 KB |
testcase_10 | AC | 48 ms
6,144 KB |
testcase_11 | AC | 42 ms
5,952 KB |
testcase_12 | AC | 44 ms
5,992 KB |
testcase_13 | AC | 2 ms
4,908 KB |
testcase_14 | AC | 1 ms
5,156 KB |
ソースコード
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; using ll = long long; struct P { int t, x, y; }; struct BIT { BIT(int n) : b(n + 1), n(n) {} void add(int i, int v) { for (int k = i + 1; k <= n; k += k & -k) b[k] += v; } int sum(int k) { int s = 0; for (; k > 0; k -= k & -k) s += b[k]; return s; } vector<int> b; int n; }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<P> p(n); int m = n; for (int i = 0; i < n; i++) { cin >> p[i].t >> p[i].x >> p[i].y; if (p[i].t == 1) p[i].y++, m++; } vector<pair<int, int>> t(m); int j = 0; for (int i = 0; i < n; i++) { t[j++] = { p[i].x, i * 2 }; if (p[i].t == 1) t[j++] = { p[i].y, i * 2 + 1 }; } sort(t.begin(), t.end()); int k = 0; for (int i = 0; i < m; i++) { if (i > 0 && t[i].first != t[i - 1].first) k++; P& q = p[t[i].second / 2]; if (t[i].second % 2 == 0) q.x = k; else q.y = k; } k++; BIT bt(k); ll ans = 0; for (int i = 0; i < n; i++) { if (p[i].t == 0) { bt.add(p[i].x, p[i].y); } else { ans += bt.sum(p[i].y) - bt.sum(p[i].x); } } cout << ans << endl; return 0; }