답안 #273469

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
273469 2020-08-19T05:30:05 Z 송준혁(#5100) Exercise Deadlines (CCO20_day1problem2) C++17
0 / 25
3 ms 384 KB
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int N;
LL ans;
pii A[202020];
int T[202020];
priority_queue<int> PQ;

void upd(int k){for(;k<=N;k+=k&-k)T[k]++;}
int read(int k){int r=0; for(;k;k^=k&-k)r+=T[k]; return r;}

int main(){
	scanf("%d", &N);
	for (int i=1; i<=N; i++) scanf("%d", &A[i].fi), A[i].se=i;
	sort(A+1, A+N+1);
	int t=N;
	for (int i=N; i>0; i--){
		while (t>0 && A[t].fi>=i) PQ.push(A[i].se), t--;
		if (PQ.empty()){
			puts("-1");
			return 0;
		}
		int x = PQ.top(); PQ.pop();
		ans += read(x), upd(x);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |  scanf("%d", &N);
      |  ~~~~~^~~~~~~~~~
Main.cpp:19:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |  for (int i=1; i<=N; i++) scanf("%d", &A[i].fi), A[i].se=i;
      |                           ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -