結果
問題 | No.776 A Simple RMQ Problem |
ユーザー | char134217728 |
提出日時 | 2018-12-24 02:14:05 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 220 ms / 3,000 ms |
コード長 | 4,042 bytes |
コンパイル時間 | 2,295 ms |
コンパイル使用メモリ | 187,108 KB |
実行使用メモリ | 15,448 KB |
最終ジャッジ日時 | 2024-09-25 10:55:03 |
合計ジャッジ時間 | 7,970 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 20 ms
6,944 KB |
testcase_03 | AC | 72 ms
14,192 KB |
testcase_04 | AC | 89 ms
6,944 KB |
testcase_05 | AC | 151 ms
14,272 KB |
testcase_06 | AC | 45 ms
8,648 KB |
testcase_07 | AC | 98 ms
14,504 KB |
testcase_08 | AC | 116 ms
8,848 KB |
testcase_09 | AC | 44 ms
14,548 KB |
testcase_10 | AC | 68 ms
9,060 KB |
testcase_11 | AC | 124 ms
14,760 KB |
testcase_12 | AC | 159 ms
15,136 KB |
testcase_13 | AC | 160 ms
14,800 KB |
testcase_14 | AC | 160 ms
14,888 KB |
testcase_15 | AC | 161 ms
14,920 KB |
testcase_16 | AC | 157 ms
15,012 KB |
testcase_17 | AC | 220 ms
14,868 KB |
testcase_18 | AC | 108 ms
14,884 KB |
testcase_19 | AC | 174 ms
14,980 KB |
testcase_20 | AC | 181 ms
14,744 KB |
testcase_21 | AC | 168 ms
14,896 KB |
testcase_22 | AC | 178 ms
14,940 KB |
testcase_23 | AC | 186 ms
14,868 KB |
testcase_24 | AC | 179 ms
14,892 KB |
testcase_25 | AC | 28 ms
6,944 KB |
testcase_26 | AC | 104 ms
14,968 KB |
testcase_27 | AC | 90 ms
15,448 KB |
コンパイルメッセージ
main.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 67 | main(){ | ^~~~
ソースコード
#include <bits/stdc++.h> #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define FORR(i,a,b) for (int i=(a);i>=(b);i--) #define pb push_back #define mp make_pair #define fi first #define se second #define pcnt __builtin_popcount #define sz(x) (int)(x).size() #define maxs(x,y) x=max(x,y) #define mins(x,y) x=min(x,y) #define show(x) cout<<#x<<" = "<<x<<endl; #define all(a) (a.begin()),(a.end()) #define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++) #define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c))) #define bit(n) (1LL<<(n)) using namespace std; typedef long long ll; typedef __int128_t lll; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template<typename T>string join(V<T>&v){stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);} template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);} lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;} ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);} ll modpow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;} bool isprime(ll n){if(n<2)return 0;if(!(n%2))return !(n-2);lll d=n-1,t,y;while(!(d%2))d>>=1;V<ll> al={2,325,9375,28178,450775,9780504,1795265022};for(ll a:al){if(n<=a)break;t=d,y=modpow(a,t,n);while(t!=n-1&&y!=1&&y!=n-1)y=y*y%n,t<<=1;if(y!=n-1&&!(t%2))return 0;}return 1;} void dout(double d){printf("%.12f\n",d);} void YN(bool z){cout<<(z?"YES\n":"NO\n");} void Yn(bool z){cout<<(z?"Yes\n":"No\n");} void yn(bool z){cout<<(z?"yes\n":"no\n");} mt19937 rnd; void set_rnd(){random_device r;rnd=mt19937(r());} V<ll> fact, rfact; void set_fact(int n, ll m){fact.pb(1);rfact.pb(1);FOR(i,1,n+1)fact.pb(fact[i-1]*i%m),rfact.pb(modpow(fact[i],m,m-2));} const int iinf = 1e9+6; const ll linf = 1e18; const int mod = 1e9+7; const double pi = acos(-1); const double eps = 1e-10; const int N = 1e5; struct SegTree{ typedef tuple<ll, ll, ll, ll> T; T e = make_tuple(0ll, -linf, -linf, -linf); inline T m(const T&a, const T&b){ return make_tuple( get<0>(a)+get<0>(b), max(max(get<1>(a), get<1>(b)), get<3>(a)+get<2>(b)), max(get<2>(a), get<0>(a)+get<2>(b)), max(get<3>(b), get<3>(a)+get<0>(b)) ); } //################################################### typedef int i;i n;vector<T> d; T q(i a,i b,i k,i l,i r){return (r<=a||b<=l)?e:(a<=l&&r<=b)?d[k]:m(q(a,b,k*2+1,l,(l+r)/2),q(a,b,k*2+2,(l+r)/2,r));} void clear(){FOR(i,0,sz(d))d[i]=e;} void resize(i m){n=1<<(32-__builtin_clz(m-1));d.resize(2*n-1);clear();} void init(vector<T>&v){resize(sz(v));FOR(j,0,sz(v))d[j+n-1]=v[j];FORR(k,n-2,0)d[k]=m(d[k*2+1],d[k*2+2]);} void update(i k,T a){k+=n-1;d[k]=a;while(k>0){k=(k-1)/2;d[k]=m(d[k*2+1],d[k*2+2]);}} T query(i a,i b){return q(a,b,0,0,n);} } seg; int n, m; V<tuple<ll, ll, ll, ll> > v; string s; main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m; FOR(i, 0, n){ ll a; cin >> a; v.pb(make_tuple(a,a,a,a)); } seg.init(v); FOR(i, 0, m){ cin >> s; if(s[0]=='s'){ ll a, b; cin >> a >> b; seg.update(a-1, make_tuple(b,b,b,b)); }else{ int l1, l2, r1, r2; cin >> l1 >> l2 >> r1 >> r2; l1--; l2--; r1--; r2--; maxs(r1, l1); mins(l2, r2); if(l2 < r1){ tuple<ll, ll, ll, ll> ql, qm, qr; ql = seg.query(l1, l2+1); qm = seg.query(l2+1, r1); qr = seg.query(r1, r2+1); printf("%lld\n", get<3>(ql)+get<0>(qm)+get<2>(qr)); }else{ tuple<ll, ll, ll, ll> ql, qm, qr; ql = seg.query(l1, r1); qm = seg.query(r1, l2+1); qr = seg.query(l2+1, r2+1); ll ans = -linf; maxs(ans, get<1>(qm)); maxs(ans, max(0ll, get<3>(ql))+get<2>(qm)); maxs(ans, max(0ll, get<2>(qr))+get<3>(qm)); maxs(ans, max(0ll, get<3>(ql))+max(0ll, get<2>(qr))+get<0>(qm)); printf("%lld\n", ans); } } } return 0; }