답안 #684226

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684226 2023-01-20T18:00:34 Z sudheerays123 Po (COCI21_po) C++17
20 / 70
52 ms 15140 KB
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
const ll N = 1e5+5 , INF = 1e18 , MOD = 1e9+7;

vector<ll> seg(4*N);
vector<ll> a(N);

void build(ll node , ll left , ll right){

	if(left == right){
		seg[node] = a[left];
		return;
	}

	ll mid = (left+right)/2;

	build(2*node,left,mid);
	build(2*node+1,mid+1,right);

	seg[node] = min(seg[2*node],seg[2*node+1]);
}

ll query(ll node , ll left , ll right , ll ql , ll qr){

	if(left >= ql && right <= qr) return seg[node];
	if(left > qr || right < ql) return INF;

	ll mid = (left+right)/2;

	ll l = query(2*node,left,mid,ql,qr);
	ll r = query(2*node+1,mid+1,right,ql,qr);

	return min(l,r);
}

void solve(){

	ll n;
	cin >> n;

	map<ll,vector<ll>> m;

	for(ll i = 1; i <= n; i++){
		cin >> a[i];
		m[a[i]].push_back(i);
	}

	build(1,1,n);
	
	ll ans = n;

	for(auto u : m){
		vector<ll> ind = u.second;
		for(ll i = 1; i < ind.size();i++) 
			if(query(1,1,n,ind[i-1],ind[i]) >= u.first) 
				ans--;
	}

	cout << ans;
}

int main(){

	fast;

	ll tc = 1;
	// cin >> tc;
	while(tc--) solve();

	return 0;
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:56:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for(ll i = 1; i < ind.size();i++)
      |                 ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Incorrect 3 ms 4180 KB Output isn't correct
3 Incorrect 3 ms 4180 KB Output isn't correct
4 Incorrect 19 ms 4928 KB Output isn't correct
5 Incorrect 29 ms 5124 KB Output isn't correct
6 Correct 52 ms 9712 KB Output is correct
7 Incorrect 45 ms 15140 KB Output isn't correct