# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1159044 | PieArmy | Money (IZhO17_money) | C++20 | 0 ms | 328 KiB |
typedef long long ll;
ll pie(ll army){return (1ll<<army);}
#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define endl '\n'
#define mid ((left+right)>>1)
const ll inf=2000000000000000005;
const int sonsuz=2000000005;
using namespace std;
ll fpow(ll x,ll y,ll m=0){if(y<0){cout<<"powError";return -1;}if(m)x%=m;ll res=1;while(y>0){if(y&1)res*=x;x*=x;if(m){x%=m;res%=m;}y>>=1;}return res;}
int n;
int arr[1000023],per[1000023],lef[1000023],rig[1000023],cnt[1000023];
void delet(int x){
lef[rig[x]]=lef[x];
rig[lef[x]]=rig[x];
}
void code(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>arr[i];
cnt[arr[i]]++;
}
iota(per+1,per+n+1,1);
sort(per+1,per+n+1,[&](const int &x,const int &y){
if(arr[x]==arr[y])return x<y;
return arr[x]<arr[y];
});
per[n+1]=1e6+1;
lef[0]=arr[per[1]];
rig[1000001]=arr[per[n]];
for(int i=1;i<=n;i++){
if(arr[per[i]]==arr[per[i-1]]){
continue;
}
else lef[arr[per[i]]]=arr[per[i-1]];
}
for(int i=n;i>=1;i--){
if(arr[per[i]]==arr[per[i+1]]){
continue;
}
else rig[arr[per[i]]]=arr[per[i+1]];
}
int ans=1;
for(int i=n;i>1;i--){
if(arr[i-1]!=arr[i]&&lef[arr[i]]!=arr[i-1]){
ans++;
}
if(--cnt[arr[i]]==0)delet(arr[i]);
}
cout<<ans;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
bool usaco=0;if(usaco){freopen(".in","r",stdin);freopen(".out","w",stdout);}
int t=1;
if(!t)cin>>t;
while(t--){code();cout<<endl;}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |