結果

問題 No.1282 Display Elements
ユーザー kzyKTkzyKT
提出日時 2020-11-06 22:02:23
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 1,572 bytes
コンパイル時間 1,451 ms
コンパイル使用メモリ 158,696 KB
実行使用メモリ 31,348 KB
最終ジャッジ日時 2023-09-29 18:44:41
合計ジャッジ時間 3,996 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,656 KB
testcase_01 AC 4 ms
7,856 KB
testcase_02 AC 3 ms
7,720 KB
testcase_03 AC 3 ms
7,648 KB
testcase_04 AC 3 ms
7,632 KB
testcase_05 AC 3 ms
7,652 KB
testcase_06 AC 4 ms
7,716 KB
testcase_07 AC 3 ms
7,856 KB
testcase_08 AC 4 ms
7,732 KB
testcase_09 AC 3 ms
7,732 KB
testcase_10 AC 3 ms
7,696 KB
testcase_11 AC 3 ms
7,672 KB
testcase_12 AC 3 ms
7,684 KB
testcase_13 AC 4 ms
7,764 KB
testcase_14 AC 4 ms
7,900 KB
testcase_15 AC 217 ms
29,160 KB
testcase_16 AC 73 ms
16,300 KB
testcase_17 AC 172 ms
25,488 KB
testcase_18 AC 99 ms
18,796 KB
testcase_19 AC 30 ms
9,352 KB
testcase_20 AC 27 ms
9,216 KB
testcase_21 AC 239 ms
31,348 KB
testcase_22 AC 43 ms
9,224 KB
testcase_23 AC 229 ms
31,084 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

class BIT{
public:
  ll n,bit[555555];
  BIT(){fill(bit,bit+555555,0);}
  void add(ll i,ll x){
    while(i<=n){
      bit[i]+=x;
      i+=i&-i;
    }
  }
  ll sum(ll i){
    ll s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }
};

BIT t=BIT();

void Main() {
  ll n;
  cin >> n;
  ll a[n],b[n];
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> b[i];
  sort(a,a+n);
  map<ll,ll> m;
  set<ll> s;
  rep(i,n) {
    s.in(a[i]);
    s.in(b[i]);
  }
  t.n=s.size()+1;
  tr(it,s) {
    ll k=m.size()+1;
    m[*it]=k;
  }
  ll ans=0;
  rep(i,n) {
    t.add(m[b[i]],1);
    ans+=t.sum(m[a[i]]-1);
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
0