結果
| 問題 |
No.743 Segments on a Polygon
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-05-15 07:29:23 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 954 bytes |
| コンパイル時間 | 277 ms |
| コンパイル使用メモリ | 29,824 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-13 13:05:35 |
| 合計ジャッジ時間 | 2,128 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 WA * 1 |
コンパイルメッセージ
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;
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;
}
bal4u