답안 #763423

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
763423 2023-06-22T09:46:15 Z KN200711 Money (IZhO17_money) C++14
0 / 100
1 ms 340 KB
# include <bits/stdc++.h>
using namespace std;

const int MXN = 1e6;
int fen[1000001];

void add(int a, int c) {
	while(a <= MXN) {
		fen[a] += c;
		a += a&(-a);
	}
	return;
}

int qry(int a) {
	int res = 0;
	while(a > 0) {
		res += fen[a];
		a -= a&(-a);
	}
	return res;
}

int main() {
	int N;
	scanf("%d", &N);
	
	vector<int> arr(N);
	for(int i=0;i<N;i++) scanf("%d", &arr[i]);
	
	for(int i=1;i<=N;i++) {
		add(i, 1);
	}
	
	int ans = 0;
	for(int i=N-1;i>=0;i--) {
		int nw = i;
		int ls = qry(arr[i]);
		i--;
		while(i >= 0 && qry(arr[i]) == ls - 1) {
			i--;
			ls--;
		}
		ans++;
		i++;
		for(int c=i;c<=nw;c++) add(arr[c], -1);
	}
	printf("%d\n", ans);
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
money.cpp:29:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |  for(int i=0;i<N;i++) scanf("%d", &arr[i]);
      |                       ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 0 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -