답안 #308993

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308993 2020-10-02T14:26:54 Z giorgigagua2006 Exercise Deadlines (CCO20_day1problem2) C++17
0 / 25
8 ms 5504 KB
#include<bits/stdc++.h>
using namespace std;
long long  f[12312],n=12312,p,k;
priority_queue<long long>q;
void upd(int i, int value)
{
	while(i<n)
	{
		f[i]+=value;
		i+=(i & -i);
	}
}

int sum(int i)
{
	int s=0;
	while(i)
	{
		s+=f[i];
		i-=(i & -i);
	}
	return s;
}

long long i,j,mx,ans;
long long d[223123];
vector<long long>v[213213];
int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>d[i];
		v[d[i]].push_back(i);
	}
	for(i=n;i>0;i--)
	{
		for(j=0;j<v[i].size();j++)
		q.push(v[i][j]);
		if(q.size()==0)
		{
			cout<<-1;
			return 0;
		}
		mx=q.top();
		q.pop();
		upd(n-mx+1,1);
        ans+=sum(n-mx+1);
	}
	cout<<ans;
	
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:38:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int, std::allocator<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |   for(j=0;j<v[i].size();j++)
      |           ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 5504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 5504 KB Output isn't correct
2 Halted 0 ms 0 KB -