Submission #359055

# Submission time Handle Problem Language Result Execution time Memory
359055 2021-01-26T09:40:41 Z Ahmad_Hasan Money (IZhO17_money) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);      cout.tie(0);
    int n;
    cin>>n;
    vector<int>v(n);

    for(int i=0;i<n;i++)
        cin>>v[i];
    int ans=0;
    set<int>ms;
    int f=0;
    int l=0;
    int vls[1e6+5]={0};
    for(int i=0;i<n;i++){
        set<int>::iterator it1=ms.lower_bound(v[i]);
        set<int>::iterator it2=ms.upper_bound(v[i]);

        if((i+1<n)&&(v[i+1]<v[i]||(it2!=ms.end()&&*it2<v[i+1])||(it1!=ms.end()&&*it1>v[l]&&*it1<v[i+1]))){
            ans++;
            for(int j=l;j<=i;j++){
                if(!vls[v[j]])
                    ms.insert(v[j]);
                vls[v[j]]=1;
            }

            l=i+1;
        }

        if(i==n-1)
            ans++;
    }

    cout<<ans<<'\n';



    return 0;
}
/**
7
2 4 6 1 3 5 7
6
3 6 4 5 1 2
*/

Compilation message

money.cpp: In function 'int main()':
money.cpp:17:16: error: conversion from 'double' to 'long unsigned int' in a converted constant expression
   17 |     int vls[1e6+5]={0};
      |             ~~~^~
money.cpp:17:16: error: could not convert '(1.0e+6 + (double)5)' from 'double' to 'long unsigned int'
money.cpp:17:16: error: size of array 'vls' has non-integral type 'double'
money.cpp:15:9: warning: unused variable 'f' [-Wunused-variable]
   15 |     int f=0;
      |         ^