結果

問題 No.743 Segments on a Polygon
ユーザー bal4ubal4u
提出日時 2019-05-15 07:29:23
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 954 bytes
コンパイル時間 382 ms
コンパイル使用メモリ 29,084 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-10-11 14:23:59
合計ジャッジ時間 2,230 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
4,352 KB
testcase_01 AC 25 ms
4,352 KB
testcase_02 AC 26 ms
4,348 KB
testcase_03 AC 25 ms
4,348 KB
testcase_04 AC 25 ms
4,352 KB
testcase_05 AC 25 ms
4,352 KB
testcase_06 AC 25 ms
4,352 KB
testcase_07 AC 25 ms
4,352 KB
testcase_08 AC 25 ms
4,348 KB
testcase_09 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:8:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:14:24: 備考: in expansion of macro ‘gc’
   14 |         int n = 0, c = gc();
      |                        ^~

ソースコード

diff #

// 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;
int sum(int i) {
	int 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, 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("%d\n", ans);
	return 0;
}
0