結果
問題 | No.1234 典型RMQ |
ユーザー | carrot46 |
提出日時 | 2020-09-18 23:13:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 379 ms / 2,000 ms |
コード長 | 2,206 bytes |
コンパイル時間 | 2,071 ms |
コンパイル使用メモリ | 173,024 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-09 02:01:58 |
合計ジャッジ時間 | 11,277 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <bits/stdc++.h> //#include <chrono> //#pragma GCC optimize("Ofast") using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() #define fi first #define se second typedef long long ll; typedef vector<ll> vec; typedef vector<vec> mat; ll N,M,H,W,Q,K,A,B; string S; typedef pair<ll, ll> P; const ll INF = (1LL<<60); template<class T> bool chmin(T &a, const T &b){ if(a > b) {a = b; return true;} else return false; } template<class T> bool chmax(T &a, const T &b){ if(a < b) {a = b; return true;} else return false; } const int sz = 317, num = 317; struct node{ vec a; ll plus, mini; int id, L, R; node(){} node(int _id, vec &_a) : a(sz), plus(0), mini(INF), id(_id), L(_id * sz), R((_id + 1) * sz){ rep(i, sz) a[i] = (i + id * sz < (int)_a.size() ? _a[i + id * sz] : INF); mini = *min_element(ALL(a)); } void eval(bool mini_update = true){ rep(i, sz) a[i] += plus; plus = 0; if(mini_update) mini = *min_element(ALL(a)); } void update(int l, int r, ll c){ if(R <= l || r <= L) return; if(l <= L && R <= r){ plus += c; }else{ eval(false); reps(i, max(L, l), min(R, r)) a[i - id * sz] += c; mini = *min_element(ALL(a)); } } ll query(int l, int r){ if(R <= l || r <= L) return INF; if(l <= L && R <= r){ return mini + plus; }else{ eval(); ll res(INF); reps(i, max(L, l), min(R, r)) chmin(res, a[i - id * sz]); return res; } } }; int main() { cin>>N; vec a(N); vector<node> group(num); rep(i, N) cin>>a[i]; rep(i, num) group[i] = node(i, a); cin>>Q; rep(_, Q){ int k, l, r, c; cin>>k>>l>>r>>c; --l; if(k == 1){ rep(i, num) group[i].update(l, r, c); }else{ ll res(INF); rep(i, num) chmin(res, group[i].query(l, r)); cout<<res<<endl; } } }