Submission #534988


Source Code Expand

#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rrep(i,n) for(int i = 1; i <= n; ++i)
#define drep(i,n) for(int i = n-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}

const int MX = 100005, INF = 1000010000;
const ll LINF = 1000000000000000000ll;
const double eps = 1e-10;

// Binary Indexed Tree
struct bit{
  typedef int TT;
  vector<TT> d; int x2;
  bit(){}
  bit(int mx){ x2 = 1; while(x2 < mx) x2 <<= 1; d.resize(x2+1);}
  void add(int i, TT x=1){ for(++i;i<=x2;i+=i&-i) d[i] += x;}
  TT sum(int i){ ++i;
    TT x = 0; for(;i;i-=i&-i) x += d[i];
    return x;
  }
};
//

int main() {
  df(n);
  vi a, b;
  rep(i,n) b.pb(in());
  rep(i,n) a.pb(in());
  vvi d(n);
  rep(i,n) {
    int p = upper_bound(rng(a),b[i])-a.begin();
    if (p == 0) {
      cout<<-1<<endl;
      return 0;
    }
    d[p-1].pb(i);
  }
  priority_queue<int> q;
  drep(i,n) {
    for (int x : d[i]) q.push(x);
    if (sz(q) == 0) {
      cout<<-1<<endl;
      return 0;
    }
    b[i] = q.top(); q.pop();
  }
  bit t(n+2);
  ll ans = 0;
  rep(i,n) {
    ans += i-t.sum(b[i]);
    t.add(b[i]);
  }
  cout<<ans<<endl;
  return 0;
}




Submission Info

Submission Time
Task G - ケンドー
User snuke
Language C++11 (GCC 4.9.2)
Score 300
Code Size 2181 Byte
Status AC
Exec Time 188 ms
Memory 7944 KB

Compile Error

./Main.cpp: In function ‘int in()’:
./Main.cpp:38:40: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 inline int in() { int x; scanf("%d",&x); return x;}
                                        ^

Judge Result

Set Name Small All
Score / Max Score 3 / 3 297 / 297
Status
AC × 13
AC × 38
Set Name Test Cases
Small 00_small_sample_00.txt, 00_small_sample_01.txt, 00_small_sample_02.txt, 10_small_01.txt, 10_small_02.txt, 10_small_03.txt, 10_small_04.txt, 10_small_05.txt, 10_small_06.txt, 10_small_07.txt, 10_small_08.txt, 10_small_09.txt, 10_small_10.txt
All 00_small_sample_00.txt, 00_small_sample_01.txt, 00_small_sample_02.txt, 10_small_01.txt, 10_small_02.txt, 10_small_03.txt, 10_small_04.txt, 10_small_05.txt, 10_small_06.txt, 10_small_07.txt, 10_small_08.txt, 10_small_09.txt, 10_small_10.txt, 20_large_01.txt, 20_large_02.txt, 20_large_03.txt, 20_large_04.txt, 20_large_05.txt, 20_large_06.txt, 20_large_07.txt, 20_large_08.txt, 20_large_09.txt, 20_large_10.txt, 30_maxcase_01.txt, 31_almost_maxcase_01.txt, 31_almost_maxcase_02.txt, 31_almost_maxcase_03.txt, 31_almost_maxcase_04.txt, 31_almost_maxcase_05.txt, 40_bad_maxcase_01.txt, 40_bad_maxcase_02.txt, 40_bad_maxcase_03.txt, 40_bad_maxcase_04.txt, 40_bad_maxcase_05.txt, 41_bad_shufflecase_01.txt, 41_bad_shufflecase_02.txt, 41_bad_shufflecase_03.txt, 41_bad_shufflecase_04.txt
Case Name Status Exec Time Memory
00_small_sample_00.txt AC 188 ms 1164 KB
00_small_sample_01.txt AC 33 ms 1164 KB
00_small_sample_02.txt AC 32 ms 1260 KB
10_small_01.txt AC 33 ms 1164 KB
10_small_02.txt AC 33 ms 1164 KB
10_small_03.txt AC 34 ms 1176 KB
10_small_04.txt AC 33 ms 1168 KB
10_small_05.txt AC 34 ms 1168 KB
10_small_06.txt AC 34 ms 1168 KB
10_small_07.txt AC 34 ms 1168 KB
10_small_08.txt AC 32 ms 1168 KB
10_small_09.txt AC 32 ms 1200 KB
10_small_10.txt AC 32 ms 1200 KB
20_large_01.txt AC 110 ms 5648 KB
20_large_02.txt AC 107 ms 5632 KB
20_large_03.txt AC 113 ms 5800 KB
20_large_04.txt AC 113 ms 5828 KB
20_large_05.txt AC 112 ms 5764 KB
20_large_06.txt AC 109 ms 5764 KB
20_large_07.txt AC 107 ms 5512 KB
20_large_08.txt AC 112 ms 5800 KB
20_large_09.txt AC 116 ms 5800 KB
20_large_10.txt AC 110 ms 5640 KB
30_maxcase_01.txt AC 104 ms 7908 KB
31_almost_maxcase_01.txt AC 119 ms 7936 KB
31_almost_maxcase_02.txt AC 107 ms 7692 KB
31_almost_maxcase_03.txt AC 112 ms 7816 KB
31_almost_maxcase_04.txt AC 110 ms 7944 KB
31_almost_maxcase_05.txt AC 111 ms 7840 KB
40_bad_maxcase_01.txt AC 105 ms 7168 KB
40_bad_maxcase_02.txt AC 105 ms 7176 KB
40_bad_maxcase_03.txt AC 107 ms 7428 KB
40_bad_maxcase_04.txt AC 104 ms 7160 KB
40_bad_maxcase_05.txt AC 105 ms 7172 KB
41_bad_shufflecase_01.txt AC 124 ms 7428 KB
41_bad_shufflecase_02.txt AC 119 ms 7172 KB
41_bad_shufflecase_03.txt AC 121 ms 7300 KB
41_bad_shufflecase_04.txt AC 116 ms 7180 KB