답안 #293525

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
293525 2020-09-08T07:18:21 Z toloraia Exercise Deadlines (CCO20_day1problem2) C++14
0 / 25
5 ms 5248 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define ll __int128
#define ll long long
#define int long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define y1 y122
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
/*
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")

#pragma GCC target("avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")

#pragma comment(linker, "/STACK: 20000000005")
*/

using namespace std;

const int N = 200005;

int n, F[N];

void upd (int x){
    for (; x <= n; x += x & -x)
        F[x]++;
}

int dat (int x){
    int ans = 0;
    for (; x > 0; x &= x-1)
        ans += F[x];
    return ans;
}

int ans;
int a[N];
vector < int > V[N];

priority_queue < int > Q;

main()
{
    //freopen ("in.in", "r", stdin);freopen ("out.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        a[i] = n - a[i] + 1;
    }
    reverse (a+1, a+n+1);
    for (int i = 1; i <= n; i++)
        V[a[i]].pb (i);
    for (int i = 1; i <= n; i++){
        for (int x : V[i])
            Q.push (-x);
        if (Q.size() == 0){
            cout << -1 << endl;
            return 0;
        }
        int x = -Q.top();
        Q.pop();
        ans += dat (x);
        upd (x);
    }
    cout << ans << endl;
}

Compilation message

Main.cpp:19:1: warning: "/*" within comment [-Wcomment]
   19 | /*
      |  
Main.cpp:55:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   55 | main()
      |      ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 5248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 5248 KB Output isn't correct
2 Halted 0 ms 0 KB -