Submission #1241222

#TimeUsernameProblemLanguageResultExecution timeMemory
1241222hainam2k9Po (COCI21_po)C++20
70 / 70
17 ms1484 KiB
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 1e5+5;
const string NAME = "";
int n,a[MAXN],pos[MAXN],MIN,rs=0;
stack<int> st;
void compress(){
    vector<int> v;
    for(int i = 1; i<=n; ++i)
        v.pb(a[i]);
    sort(v.begin(),v.end());
    for(int i = 1; i<=n; ++i)
        a[i]=lb(v.begin(),v.end(),a[i])-v.begin()+1;
    MIN=v[0];
}
int main()
{
    tt;
    if(fopen((NAME + ".INP").c_str(), "r")) fo;
    cin >> n;
    for(int i = 1; i<=n; ++i)
        cin >> a[i];
    compress();
    if(MIN==0) pos[1]=1;
    for(int i = 1; i<=n; ++i){
        while(!st.empty()&&a[st.top()]>=a[i]) st.pop();
        if(pos[a[i]]==0) ++rs;
        else if(!st.empty()&&st.top()>pos[a[i]]) ++rs;
        pos[a[i]]=i, st.push(i);
    }
    cout << rs;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:36:45: note: in expansion of macro 'fo'
   36 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
Main.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:36:45: note: in expansion of macro 'fo'
   36 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...