Cod sursa(job #2742953)

Utilizator PredaBossPreda Andrei PredaBoss Data 22 aprilie 2021 13:04:22
Problema Twoton Scor 0
Compilator cpp-64 Status done
Runda acm_2017_ubb4 Marime 0.59 kb
#include <bits/stdc++.h>
#define ll long long
#define rest 19997
using namespace std;
ifstream fin("twoton.in");
ofstream fout("twoton.out");
bool smallest[100005];
int n;
int a[100005];
ll ans;
int main()
{
    fin>>n;
    for(int i=1;i<=n;i++)
        fin>>a[i];

    int small=0;
    for(int i=n;i>=1;i--)
        if(small>a[i])
        {
            small=a[i];
            smallest[i]=true;
        }
    ll cnt=1;
    for(int i=1;i<=n;i++)
    {
        ans=(ans+cnt)%rest;
        if(!smallest[i])
            cnt=(cnt*2LL)%rest;
    }
    fout<<ans;
    return 0;
}