結果
問題 | No.880 Yet Another Segment Tree Problem |
ユーザー | maroon_kuri |
提出日時 | 2019-09-06 22:45:38 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 410 ms / 5,000 ms |
コード長 | 6,743 bytes |
コンパイル時間 | 2,142 ms |
コンパイル使用メモリ | 180,588 KB |
実行使用メモリ | 16,456 KB |
最終ジャッジ日時 | 2024-09-22 19:34:28 |
合計ジャッジ時間 | 10,580 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 3 ms
5,376 KB |
testcase_02 | AC | 3 ms
5,376 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 3 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 3 ms
5,376 KB |
testcase_09 | AC | 3 ms
5,376 KB |
testcase_10 | AC | 3 ms
5,376 KB |
testcase_11 | AC | 367 ms
16,128 KB |
testcase_12 | AC | 363 ms
16,136 KB |
testcase_13 | AC | 253 ms
16,128 KB |
testcase_14 | AC | 350 ms
16,240 KB |
testcase_15 | AC | 384 ms
16,216 KB |
testcase_16 | AC | 410 ms
16,256 KB |
testcase_17 | AC | 305 ms
16,384 KB |
testcase_18 | AC | 293 ms
16,256 KB |
testcase_19 | AC | 191 ms
16,256 KB |
testcase_20 | AC | 196 ms
16,128 KB |
testcase_21 | AC | 198 ms
16,336 KB |
testcase_22 | AC | 197 ms
16,244 KB |
testcase_23 | AC | 201 ms
16,248 KB |
testcase_24 | AC | 163 ms
16,316 KB |
testcase_25 | AC | 164 ms
16,300 KB |
testcase_26 | AC | 173 ms
16,280 KB |
testcase_27 | AC | 165 ms
16,252 KB |
testcase_28 | AC | 170 ms
16,240 KB |
testcase_29 | AC | 340 ms
16,244 KB |
testcase_30 | AC | 370 ms
16,456 KB |
testcase_31 | AC | 402 ms
16,244 KB |
testcase_32 | AC | 85 ms
16,264 KB |
testcase_33 | AC | 138 ms
16,252 KB |
testcase_34 | AC | 146 ms
16,232 KB |
testcase_35 | AC | 136 ms
16,320 KB |
testcase_36 | AC | 134 ms
16,228 KB |
testcase_37 | AC | 139 ms
16,148 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll=long long; #define int ll #define rng(i,a,b) for(int i=int(a);i<int(b);i++) #define rep(i,b) rng(i,0,b) #define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--) #define per(i,b) gnr(i,0,b) #define pb push_back #define eb emplace_back #define a first #define b second #define bg begin() #define ed end() #define all(x) x.bg,x.ed #ifdef LOCAL #define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl #else #define dmp(x) void(0) #endif template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;} template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;} template<class t> using vc=vector<t>; template<class t> using vvc=vc<vc<t>>; using pi=pair<int,int>; using vi=vc<int>; template<class t,class u> ostream& operator<<(ostream& os,const pair<t,u>& p){ return os<<"{"<<p.a<<","<<p.b<<"}"; } template<class t> ostream& operator<<(ostream& os,const vc<t>& v){ os<<"{"; for(auto e:v)os<<e<<","; return os<<"}"; } #define mp make_pair #define mt make_tuple #define one(x) memset(x,-1,sizeof(x)) #define zero(x) memset(x,0,sizeof(x)) using uint=unsigned; using ull=unsigned long long; template<int i,class T> void print_tuple(ostream&,const T&){ } template<int i,class T,class H,class ...Args> void print_tuple(ostream&os,const T&t){ if(i)os<<","; os<<get<i>(t); print_tuple<i+1,T,Args...>(os,t); } template<class ...Args> ostream& operator<<(ostream&os,const tuple<Args...>&t){ os<<"{"; print_tuple<0,tuple<Args...>,Args...>(os,t); return os<<"}"; } void print(ll x,int suc=1){ cout<<x; if(suc==1) cout<<"\n"; if(suc==2) cout<<" "; } ll read(){ ll i; cin>>i; return i; } vi readvi(int n,int off=0){ vi v(n); rep(i,n)v[i]=read()+off; return v; } template<class T> void print(const vector<T>&v,int suc=1){ rep(i,v.size()) print(v[i],i==int(v.size())-1?suc:2); } string readString(){ string s; cin>>s; return s; } template<class T> T sq(const T& t){ return t*t; } //#define CAPITAL void yes(bool ex=true){ #ifdef CAPITAL cout<<"YES"<<endl; #else cout<<"Yes"<<endl; #endif if(ex)exit(0); } void no(bool ex=true){ #ifdef CAPITAL cout<<"NO"<<endl; #else cout<<"No"<<endl; #endif if(ex)exit(0); } constexpr ll ten(int n){ return n==0?1:ten(n-1)*10; } const ll infLL=LLONG_MAX/3; #ifdef int const int inf=infLL; #else const int inf=INT_MAX/2-100; #endif int topbit(signed t){ return t==0?-1:31-__builtin_clz(t); } int topbit(ll t){ return t==0?-1:63-__builtin_clzll(t); } int popcount(signed t){ return __builtin_popcount(t); } int popcount(ll t){ return __builtin_popcountll(t); } bool ispow2(int i){ return i&&(i&-i)==i; } int mask(int i){ return (int(1)<<i)-1; } bool inc(int a,int b,int c){ return a<=b&&b<=c; } template<class t> void mkuni(vc<t>&v){ sort(all(v)); v.erase(unique(all(v)),v.ed); } ll rand_int(ll l, ll r) { //[l, r] static random_device rd; static mt19937_64 gen(rd()); return uniform_int_distribution<ll>(l, r)(gen); } //KUPC2017I //HDU 5306 Gorgeous Sequence template<class N> struct segbeats{ vc<N> x; int s; template<class T> segbeats(const vc<T>& a){ int n=a.size(); s=1; while(s<n)s*=2; x.resize(s*2); rep(i,n) x[s+i]=N(a[i]); gnr(i,1,s) upd(i); } void push(int i){ x[i].push(x[i*2],x[i*2+1]); } void upd(int i){ x[i]=N::merge(x[i*2],x[i*2+1]); } template<class F,class... Args> void chr(int l,int r,int i,int b,int e,F f,Args... args){ if(e<=l||r<=b) return; if(b<=l&&r<=e&&(x[i].*f)(args...)) return; push(i); int m=(l+r)/2; chr(l,m,i*2,b,e,f,args...); chr(m,r,i*2+1,b,e,f,args...); upd(i); } template<class F,class... Args> void ch(int b,int e,F f,Args... args){ assert(b<e); chr(0,s,1,b,e,f,args...); } //use decltype((declval<N>().*F())()) for old-fashioned judges template<class F,class G,class H> auto getr(int l,int r,int i,int b,int e,F f,G g,H h){ if(e<=l||r<=b) return h; if(b<=l&&r<=e) return (x[i].*f)(); push(i); int m=(l+r)/2; return g(getr(l,m,i*2,b,e,f,g,h),getr(m,r,i*2+1,b,e,f,g,h)); } template<class F,class G,class H> auto get(int b,int e,F f,G g,H h){ assert(b<e); return getr(0,s,1,b,e,f,g,h); } //return minimum index template<class F,class...Args> pair<int,N> findr(int i,int l,int r,int b,int e,F f,Args&...args){ if(e<=l||r<=b)return {e,N()}; if(b<=l&&r<=e){ if(!(x[i].*f)(args...))return {e,N()}; if(r-l==1)return {l,x[i]}; } push(i); int m=(l+r)/2; auto a=findr(i*2,l,m,b,e,f,args...); if(a.a<e)return a; return findr(i*2+1,m,r,b,e,f,args...); } template<class F,class...Args> pair<int,N> find(int b,int e,F f,Args&...args){ assert(b<e); return findr(1,0,s,b,e,f,args...); } //NOT VERIFIED /* //return maximum index template<class F,class...Args> pair<int,N> findr(int i,int l,int r,int b,int e,F f,Args&&...args){ if(e<=l||r<=b)return {b-1,N()}; if(b<=l&&r<=e){ if(!(x[i].*f)(args...))return {b-1,N()}; if(r-l==1)return {l,x[i]}; } push(i); int m=(l+r)/2; auto a=findr(i*2+1,m,r,b,e,f,forward<Args>(args)...); if(a.a>=b)return a; return findr(i*2,l,m,b,e,f,forward<Args>(args)...); } template<class F,class...Args> pair<int,N> find(int b,int e,F f,Args&&...args){ assert(b<e); return findr(1,0,s,b,e,f,forward<Args>(args)...); } */ }; //usage int botbit(int a){ return __builtin_ctzll(a); } //ARC055D //int gcd(int a,int b){return b?gcd(b,a%b):a;} int gcd(int a,int b){ if(a==0)return b; if(b==0)return a; if(a<0)a=-a; if(b<0)b=-b; int s=botbit(a|b); a>>=botbit(a); do{ b>>=botbit(b); if(a>b)swap(a,b); b-=a; }while(b); return a<<s; } int lcm(int a,int b){return a/gcd(a,b)*b;} struct N{ int lz,mn,mx,z,num,sum; N(int v=1):lz(-1),mn(v),mx(v),z(v),num(1),sum(v){} bool set(int v){ lz=v; mn=v; mx=v; z=v; sum=num*v; return true; } bool waf(int g){ if(gcd(g,z)==z)return true; if(num==1||mx==mn) return set(gcd(mx,g)); return false; } void push(N& x,N& y){ if(lz!=-1){ x.set(lz); y.set(lz); lz=-1; } } static N merge(N x,N y){ N res; res.mn=min(x.mn,y.mn); res.mx=max(x.mx,y.mx); static const int v=ten(9)+7; res.z=min(v,lcm(x.z,y.z)); res.num=x.num+y.num; res.sum=x.sum+y.sum; return res; } int gets(){return sum;} int getm(){return mx;} }; signed main(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); int n,q;cin>>n>>q; vi a=readvi(n); segbeats<N> seg(a); rep(_,q){ int t,l,r;cin>>t>>l>>r; l--; if(t==1){ int x;cin>>x; seg.ch(l,r,&N::set,x); }else if(t==2){ int x;cin>>x; seg.ch(l,r,&N::waf,x); }else if(t==3){ print(seg.get(l,r,&N::getm,[](int x,int y){return max(x,y);},int(0))); }else{ print(seg.get(l,r,&N::gets,[](int x,int y){return x+y;},int(0))); } } }