Submission #1063534

#TimeUsernameProblemLanguageResultExecution timeMemory
1063534Dennis_JasonStone Arranging 2 (JOI23_ho_t1)C++14
25 / 100
2063 ms9336 KiB
#include <bits/stdc++.h> #define NMAX 1010 //#define int long long #define pb push_back #define eb emplace_back #define MOD 1000000007 #define nl '\n' #define INF 1000000007 #define LLONG_MAX 9223372036854775807 #define pii pair<int,int> #define tpl tuple<int,int,int,int> //#pragma GCC optimize("O3") using namespace std; ifstream fin("aib.in"); ofstream fout("aib.out"); /* * * ----------------DEMONSTRATION------------------- 1 2 2 3 4 2 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 4 5 ---------------------END------------------------ */ int n; vector<int>v; vector<int>ans; class segtree{ private: int n; vector<int>tree; vector<int>lazy; public: void init(int sz) { n=sz; tree.resize(4*sz+1); lazy.resize(4*sz+1); } void push(int node,int L,int R) { if(lazy[node]) { tree[node] = lazy[node]; if(L != R) { lazy[2*node] = lazy[node]; lazy[2*node+1] = lazy[node]; } lazy[node] = 0; } } void update_lazy(int node,int st,int dr,int L,int R,int val) { push(node,st,dr); if(st>R || dr<L) return; if(L<=st && dr<=R) { lazy[node]=val; push(node,st,dr); return; } int mid=(st+dr)/2; update_lazy(2*node,st,mid,L,R,val); update_lazy(2*node+1,mid+1,dr,L,R,val); tree[node]=max(tree[2*node],tree[2*node+1]); } void update(int node,int st,int dr,int pos,int val) { if(st==dr) { tree[node]=val; return; } int mid=(st+dr)/2; if(pos<=mid) update(2*node,st,mid,pos,val); else update(2*node+1,mid+1,dr,pos,val); tree[node]=max(tree[2*node],tree[2*node+1]); } int last_stone(int node,int st,int dr,int L,int R,int val) { push(node,st,dr); if(tree[node]<val || st>R || dr<L) return 0; if(st==dr) { if(tree[node]==val) return st; else return 0; } int mid=(st+dr)/2; int ans= last_stone(2*node+1,mid+1,dr,L,R,val); if(ans==0) ans= last_stone(2*node,st,mid,L,R,val); return ans; } void print(int node,int st,int dr) { push(node,st,dr); if(st==dr) { ans[st]=tree[node]; return; } int mid=(st+dr)/2; print(2*node,st,mid); print(2*node+1,mid+1,dr); } void update(int pos,int val) { update(1,1,n,pos,val); } int last(int L,int R,int val) { if(L>R) return 0; return last_stone(1,1,n,L,R,val); } void update_lazy(int L,int R,int val) { update_lazy(1,1,n,L,R,val); } }; segtree seg; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n; v.resize(n+1); ans.resize(n+1); vector<int>aux(n+1); for(int i=1;i<=n;++i) { cin>>v[i]; } // aux=v; // sort(aux.begin()+1,aux.end()); // map<int,int>mp; // int cnt=0; // for(int i=1;i<=n;++i) // { // if(!mp[aux[i]]) // mp[aux[i]]=++cnt; // } // for(int i=1;i<=n;++i) // { // v[i]=mp[v[i]]; // } seg.init(n); for(int i=1;i<=n;++i) { int res=seg.last(1,i-1,v[i]); seg.update(i,v[i]); if(res!=0) { seg.update_lazy(res,i,v[i]); } } seg.print(1,1,n); for(int i=1;i<=n;++i) { cout<<ans[i]<<nl; } return 0; }

Compilation message (stderr)

Main.cpp:9: warning: "LLONG_MAX" redefined
    9 | #define LLONG_MAX 9223372036854775807
      | 
In file included from /usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h:195,
                 from /usr/lib/gcc/x86_64-linux-gnu/10/include/syslimits.h:7,
                 from /usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h:34,
                 from /usr/include/c++/10/climits:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:39,
                 from Main.cpp:1:
/usr/include/limits.h:135: note: this is the location of the previous definition
  135 | #  define LLONG_MAX __LONG_LONG_MAX__
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...