Cod sursa(job #1709196)

Utilizator UNIBUC_Echipa_LachetaBicsi Nitu Velea UNIBUC_Echipa_Lacheta Data 28 mai 2016 11:14:16
Problema Twoton Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 1.66 kb
#include <cassert>
#include <fstream>
#include <cstring>
#include <queue>
#include <algorithm>
#include <bitset>
#include <ctime>
#include <set>
#include <cmath>
#include <iomanip>
#include <map>
#include <stack>
#include <vector>
#include <bitset>

#include <fstream>

using namespace std;

#define FOR(i, a, n) for (int i = a; i <= n; ++i)
#define ROF(i, n, a) for (int i = n; i >= a; i--)
#define FIT(i, v) for (auto &i : v)
#define pb push_back
#define mp make_pair
#define mt make_touple
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef pair<int,int> pii;
const int mod = 19997;
ll powmod(ll a, ll b) {ll res=1; a %= mod; assert(b >= 0); for(; b; b >>= 1) {if (b & 1) res = res * a % mod; a = a * a % mod;} return res;}

const int N = 1000010;

ifstream fin("twoton.in");
ofstream fout("twoton.out");

int a[N], n, cnt[N], ok[N], wt[N];
int wtf(int i) {
    if(ok[i]) {
        return wt[i];
    }
    ok[i] = 1;
    cnt[i]++;
    if (cnt[i] >= mod) {
        cnt[i] -= mod;
    }
    if (i == n - 1) {
        wt[i] = a[i];
        return wt[i];
    }
    if (a[i] < wtf(i + 1)) {
        cnt[i] += cnt[i + 1];
        if (cnt[i] >= mod) {
            cnt[i] -= mod;
        }
        wt[i] = a[i];
        return a[i];
    } else {
        cnt[i] += cnt[i + 1];
        if (cnt[i] >= mod) {
            cnt[i] -= mod;
        }
        cnt[i] += cnt[i + 1];
        if (cnt[i] >= mod) {
            cnt[i] -= mod;
        }
        wt[i] = wtf(i + 1);
        return wt[i];
    }
}
int main() {
    fin >> n;
    FOR(i,0,n-1) {
        fin >> a[i];
    }
    wtf(0);
    fout << cnt[0];
    return 0;
}