第一次写Acwing的周赛,前两道题挺简单,这道题也不难,考场上交上去的代码过了10/16,我以为我哪里逻辑有错,结果下考了才知道是我没有定义long long ,用的int,AC就这么远离了我,心痛。
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+10;
const int mod=998244353 ;
#define ll long long
int a[N];
map<int,int> m;
ll fun(ll a,ll k)
{
ll res=1;
while(k)
{
if(k&1) res=((res%mod)*(a%mod))%mod;
a=((a%mod)*(a%mod))%mod;
k/=2;
}
return res;
}
int main()
{
int n;
cin>>n;
int num=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
m[a[i]]=i;
}
int tmp=m[a[1]];
for(int i=1;i<=n;i++)
{
if(i>tmp) num++;
tmp=max(tmp,m[a[i]]);
}
cout<<fun(2,num);
return 0;
}