結果

問題 No.777 再帰的ケーキ
ユーザー tarakojo1019
提出日時 2021-01-18 18:38:25
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,873 bytes
コンパイル時間 1,580 ms
コンパイル使用メモリ 141,288 KB
実行使用メモリ 57,064 KB
最終ジャッジ日時 2024-12-14 09:26:40
合計ジャッジ時間 9,531 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 32 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<numeric>
#include<cstring>
#include<random>
#include<array>
#include<fstream>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include<queue>
/*
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) std::cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", (double)v)
template<typename A, typename B>void mins(A& a, const B& b) { a = min(a, (A)b); };
template<typename A, typename B>void maxs(A& a, const B& b) { a = max(a, (A)b); };
template<typename X>
class segtree {
public:
using func_xx = function<X(X, X)>;
long long N;
func_xx fxx;
X ex;
vector<X> dat;
bool changed;
segtree() {}
segtree(long long n, func_xx fxx, const X& ex) : fxx(fxx), ex(ex), changed(false) {
if (n == 1) ++n;
int x = 1;
while (x < n) x *= 2;
N = x;
dat.resize(2 * N - 1, ex);
}
const segtree<X>& operator=(const segtree& source) {
N = source.N;
fxx = source.fxx;
ex = source.ex;
dat = source.dat;
changed = source.changed;
return *this;
}
//
void update(int k) {
dat[k] = fxx(dat[2 * k + 1], dat[2 * k + 2]);
if (k != 0) update((k - 1) / 2);
}
void build() {
for (int i = N - 2; i >= 0; --i) dat[i] = fxx(dat[2 * i + 1], dat[2 * i + 2]);
changed = false;
}
//
void set(int i, const X& x, bool update = true) {
dat[N - 1 + i] = x;
if (update) this->update((N - 2 + i) / 2);
else changed = true;
}
//
const X& elem(int i) {
return dat[N - 1 + i];
}
X query_sub(int a, int b, int k, int l, int r) {
if (r <= a || b <= l) { return ex; }
else if (a <= l && r <= b) { return dat[k]; }
else {
return fxx(query_sub(a, b, 2 * k + 1, l, (l + r) / 2),
query_sub(a, b, 2 * k + 2, (l + r) / 2, r));
}
}
//[a,b)fxx
X query(int a, int b) {
if (changed) build();
return query_sub(a, b, 0, 0, N);
}
};
int main() {
auto func = [](auto a, auto b) {return max(a, b); };
ll N; cin >> N;
map<ll, map <ll, ll, greater<ll>>> mp;
set<ll> W;
REP(i, 0, N) {
ll a, b, c; cin >> a >> b >> c;
if (mp.count(a) != 0 && mp.count(b) != 0 && mp[a][b] >= c) continue;
mp[a][b] = c;
W.insert(b);
}
unordered_map<ll, ll> wind;
ll c = 0;
for (ll x : W) wind[x] = c++;
segtree<ll> seg{ N, func, 0 };
for (auto& v : mp) {
for (auto p : v.second) {
ll tmp = seg.query(0, wind[p.first]);
if (seg.elem(wind[p.first]) < tmp + p.second) seg.set(wind[p.first], tmp + p.second);
}
}
PRI(seg.query(0, N));
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0