답안 #888248

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
888248 2023-12-16T16:00:48 Z pcc Money (IZhO17_money) C++14
0 / 100
2 ms 4700 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
#define tiii tuple<int,int,int>


const int mxn = 1e6+10;

int arr[mxn];
int n;
int bit[mxn];

void modify(int p,int val){
	for(;p<mxn;p+=p&-p)bit[p] += val;
	return;
}
int getval(int p){
	int re = 0;
	for(;p>0;p-= p&-p)re += bit[p];
	return re;
}

set<int> st;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i = 1;i<=n;i++){
		cin>>arr[i];
		st.insert(arr[i]);
	}
	assert(st.size() == n&&*st.rbegin() == n);
	int ans = 0;
	for(int i = n;i>=1;){
		int now = arr[i]-getval(arr[i]);
		int pt = i;
		for(;arr[pt]-getval(arr[pt]) == now&&pt>0;pt--,now--)modify(arr[pt],1);
		ans++;
		//cout<<pt<<' '<<i<<endl;
		i = pt;
	}
	cout<<ans;
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from money.cpp:1:
money.cpp: In function 'int main()':
money.cpp:38:19: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   38 |  assert(st.size() == n&&*st.rbegin() == n);
      |         ~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Runtime error 2 ms 4700 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Runtime error 2 ms 4700 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Runtime error 2 ms 4700 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Runtime error 2 ms 4700 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -