답안 #308999

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308999 2020-10-02T14:46:01 Z giorgigagua2006 Exercise Deadlines (CCO20_day1problem2) C++17
17 / 25
178 ms 22904 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,n;
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(int i = 1; i <= n; ++i) 
	upd(i , 1);
	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:40: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]
   40 |   for(j=0;j<v[i].size();j++)
      |           ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5504 KB Output is correct
2 Correct 8 ms 5632 KB Output is correct
3 Correct 8 ms 5504 KB Output is correct
4 Correct 7 ms 5504 KB Output is correct
5 Correct 7 ms 5504 KB Output is correct
6 Correct 7 ms 5504 KB Output is correct
7 Correct 7 ms 5632 KB Output is correct
8 Correct 8 ms 5888 KB Output is correct
9 Correct 7 ms 5632 KB Output is correct
10 Correct 7 ms 5632 KB Output is correct
11 Correct 7 ms 5632 KB Output is correct
12 Correct 7 ms 5632 KB Output is correct
13 Correct 8 ms 5504 KB Output is correct
14 Correct 7 ms 5632 KB Output is correct
15 Correct 8 ms 5504 KB Output is correct
16 Correct 7 ms 5504 KB Output is correct
17 Correct 7 ms 5504 KB Output is correct
18 Correct 7 ms 5504 KB Output is correct
19 Correct 7 ms 5504 KB Output is correct
20 Correct 7 ms 5504 KB Output is correct
21 Correct 8 ms 5504 KB Output is correct
22 Correct 7 ms 5504 KB Output is correct
23 Correct 7 ms 5504 KB Output is correct
24 Correct 7 ms 5504 KB Output is correct
25 Correct 8 ms 5504 KB Output is correct
26 Correct 7 ms 5504 KB Output is correct
27 Correct 7 ms 5504 KB Output is correct
28 Correct 7 ms 5504 KB Output is correct
29 Correct 8 ms 5504 KB Output is correct
30 Correct 7 ms 5504 KB Output is correct
31 Correct 7 ms 5504 KB Output is correct
32 Correct 7 ms 5632 KB Output is correct
33 Correct 7 ms 5632 KB Output is correct
34 Correct 7 ms 5504 KB Output is correct
35 Correct 7 ms 5504 KB Output is correct
36 Correct 7 ms 5632 KB Output is correct
37 Correct 7 ms 5632 KB Output is correct
38 Correct 7 ms 5504 KB Output is correct
39 Correct 7 ms 5504 KB Output is correct
40 Correct 8 ms 5504 KB Output is correct
41 Correct 7 ms 5432 KB Output is correct
42 Correct 8 ms 5504 KB Output is correct
43 Correct 7 ms 5604 KB Output is correct
44 Correct 4 ms 5376 KB Output is correct
45 Correct 4 ms 5376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5504 KB Output is correct
2 Correct 8 ms 5632 KB Output is correct
3 Correct 8 ms 5504 KB Output is correct
4 Correct 7 ms 5504 KB Output is correct
5 Correct 7 ms 5504 KB Output is correct
6 Correct 7 ms 5504 KB Output is correct
7 Correct 7 ms 5632 KB Output is correct
8 Correct 8 ms 5888 KB Output is correct
9 Correct 7 ms 5632 KB Output is correct
10 Correct 7 ms 5632 KB Output is correct
11 Correct 7 ms 5632 KB Output is correct
12 Correct 7 ms 5632 KB Output is correct
13 Correct 8 ms 5504 KB Output is correct
14 Correct 7 ms 5632 KB Output is correct
15 Correct 8 ms 5504 KB Output is correct
16 Correct 7 ms 5504 KB Output is correct
17 Correct 7 ms 5504 KB Output is correct
18 Correct 7 ms 5504 KB Output is correct
19 Correct 7 ms 5504 KB Output is correct
20 Correct 7 ms 5504 KB Output is correct
21 Correct 8 ms 5504 KB Output is correct
22 Correct 7 ms 5504 KB Output is correct
23 Correct 7 ms 5504 KB Output is correct
24 Correct 7 ms 5504 KB Output is correct
25 Correct 8 ms 5504 KB Output is correct
26 Correct 7 ms 5504 KB Output is correct
27 Correct 7 ms 5504 KB Output is correct
28 Correct 7 ms 5504 KB Output is correct
29 Correct 8 ms 5504 KB Output is correct
30 Correct 7 ms 5504 KB Output is correct
31 Correct 7 ms 5504 KB Output is correct
32 Correct 7 ms 5632 KB Output is correct
33 Correct 7 ms 5632 KB Output is correct
34 Correct 7 ms 5504 KB Output is correct
35 Correct 7 ms 5504 KB Output is correct
36 Correct 7 ms 5632 KB Output is correct
37 Correct 7 ms 5632 KB Output is correct
38 Correct 7 ms 5504 KB Output is correct
39 Correct 7 ms 5504 KB Output is correct
40 Correct 8 ms 5504 KB Output is correct
41 Correct 7 ms 5432 KB Output is correct
42 Correct 8 ms 5504 KB Output is correct
43 Correct 7 ms 5604 KB Output is correct
44 Correct 4 ms 5376 KB Output is correct
45 Correct 4 ms 5376 KB Output is correct
46 Runtime error 178 ms 22904 KB Execution killed with signal 11 (could be triggered by violating memory limits)
47 Halted 0 ms 0 KB -