Submission #888226

# Submission time Handle Problem Language Result Execution time Memory
888226 2023-12-16T14:23:22 Z pcc Money (IZhO17_money) C++14
0 / 100
1 ms 6492 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>


const int mxn = 1e6+10;
int n;
int arr[mxn],pos[mxn],bit[mxn];
bitset<mxn> done;
int sh = 0;
int ans = 0;

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

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];
		pos[arr[i]] = i;
	}
	for(int i = 1;i<=n;i++)assert(pos[i]);
	for(int i = n;i>=1;i--){
		int p = pos[i];
		if(p == n||arr[p+1]-getval(arr[p+1]) != i+1)ans++;
		else{
			if(!done[p+1])done[p+1] = true,modify(arr[p+1],1);
			done[p] = true,modify(i,1);
		}
	}
	cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Incorrect 1 ms 4444 KB Output isn't correct
3 Halted 0 ms 0 KB -