Submission #1298593

#TimeUsernameProblemLanguageResultExecution timeMemory
1298593minggaMoney (IZhO17_money)C++20
0 / 100
2 ms576 KiB
#include "bits/stdc++.h"

using namespace std;

#ifdef LOCAL
#include "D:/debug.h"
#define debug(...) cerr << "\033[35m" << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 240408
#endif

#define ln "\n"
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ll long long
const int mod = 1e9 + 7;
const ll inf = 2e18;

const int N = 1e5 + 7;

int n, a[N];

signed main() {
    cin.tie(0) -> sync_with_stdio(0);
    #define task ""
    if(fopen(task ".INP", "r")) {
        freopen(task ".INP", "r", stdin);
        freopen(task ".OUT", "w", stdout);
    }
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];
    set<pair<int, int>> s;
	s.insert({a[1], 1});
	int ans = 1;
	for(int i = 2; i <= n; i++) {
		auto it = s.find(make_pair(a[i - 1], i - 1));
		debug(i, a[i], (*it));
		if((*it).fi > a[i]) {
			ans++;
			s.insert({a[i], i});
			continue;
		}
		it++;
		if(it == s.end()) {
			s.insert({a[i], i});
			continue;
		}
		debug(i, a[i], (*it));
		if((*it).fi < a[i]) ans++;
		s.insert({a[i], i});
	}
	cout << ans << ln;
    cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC;
}

Compilation message (stderr)

money.cpp: In function 'int main()':
money.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         freopen(task ".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
money.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         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...