답안 #684219

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684219 2023-01-20T17:29:14 Z sudheerays123 Po (COCI21_po) C++17
20 / 70
46 ms 15152 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;

		ll last = 0;

		for(ll i = 1; i < ind.size();){

			if(query(1,1,n,ind[last],ind[i]) < u.first){
				i++;
				last = i;
				continue;
			}

			ans--;
			i++;
		}
	}

	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:60: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]
   60 |   for(ll i = 1; i < ind.size();){
      |                 ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Incorrect 2 ms 4180 KB Output isn't correct
3 Incorrect 2 ms 4180 KB Output isn't correct
4 Incorrect 14 ms 4936 KB Output isn't correct
5 Incorrect 23 ms 5132 KB Output isn't correct
6 Correct 45 ms 9712 KB Output is correct
7 Incorrect 46 ms 15152 KB Output isn't correct