結果
| 問題 |
No.1826 Fruits Collecting
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2022-01-28 21:40:55 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 164 ms / 2,000 ms |
| コード長 | 2,943 bytes |
| コンパイル時間 | 1,663 ms |
| コンパイル使用メモリ | 107,168 KB |
| 最終ジャッジ日時 | 2025-01-27 16:18:24 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 43 |
ソースコード
#include <vector>
#include <algorithm>
namespace nachia{
class CoordinateCompress {
using Elem = long long;
static const Elem negInf = -1001001001001001001;
std::vector<std::pair<Elem, int>> G;
std::vector<int> res;
std::vector<Elem> mRealval;
Elem mMaxcoord;
bool ok = true;
void calc() {
if (ok) return;
sort(G.begin(), G.end());
res.resize(G.size());
mRealval.clear();
Elem x = negInf;
int p = -1;
for(int i=0; i<(int)G.size(); i++){
if (x != G[i].first) { x = G[i].first; mRealval.push_back(x); p++; }
res[G[i].second] = p;
}
mMaxcoord = p;
ok = true;
}
public:
int push(Elem x) {
ok = false;
G.push_back({ x,(int)G.size() });
return G.back().second;
}
int operator[](int i) {
calc();
return res[i];
}
Elem realval(int x) {
calc();
return mRealval[x];
}
Elem maxcoord() {
calc();
return mMaxcoord;
}
};
template<class Elem>
std::vector<int> coordinate_compress_instant(const std::vector<Elem>& A, bool disjoint = false){
int n = A.size();
std::vector<int> ord(n);
for(int i=0; i<n; i++) ord[i] = i;
if(disjoint){
std::sort(ord.begin(), ord.end(), [&](int l, int r) -> bool { return (A[l] != A[r]) ? (A[l] < A[r]) : (l < r); });
std::vector<int> res(n, 0);
for(int i=0; i<n; i++) res[ord[i]] = i;
return res;
}
std::sort(ord.begin(), ord.end(), [&](int l, int r) -> bool { return A[l] < A[r]; });
std::vector<int> res(n, 0);
for(int i=1; i<n; i++) res[ord[i]] = res[ord[i-1]] + ((A[ord[i-1]] < A[ord[i]]) ? 1 : 0);
return res;
}
}
#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/segtree>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
using i32 = int;
using u32 = unsigned int;
#define rep(i,n) for(int i=0; i<(n); i++)
namespace RQ{
using S = i64;
S op(S l, S r){ return max(l,r); }
S e(){ return 0; }
using RQ = atcoder::segtree<S,op,e>;
}
struct Item{ i64 x,y,v; };
bool sortItem(Item l, Item r){ return make_pair(l.x, l.y) < make_pair(r.x,r.y); }
nachia::CoordinateCompress CCY;
int main() {
int N; cin >> N;
vector<Item> A(N);
rep(i,N){
i64 x,y,v; cin >> x >> y >> v;
A[i] = { x+y, x-y, v };
if(x+y < 0 || x-y < 0) A[i] = {0,0,0};
}
rep(i,N) A[i].y = CCY.push(A[i].y);
rep(i,N) A[i].y = CCY[A[i].y];
sort(A.begin(), A.end(), sortItem);
RQ::RQ rq(N);
for(auto [x,y,v] : A){
i64 pans = rq.prod(0,y+1);
rq.set(y, pans + v);
}
i64 ans = rq.all_prod();
cout << ans << "\n";
return 0;
}
struct ios_do_not_sync{
ios_do_not_sync(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
}
} ios_do_not_sync_instance;
Nachia