結果
問題 | No.777 再帰的ケーキ |
ユーザー |
|
提出日時 | 2021-01-18 19:17:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 468 ms / 2,000 ms |
コード長 | 3,341 bytes |
コンパイル時間 | 1,748 ms |
コンパイル使用メモリ | 138,168 KB |
実行使用メモリ | 24,572 KB |
最終ジャッジ日時 | 2024-12-14 10:14:53 |
合計ジャッジ時間 | 6,280 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 33 |
コンパイルメッセージ
main.cpp: In function 'void solve()': main.cpp:143:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 143 | auto [a, b, c] = abc[i]; | ^
ソースコード
#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>using namespace std;#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)#define REP(i,n) rep(i,0,n)#define REP2(i,n) rep2(i,0,n)#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)#define all(hoge) (hoge).begin(),(hoge).end()#define en '\n'using ll = long long;using ull = unsigned long long;template <class T> using vec = vector<T>;template <class T> using vvec = vector<vec<T>>;typedef pair<ll, ll> P;constexpr long long INF = 1LL << 60;constexpr int INF_INT = 1 << 25;constexpr long long MOD = (ll)1e9 + 7;//constexpr long long MOD = 998244353LL;typedef vector<ll> Array;typedef vector<Array> Matrix;template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}struct Edge {ll to, cap, rev;Edge(ll _to, ll _cap, ll _rev) {to = _to; cap = _cap; rev = _rev;}};using Edges = vector<Edge>;using Graph = vector<Edges>;void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {G[from].push_back(Edge(to, cap, (ll)G[to].size()));if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));}template<typename T, typename F>class SegmentTree {private:T e;F op;ll n;vector<T> dat;public:SegmentTree(F f, T _e, vector<T> v) :op(f), e(_e) {int _n = v.size();n = 1;while (n < _n)n *= 2;dat.resize(2 * n - 1, e);REP(i, _n)dat[n + i - 1] = v[i];for (int i = n - 2; i >= 0; i--)dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);}SegmentTree(F f, T _e, int _n) :op(f), e(_e) {n = 1;while (n < _n)n *= 2;dat.resize(2 * n - 1, e);for (int i = n - 2; i >= 0; i--)dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);}void update(int i, T x) {i += n - 1;dat[i] = x;while (i > 0) {i = (i - 1) / 2;dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);}}T query(int l, int r) {//[l,r)でのクエリ処理T left = e, right = e;l += n - 1; r += n - 1;while (l < r) {if ((l & 1) == 0)left = op(left, dat[l]);if ((r & 1) == 0)right = op(dat[r - 1], right);l = l / 2;r = (r - 1) / 2;}return op(left, right);}};void solve() {ll n;cin >> n;vec<tuple<ll, ll, ll>> abc(n);map<ll, ll> mp;REP(i, n) {ll a, b, c;cin >> a >> b >> c;abc[i] = { a,-b,c };mp[b]++;}sort(all(abc));ll con = 0;for (auto& i : mp) {i.second = con;con++;}auto op = [](ll a, ll b) {return max(a, b); };SegmentTree<ll, decltype(op)> seg(op, 0, 202020);REP(i, n) {auto [a, b, c] = abc[i];ll m = seg.query(0, mp[-b]);if (seg.query(mp[-b], mp[-b]+1) < m + c)seg.update(mp[-b], m + c);}cout << seg.query(0, 202020) << en;}int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);solve();//ll t;cin>>t;REP(i,t) solve();return 0;}