結果
| 問題 |
No.743 Segments on a Polygon
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2018-10-11 13:13:10 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,555 bytes |
| コンパイル時間 | 865 ms |
| コンパイル使用メモリ | 87,200 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-12 17:36:16 |
| 合計ジャッジ時間 | 2,518 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 WA * 9 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:76:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
76 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:81:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
81 | scanf("%d%d", &rs[i].first, &rs[i].second);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 743.cc: No.743 Segments on a Polygon - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 100000;
const int MAX_M = 200000;
/* typedef */
typedef long long ll;
typedef pair<int,int> pii;
template <typename T, const int MAX_N>
struct BIT {
int n;
T bits[MAX_N + 1];
BIT() {}
void init(int _n) {
n = _n;
memset(bits, 0, sizeof(bits));
}
T sum(int x) {
T s = 0;
while (x > 0) {
s += bits[x];
x -= (x & -x);
}
return s;
}
void add(int x, T v) {
while (x <= n) {
bits[x] += v;
x += (x & -x);
}
}
};
/* global variables */
BIT<int,MAX_M+1> bit;
pii rs[MAX_N];
/* subroutines */
/* main */
int main() {
int n, m;
scanf("%d%d", &n, &m);
bit.init(m + 1);
for (int i = 0; i < n; i++)
scanf("%d%d", &rs[i].first, &rs[i].second);
sort(rs, rs + n);
ll sum = 0;
for (int i = 0; i < n; i++) {
int a = rs[i].first, b = rs[i].second;
if (a > b) swap(a, b);
a++, b++;
int d = bit.sum(b) - bit.sum(a);
sum += d;
//for (int i = 1; i <= m; i++) printf("%d ", bit.sum(i));
//printf("%d-%d: d=%d\n", a, b, d);
bit.add(b, 1);
}
printf("%lld\n", sum);
return 0;
}
tnakao0123