Pagini recente » Cod sursa (job #787120) | Cod sursa (job #1597886) | Cod sursa (job #3803) | Cod sursa (job #1027046) | Cod sursa (job #1709209)
#include <cstdio>
#include<utility>
#include<stack>
int n;
int a[1000024];
int count[1000024];
int ret[1000024];
//stack<pair<int,int> > stk;
/*int wtf(int i)
{
count++;
if (count >= 19997) {
count -= 19997;
}
if (i == n - 1) {
return a[i];
}
if (a[i] < wtf(i + 1)) {
return a[i];
} else {
return wtf(i + 1);
}
}*/
void wtf(){
int i;
ret[n-1]=a[n-1];
count[n-1]=1;
for(i=n-2;i>=0;i--){
count[i]=1+count[i+1];
if (a[i]<ret[i+1]){
ret[i]=a[i];
}
else {
ret[i]=ret[i+1];
count[i]+=count[i+1];
}
if (count[i] >= 19997) {
count[i] -= 19997;
}
if (count[i] >= 19997) {
count[i] -= 19997;
}
}
}
//int ret;
/*int wtf(int i)
{
stk.push_back(make_pair(i,0));
while(!stk.empty()){
count++;
if (count >= 19997) {
count -= 19997;
}
if (stk.top().first == n - 1) {
ret=a[stk.top().first];
stk.pop();
}
else
if (a[i] < wtf(i + 1)) {
ret=a[stk.top()];
stk.pop();
}
else {
return wtf(i + 1);
}
}
}*/
int main()
{
FILE *fin = fopen("twoton.in", "r");
FILE *fout = fopen("twoton.out", "w");
fscanf(fin, "%d", &n);
for (int i = 0; i < n; ++i) {
fscanf(fin, "%d", &a[i]);
}
wtf();
fprintf(fout, "%d\n", count[0]);
fclose(fin);
fclose(fout);
}