結果
| 問題 |
No.777 再帰的ケーキ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-22 19:09:39 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,649 bytes |
| コンパイル時間 | 1,214 ms |
| コンパイル使用メモリ | 93,668 KB |
| 実行使用メモリ | 11,856 KB |
| 最終ジャッジ日時 | 2024-10-09 20:43:58 |
| 合計ジャッジ時間 | 6,284 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 25 WA * 8 |
コンパイルメッセージ
main.cpp:53:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
53 | main()
| ^~~~
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<vector>
#include<functional>
#include<limits>
template<typename T>
struct segtree{
using F=function<T(T,T)>;
const F calcfn,updatefn;
int n;
T defvalue;
vector<T>dat;
segtree(int n_=0,T defvalue_=numeric_limits<T>::max(),
const F calcfn_=[](T a,T b){return a<b?a:b;},
const F updatefn_=[](T a,T b){return b;}
):defvalue(defvalue_),calcfn(calcfn_),updatefn(updatefn_)
{
n=1;
while(n<n_)n<<=1;
dat.assign(2*n-1,defvalue);
}
void copy(const vector<T>&v)
{
for(int i=0;i<v.size();i++)dat[i+n-1]=v[i];
for(int i=n-2;i>=0;i--)dat[i]=calcfn(dat[i*2+1],dat[i*2+2]);
}
void update(int i,T a)
{
i+=n-1;
dat[i]=updatefn(dat[i],a);
while(i>0)
{
i=(i-1)/2;
dat[i]=calcfn(dat[2*i+1],dat[2*i+2]);
}
}
T query(int a,int b)//[a,b)
{
int L=(a<0?0:a>n?n:a)+n-1;
int R=(b<0?0:b>n?n:b)+n-1;
T lret=defvalue,rret=defvalue;
for(;L<R;L>>=1,R>>=1)
{
if(!(L&1))lret=calcfn(lret,dat[L]);
if(!(R&1))rret=calcfn(dat[--R],rret);
}
return calcfn(lret,rret);
}
};
int N;
main()
{
cin>>N;
vector<pair<pair<int,int>,int> >A;
vector<int>B;
for(int i=0;i<N;i++)
{
int a,b,c;cin>>a>>b>>c;
A.push_back(make_pair(make_pair(a,-b),c));
B.push_back(b);
}
sort(B.begin(),B.end());
B.erase(unique(B.begin(),B.end()),B.end());
segtree<long>P(B.size(),0,[](int a,int b){return a<b?b:a;},[](int a,int b){return a<b?b:a;});
sort(A.begin(),A.end());
for(pair<pair<int,int>,int>p:A)
{
int b=lower_bound(B.begin(),B.end(),-p.first.second)-B.begin();
P.update(b,p.second+P.query(0,b));
}
cout<<P.query(0,B.size())<<endl;
}