結果
| 問題 |
No.2333 Slime Structure
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-16 18:26:06 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 195 ms / 3,000 ms |
| コード長 | 4,375 bytes |
| コンパイル時間 | 1,239 ms |
| コンパイル使用メモリ | 113,428 KB |
| 最終ジャッジ日時 | 2025-02-13 00:52:10 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 31 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:121:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
121 | scanf("%lld %lld", &A[i], &B[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:129:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
129 | scanf("%lld %lld %lld", &t[i], &x[i], &y[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
#include <limits>
#include <array>
static const int MOD = 1000000007;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
template <class M>
struct SegmentTree{
using T = typename M::T;
int sz, n, height{};
vector<T> seg;
explicit SegmentTree(int n) : n(n) {
sz = 1; while(sz < n) sz <<= 1, height++;
seg.assign(2*sz, M::e());
}
void set(int k, const T &x){ seg[k + sz] = x; }
void build(){
for (int i = sz-1; i > 0; --i) seg[i] = M::f(seg[2*i], seg[2*i+1]);
}
void update(int k, const T &x){
k += sz;
seg[k] = x;
while (k >>= 1) seg[k] = M::f(seg[2*k], seg[2*k+1]);
}
T query(int a, int b){
T l = M::e(), r = M::e();
for(a += sz, b += sz; a < b; a >>=1, b>>=1){
if(a & 1) l = M::f(l, seg[a++]);
if(b & 1) r = M::f(seg[--b], r);
}
return M::f(l, r);
}
template<class F>
int search_right(int l, F cond){
if(l == n) return n;
T val = M::e();
l += sz;
do {
while(!(l&1)) l >>= 1;
if(!cond(M::f(val, seg[l]))){
while(l < sz) {
l <<= 1;
if (cond(M::f(val, seg[l]))){
val = M::f(val, seg[l]);
l++;
}
}
return l - sz;
}
val = M::f(val, seg[l]);
l++;
} while((l & -l) != l);
return n;
}
template<class F>
int search_left(int r, F cond){
if(r == 0) return 0;
T val = M::e();
r += sz;
do {
r--;
while(r&1) r >>= 1;
if(!cond(M::f(seg[r], val))){
while(r < sz) {
r = ((r << 1)|1);
if (cond(M::f(seg[r], val))){
val = M::f(seg[r], val);
r--;
}
}
return r + 1 - sz;
}
val = M::f(seg[r], val);
} while((r & -r) != r);
return 0;
}
T operator[](const int &k) const { return seg[k + sz]; }
};
struct Monoid{
using T = array<ll, 4>;
static T f(T a, T b) { // L, R, sum, ans
return {
max(a[0], b[0]+a[2]),
max(b[1], a[1]+b[2]),
a[2]+b[2],
max({a[3], b[3], a[1]+max(0LL, b[0]), b[0]+max(0LL, a[1])})
};
}
static T e() { return {-INF<ll>, -INF<ll>, -INF<ll>, -INF<ll>}; }
};
int main() {
int n;
cin >> n;
vector<ll> A(n), B(n);
ll S = 0;
vector<ll> z;
z.emplace_back(0);
for (int i = 0; i < n; ++i) {
scanf("%lld %lld", &A[i], &B[i]);
S += B[i];
z.emplace_back(S);
}
ll q;
cin >> q;
vector<ll> t(q), x(q), y(q);
for (int i = 0; i < q; ++i) {
scanf("%lld %lld %lld", &t[i], &x[i], &y[i]);
if(t[i] == 1){
x[i]--;
z.emplace_back(x[i]);
z.emplace_back(x[i]+1);
}else {
x[i]--;
z.emplace_back(x[i]);
z.emplace_back(y[i]);
}
}
sort(z.begin(), z.end());
z.erase(unique(z.begin(), z.end()), z.end());
auto f = [&](ll a){ return lower_bound(z.begin(),z.end(), a) - z.begin(); };
SegmentTree<Monoid> seg(z.size());
S = 0;
for (int i = 0; i < n; ++i) {
int l = f(S), r = f(S+B[i]);
for (int j = l; j < r; ++j) {
ll len = z[j+1]-z[j];
seg.set(j, {
max(A[i], A[i]*len),
max(A[i], A[i]*len),
A[i]*len,
max(A[i], A[i]*len)
});
}
S += B[i];
}
seg.build();
for (int i = 0; i < q; ++i) {
if(t[i] == 1){
int xx = f(x[i]);
seg.update(xx, {y[i], y[i], y[i], y[i]});
}else {
int l = f(x[i]), r = f(y[i]);
auto [a, b, c, d] = seg.query(l, r);
printf("%lld\n", max({a, b, d}));
}
}
return 0;
}