제출 #1226336

#제출 시각아이디문제언어결과실행 시간메모리
1226336boclobanchatStone Arranging 2 (JOI23_ho_t1)C++20
100 / 100
300 ms17388 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN=2e5+5; map<int,int> mp; stack< pair<int,int> > st; int seg[MAXN*4],lazy[MAXN*4]; void down(int pos) { int val=lazy[pos]; if(!val) return ; seg[pos*2]=seg[pos*2+1]=val; lazy[pos*2]=lazy[pos*2+1]=val; lazy[pos]=0; } void update(int l,int r,int u,int v,int val,int pos) { if(v<l||r<u) return ; if(u<=l&&r<=v) { seg[pos]=lazy[pos]=val; return ; } int mid=(l+r)/2; down(pos); update(l,mid,u,v,val,pos*2); update(mid+1,r,u,v,val,pos*2+1); } void get(int l,int r,int pos) { if(l==r) { cout<<seg[pos]<<"\n"; return ; } int mid=(l+r)/2; down(pos); get(l,mid,pos*2); get(mid+1,r,pos*2+1); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; for(int i=1;i<=n;i++) { int res; cin>>res; if(!mp[res]) update(1,n,i,i,res,1); else { while(!st.empty()&&st.top().second!=res) mp[st.top().second]--,st.pop(); update(1,n,st.top().first+1,i,res,1); } st.push({i,res}),mp[st.top().second]++; } get(1,n,1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...