結果
問題 | No.789 範囲の合計 |
ユーザー | WarToks |
提出日時 | 2019-04-08 02:02:20 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 5,255 bytes |
コンパイル時間 | 1,136 ms |
コンパイル使用メモリ | 144,112 KB |
実行使用メモリ | 14,880 KB |
最終ジャッジ日時 | 2024-05-07 19:00:52 |
合計ジャッジ時間 | 3,752 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
10,624 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | TLE | - |
testcase_03 | -- | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
ソースコード
#include <iostream> #include <set> #include <queue> #include <stack> #include <vector> #include <algorithm> #include <map> #include <chrono> #include <math.h> using namespace std; using lli = long long int; using Vint = std::vector<int>; using Vlli = std::vector<lli>; using Wint = std::vector<Vint>; using Wlli = std::vector<Vlli>; using Vbool = std::vector<bool>; using pii = std::pair<int, int>; using pll = std::pair<lli, lli>; constexpr int MOD = 1e9 + 7; constexpr int INFi = 2e9 + 1; constexpr lli INFl = (lli)(9e18) + 1; const vector<pii> DXDY = {std::make_pair(1, 0), std::make_pair(-1, 0), std::make_pair(0, 1), std::make_pair(0, -1)}; constexpr char BR = '\n'; #define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++) #define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++) #define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--) #define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step)) #define REP(i, n) FOR(i, 0, n) #define rREP(i, n) rFOR(i, 0, (n-1)) #define vREP(ele, vec) for(auto &(ele) : (vec)) #define vREPcopy(ele, vec) for(auto (ele) : (vec)) #define SORT(A) std::sort((A).begin(), (A).end()) template <class T> inline int argmin(vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();} template <class T> inline int argmax(vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();} template <class T> inline void chmax(T &a, T b){a = max(a, b);} template <class T> inline void chmin(T &a, T b){a = min(a, b);} inline int toInt(string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;} inline int toInt(const string s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;} inline long long int toLong(string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;} inline long long int toLong(const string s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;} template <class T> inline std::string toString(T n){ if(n == 0) return "0"; std::string res = ""; if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return '-' + res;} while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res; } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ template <class T> class SegKi{ int n; std::vector<T> DataTree; public: // 区間の長さszから(2^k ≥ sz)となるkを求めて初期化 SegKi(int sz){ this->n = 1; while((1 << this->n) < sz) this->n++; this->DataTree.resize((1 << (this->n + 1)) -1); } // デフォルト値をしてして初期化 SegKi(int sz, T defaultValue){ this->n = 1; while((1 << this->n) < sz) this->n++; this->DataTree.resize((1 << (this->n + 1)) - 1, defaultValue); for(int i = (1 << this->n) - 2; i >= 0; i--) DataTree.at(i) = DataTree.at(2 * i + 1) + DataTree.at(2 * i + 2); } // vectorによって初期化 SegKi(vector<T> A){ const int sz = A.size(); this->n = 1; while((1 << n) < sz) this->n++; DataTree.resize(1 << this->n); for(int i = 0; i < sz; i++) DataTree.at(i) = A.at(i); for(int i = (1 << this->n) - 2; i >= 0; i--) DataTree.at(i) = DataTree.at(2 * i + 1) + DataTree.at(2 * i + 2); } void update(int k, T value){ // A[k]の値をvalueで更新 k += (1 << this->n) - 1; DataTree.at(k) = value; while(k > 0){ k = (k - 1) / 2; DataTree.at(k) = DataTree.at(2 * k + 1) + DataTree.at(2 * k + 2); } } void add(int k, T value){ // A[k]の値をvalueで更新 k += (1 << this->n) - 1; DataTree.at(k) += value; while(k > 0){ k = (k - 1) / 2; DataTree.at(k) = DataTree.at(2 * k + 1) + DataTree.at(2 * k + 2); } } T getsum(int a, int b, T k=0, int l=0, int r=-1) { if(r < 0) r = (1 << this->n); if(b <= l or r <= a) return 0; if(a <= l and r <= b) return DataTree.at(k); T vl = getsum(a, b, 2 * k + 1, l, (l+r)/2); T vr = getsum(a, b, 2 * k + 2, (l+r)/2, r); return vl + vr; } T getValue(int j){ return DataTree.at(j + (1 << this->n) - 1); } }; int main(void){ int n, q, x, y; scanf("%d", &n); using sub_information_number = std::pair<int, int>; using information = std::pair<bool, sub_information_number>; std::vector<information> Query(n); set<int> Apple; REP(i, n){ scanf("\n%d %d %d", &q, &x, &y); Query.at(i) = make_pair(q == 0, make_pair(x, y)); if(q == 0) Apple.insert(x); } const int Asz = Apple.size(); lli ans = 0; SegKi<lli> Data(Asz); vREP(ele, Query){ const sub_information_number United = ele.second; if(ele.first){ int position = distance(Apple.begin(), Apple.find(United.first)); Data.add(position, United.second); } else{ int position_l = std::distance(Apple.begin(), lower_bound(Apple.begin(), Apple.end(), United.first)), position_r = std::distance(Apple.begin(), upper_bound(Apple.begin(), Apple.end(), United.second)); ans += Data.getsum(position_l, position_r); } } printf("%lld\n", ans); return 0; }