結果
| 問題 | No.743 Segments on a Polygon | 
| コンテスト | |
| ユーザー |  bal4u | 
| 提出日時 | 2019-05-15 07:33:19 | 
| 言語 | C (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 26 ms / 2,000 ms | 
| コード長 | 979 bytes | 
| コンパイル時間 | 507 ms | 
| コンパイル使用メモリ | 29,824 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-09-13 13:09:20 | 
| 合計ジャッジ時間 | 1,393 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 10 | 
コンパイルメッセージ
main.c: In function 'in':
main.c:8:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:14:24: note: in expansion of macro 'gc'
   14 |         int n = 0, c = gc();
      |                        ^~
            
            ソースコード
// yukicoder: No.743 Segments on a Polygon
// 2019.5.15 bal4u
#include <stdio.h>
#include <stdlib.h>
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}
// Bit木 library
#define MAX 200005
int bit[MAX]; int n;
long long sum(int i) {
	long long s = 0;
	while (i > 0) s += bit[i], i -= i & -i;
	return s;
}
void add(int i) {
	while (i <= n) bit[i]++, i += i & -i;
}
typedef struct { int a, b; } T;
T t[100003];
int cmp(const void *a, const void *b) { return ((T *)a)->a - ((T *)b)->a; }
int main()
{
	int i, N, M, a, b;
	long long ans;
	
	N = in(), M = in();
	for (i = 0; i < N; i++) {
		a = in(), b = in();
		if (a < b) t[i].a = a, t[i].b = b;
		else       t[i].a = b, t[i].b = a;
	}
	qsort(t, N, sizeof(T), cmp);
	
	n = M, ans = 0;
	for (i = 0; i < N; i++) {
		ans += sum(t[i].b) - sum(t[i].a);
		add(t[i].b);
	}
	printf("%lld\n", ans);
	return 0;
}
            
            
            
        