답안 #977455

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
977455 2024-05-08T02:31:06 Z shoryu386 Money (IZhO17_money) C++17
0 / 100
5 ms 4700 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define MX 1000007
int fwt[MX];
#define lsb(x) (x&(-x))

void update(int x, int k){
	x++;
	
	for (; x < MX; x += lsb(x)){
		fwt[x] += k;
	}
}

int sum(int x){
	x++;
	
	int res = 0;
	for (; x != 0; x -= lsb(x)){
		res += fwt[x];
	}
	
	return res;
}

int query(int a, int b){
	return sum(b) - sum(a-1);
}

main(){ ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n; cin >> n;
	//attempt greedy
	
	int arr[n]; for (int x = 0; x < n; x++) cin >> arr[x];
	
	bitset<1000007> taken;
	int ans = 0;
	for (int zzz = 0; zzz < n; zzz++){
		if (taken[zzz]){
			continue;
		}
		
		ans++;
		taken[zzz] = 1;
		
		vector<int> items; items.push_back(arr[zzz]);
		
		for (int y = zzz+1; y < n; y++){
			if (items.back() <= arr[y] && query(arr[zzz]+1, arr[y]-1) == 0){
				taken[y] = 1;
				items.push_back(arr[y]);
			}
			else{
				break;
			}
		}
		
		for (auto y : items){
			update(y, 1);
		}
		
	}
	
	cout << ans;
	
	
}

Compilation message

money.cpp:33:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   33 | main(){ ios_base::sync_with_stdio(0); cin.tie(0);
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4696 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 2 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Incorrect 0 ms 604 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4696 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 2 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Incorrect 0 ms 604 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4696 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 2 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Incorrect 0 ms 604 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4696 KB Output is correct
2 Correct 1 ms 4700 KB Output is correct
3 Correct 1 ms 4700 KB Output is correct
4 Correct 1 ms 4700 KB Output is correct
5 Correct 2 ms 4700 KB Output is correct
6 Correct 1 ms 4700 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Incorrect 0 ms 604 KB Output isn't correct
9 Halted 0 ms 0 KB -