Submission #467125

# Submission time Handle Problem Language Result Execution time Memory
467125 2021-08-21T18:30:39 Z aryan12 Money (IZhO17_money) C++17
0 / 100
0 ms 204 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e6 + 5;
int bit[N];

//3 5 4 6
//4 5 6 3
//3 4 5 4

void Update(int pos, int val) {
	for(int i = pos; i < N; i += (i & (-i))) {
		bit[i] += val;
	}
}

int Query(int pos) {
	int ans = 0;
	for(int i = pos; i > 0; i -= (i & (-i))) {
		ans += bit[i];
	}
	return ans;
}

void Solve() {
	int n;
	cin >> n;
	int a[n + 1];
	map<int, int> cc;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		cc[a[i]] = 1;
	}
	int tem = 1;
	for(auto i: cc) {
		cc[i.first] = tem++;
	}
	for(int i = 1; i <= n; i++) {
		a[i] = cc[a[i]];
	}
	vector<int> temp;
	temp.push_back(a[1]);
	int cur_min = a[1], cur_max = a[1];
	int prev = 1;
	int ans = 1;
	for(int i = 2; i <= n; i++) {
		if(a[i] < a[i - 1]) {
			ans++;
			for(int j = 0; j < temp.size(); j++) {
				if(temp[j] > cur_min && temp[j] < cur_max) {
					ans++;
					break; 
				}
			}
			for(int j = i - 1; j >= prev; j--) {
				temp.push_back(a[j]);
			}
			prev = i;
			cur_min = INT_MAX;
			cur_max = -1;
		}
		cur_max = max(cur_max, a[i]);
		cur_min = min(cur_min, a[i]);
	}
	for(int j = 0; j < temp.size(); j++) {
		if(temp[j] > cur_min && temp[j] < cur_max) {
			ans++;
			break; 
		}
	}

	cout << ans << "\n";
}

int32_t main() {
	auto begin = std::chrono::high_resolution_clock::now();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) {
		Solve();
	}
	auto end = std::chrono::high_resolution_clock::now();
    auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
    cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
	return 0;
}

Compilation message

money.cpp: In function 'void Solve()':
money.cpp:52:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |    for(int j = 0; j < temp.size(); j++) {
      |                   ~~^~~~~~~~~~~~~
money.cpp:68:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |  for(int j = 0; j < temp.size(); j++) {
      |                 ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -