제출 #950478

#제출 시각아이디문제언어결과실행 시간메모리
950478vjudge1Triple Jump (JOI19_jumps)C++17
100 / 100
2532 ms148268 KiB
#include <bits/stdc++.h> #pragma optimize("Ofast,unroll-loops") #pragma target("avx2") using namespace std; #define ll long long #define ld long double #define pb push_back #define pf push_front #define pii pair<int,int> #define all(v) v.begin(),v.end() #define F first #define S second #define mem(a,i) memset(a,i,sizeof(a)) #define sz(s) (int)s.size() #define y1 yy #define ppb pop_back #define lb lower_bound #define ub upper_bound #define gcd(a,b) __gcd(a,b) #define in insert #define int ll const int MAX=5e5+10; const int B=500; const int maxB=1000; const int N=104; const int block=450; const int inf=2e9; const int mod=1e9+7; const int mod1=1e9+9; const ld eps=1e-9; int dx[8]={1,0,-1,0,1,-1,-1,1}; int dy[8]={0,1,0,-1,1,-1,1,-1}; int binpow(int a,int n){ if(!n)return 1; if(n%2==1)return a*binpow(a,n-1)%mod; int k=binpow(a,n/2); return k*k%mod; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int l[MAX],r[MAX]; int n,q; int a[MAX]; int ans[MAX]; struct segtree{ int t[4*MAX]; int d[4*MAX]; int s[4*MAX]; int add[4*MAX]; segtree(){ mem(t,0); mem(s,0); mem(d,0); mem(add,-1); } void build(int v,int tl,int tr,int (&a)[]){ if(tl==tr){ d[v]=a[tl]; t[v]=a[tl]; return; } int tm=(tl+tr)/2; build(2*v,tl,tm,a); build(2*v+1,tm+1,tr,a); t[v]=max(t[2*v],t[2*v+1]); d[v]=max(d[2*v],d[2*v+1]); } void push(int v){ if(add[v]==-1)return; t[2*v]=add[v]+d[2*v]; t[2*v+1]=add[v]+d[2*v+1]; s[2*v]=s[2*v+1]=add[v]; add[2*v]=add[2*v+1]=add[v]; add[v]=-1; } void update(int v,int tl,int tr,int l,int r,int x){ if(l>r||tl>r||l>tr)return; if(l<=tl&&tr<=r){ t[v]=x+d[v]; s[v]=x; add[v]=x; return; } push(v); int tm=(tl+tr)/2; update(2*v,tl,tm,l,r,x); update(2*v+1,tm+1,tr,l,r,x); s[v]=max(s[2*v],s[2*v+1]); t[v]=max(t[2*v],t[2*v+1]); } int get(int v,int tl,int tr,int l,int r){ if(l>r||tl>r||l>tr)return 0; if(l<=tl&&tr<=r)return t[v]; push(v); int tm=(tl+tr)/2; return max(get(2*v,tl,tm,l,r),get(2*v+1,tm+1,tr,l,r)); } }t; vector<int> seg[MAX]; vector<pii> zap[MAX]; void solve(){ cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } t.build(1,1,n,a); stack<int> st; for(int i=1;i<=n;i++){ while(!st.empty()&&a[i]>a[st.top()]){ st.pop(); } if(!st.empty())l[i]=st.top(); st.push(i); } while(!st.empty())st.pop(); for(int i=n;i>=1;i--){ while(!st.empty()&&a[i]>a[st.top()]){ st.pop(); } if(!st.empty())r[i]=st.top(); st.push(i); } for(int i=1;i<=n;i++){ if(r[i]){ // cout<<i<<" "<<r[i]<<"\n"; seg[i].pb(r[i]); } if(l[i]){ // cout<<l[i]<<" "<<i<<"\n"; seg[l[i]].pb(i); } } cin>>q; for(int i=1;i<=q;i++){ int l,r; cin>>l>>r; zap[l].pb({r,i}); } for(int i=n;i>=1;i--){ for(auto r:seg[i]){ int r1=r+(r-i); if(r1<=n){ int s=a[i]+a[r]; int lef=r1,rig=n,res=-1; while(lef<=rig){ int mid=(lef+rig)/2; if(t.get(1,1,n,mid,mid)-a[mid]<s){ lef=mid+1; res=mid; } else rig=mid-1; } t.update(1,1,n,r1,res,s); } } for(auto [r,num]:zap[i]){ ans[num]=t.get(1,1,n,i,r); } } for(int i=1;i<=q;i++)cout<<ans[i]<<"\n"; } signed main(){ // freopen("triangles.in","r",stdin); // freopen("triangles.out","w",stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // prec(); int t=1; // cin>>t; while(t--){ solve(); } }

컴파일 시 표준 에러 (stderr) 메시지

jumps.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    3 | #pragma optimize("Ofast,unroll-loops")
      | 
jumps.cpp:4: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    4 | #pragma target("avx2")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...