Submission #419402

#TimeUsernameProblemLanguageResultExecution timeMemory
419402cpp219Money (IZhO17_money)C++14
100 / 100
1243 ms58044 KiB
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")

#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 1e6 + 9;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;
set<ll> s;
ll n,a[N],L = inf,R,ans = 1;

bool chk(ll l,ll r){
    ll p = *s.upper_bound(l),q = *prev(s.lower_bound(r));
    return (q < p);
}

ll Travel(ll now){
    ll kq = now;
    ll l = a[now],r = a[now];
    for (ll i = now + 1;i <= n;i++){
        l = min(l,a[i]); r = max(r,a[i]);
        if (!chk(l,r) || a[i] < a[i - 1]) break; kq = i;
    }

    return kq;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define task "test"
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    cin>>n; s.insert(0); s.insert(inf);
    for (ll i = 1;i <= n;i++) cin>>a[i];
    for (ll i = 1;i <= n;){
        ll nxt = Travel(i); //cout<<nxt<<"x\n"; //return 0;
        for (ll j = i;j <= nxt;j++) s.insert(a[j]);
        ans++;
        i = nxt + 1;
    }
    cout<<ans - 1;
}

Compilation message (stderr)

money.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
money.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
money.cpp: In function 'int Travel(int)':
money.cpp:27:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   27 |         if (!chk(l,r) || a[i] < a[i - 1]) break; kq = i;
      |         ^~
money.cpp:27:50: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   27 |         if (!chk(l,r) || a[i] < a[i - 1]) break; kq = i;
      |                                                  ^~
money.cpp: In function 'int main()':
money.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
money.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...