提出 #53851581


ソースコード 拡げる

// #pragma GCC optimize("Ofast,unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf (ll)1e18
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define fi first
#define se second
#define lll __int128
const int N = 1e6 + 5;

//树状数组 [1,n]
struct BIT {
    ll n;
    vl tree;
    void init(ll n) { //初始化
        this->n = n;
        this->tree = vl(n + 1);
    }
    ll lowbit(ll x) {
        return x & (-x);
    }
    void upd(ll x, ll d) { //单修
        while (x <= n) {
            tree[x] += d;
            x += lowbit(x);
        }
    }
    ll query(ll x) { //查[1,x]
        ll ans = 0;
        while (x) {
            ans += tree[x];
            x -= lowbit(x);
        }
        return ans;
    }
    ll query(ll l, ll r) { //查[l,r]
        return query(r) - query(l - 1);
    }
} bt;

void solve() {
	ll n;
	cin >> n;
	vector<pll> v(n + 1);
	set<ll> s;
	for (ll i = 1; i <= n; i++) {
		cin >> v[i].fi >> v[i].se;
		s.insert(v[i].fi);
		s.insert(v[i].se);
	}
	map<ll, ll> mp;
	ll id = 1;
	for (ll x : s) {
		mp[x] = id++;
	}
	bt.init(id);
	for (ll i = 1; i <= n; i++) {
		v[i].fi = mp[v[i].fi];
		v[i].se = mp[v[i].se];
	}
	sort(v.begin() + 1, v.end());
	ll ans = 0;
	for (ll i = 1; i <= n; i++) {
		auto [l, r] = v[i];
		ans += bt.query(l, id);
		bt.upd(r, 1);
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
	solve();
	return 0;
}

提出情報

提出日時
問題 D - Intersecting Intervals
ユーザ TopCloser
言語 C++ 20 (gcc 12.2)
得点 400
コード長 1555 Byte
結果 AC
実行時間 1913 ms
メモリ 128312 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 22
セット名 テストケース
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 1 ms 3356 KiB
00_sample_02.txt AC 1 ms 3548 KiB
00_sample_03.txt AC 1 ms 3428 KiB
01_random_01.txt AC 1757 ms 127948 KiB
01_random_02.txt AC 670 ms 67688 KiB
01_random_03.txt AC 1693 ms 127972 KiB
01_random_04.txt AC 940 ms 86428 KiB
01_random_05.txt AC 1745 ms 127872 KiB
01_random_06.txt AC 1574 ms 121732 KiB
01_random_07.txt AC 1750 ms 127948 KiB
01_random_08.txt AC 907 ms 82204 KiB
01_random_09.txt AC 1913 ms 127928 KiB
01_random_10.txt AC 1705 ms 122108 KiB
01_random_11.txt AC 1820 ms 127876 KiB
01_random_12.txt AC 58 ms 12036 KiB
01_random_13.txt AC 1808 ms 127880 KiB
01_random_14.txt AC 945 ms 84316 KiB
01_random_15.txt AC 1753 ms 127916 KiB
02_handmade_01.txt AC 646 ms 128312 KiB
02_handmade_02.txt AC 654 ms 128240 KiB
02_handmade_03.txt AC 466 ms 69608 KiB
02_handmade_04.txt AC 56 ms 11092 KiB