답안 #36060

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
36060 2017-12-05T02:13:05 Z UncleGrandpa925 Money (IZhO17_money) C++14
0 / 100
3 ms 9828 KB
/*input
4
4 6 1 7
*/
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define mp make_pair
#define N 1000005
#define bit(x,y) ((x>>y)&1LL)
#define na(x) (#x) << ":" << x
ostream& operator << (ostream &os, vector<int>&x) {
	for (int i = 0; i < x.size(); i++) os << x[i] << sp;
	return os;
}
ostream& operator << (ostream &os, pair<int, int> x) {
	cout << x.fi << sp << x.se << sp;
	return os;
}
ostream& operator << (ostream &os, vector<pair<int, int> >&x) {
	for (int i = 0; i < x.size(); i++) os << x[i] << endl;
	return os;
}

int n;
int a[N];
int tree[N];

void update(int i, int val) {
	for (; i; i -= i & -i) tree[i] = min(tree[i], val);
}

int get(int i) {
	int ret = 1e9;
	for (; i <= N - 5; i += i & -i){
		ret = min(ret, tree[i]);
	}
	return ret;
}

signed main() {
	memset(tree, 127, sizeof(tree));
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int t; scanf("%d", &a[i]);
	}
	int last = a[0], ans = 0;
	int mx = 1e9;
	update(a[0], a[0] - 1);
	int len = 1;
	for (int i = 1; i < n; i++) {
		if (a[i] < last) {
			ans++;
			mx = get(a[i]);
		}
		else if (a[i] > mx) {
			ans++;
			mx = get(a[i]);
		}
		last = a[i];
		update(a[i], a[i] - 1);
	}
	ans++;
	printf("%d\n", ans);
}

Compilation message

money.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<int>&)':
money.cpp:16:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << sp;
                    ^
money.cpp: In function 'std::ostream& operator<<(std::ostream&, std::vector<std::pair<int, int> >&)':
money.cpp:24:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < x.size(); i++) os << x[i] << endl;
                    ^
money.cpp: In function 'int main()':
money.cpp:48:7: warning: unused variable 't' [-Wunused-variable]
   int t; scanf("%d", &a[i]);
       ^
money.cpp:53:6: warning: unused variable 'len' [-Wunused-variable]
  int len = 1;
      ^
money.cpp:46:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
money.cpp:48:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int t; scanf("%d", &a[i]);
                            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 9828 KB Output is correct
2 Correct 0 ms 9828 KB Output is correct
3 Correct 3 ms 9828 KB Output is correct
4 Incorrect 0 ms 9828 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 9828 KB Output is correct
2 Correct 0 ms 9828 KB Output is correct
3 Correct 3 ms 9828 KB Output is correct
4 Incorrect 0 ms 9828 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 9828 KB Output is correct
2 Correct 0 ms 9828 KB Output is correct
3 Correct 3 ms 9828 KB Output is correct
4 Incorrect 0 ms 9828 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 9828 KB Output is correct
2 Correct 0 ms 9828 KB Output is correct
3 Correct 3 ms 9828 KB Output is correct
4 Incorrect 0 ms 9828 KB Output isn't correct
5 Halted 0 ms 0 KB -