結果
| 問題 |
No.742 にゃんにゃんにゃん 猫の挨拶
|
| コンテスト | |
| ユーザー |
poyompy
|
| 提出日時 | 2018-10-05 21:37:58 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 2,500 ms |
| コード長 | 483 bytes |
| コンパイル時間 | 203 ms |
| コンパイル使用メモリ | 23,552 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-12 13:54:53 |
| 合計ジャッジ時間 | 806 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:26:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
26 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:30:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
30 | scanf("%d", &m);
| ~~~~~^~~~~~~~~~
ソースコード
#include <stdio.h>
#include <string.h>
int bit[30303];
void update(int k, int v) {
k++;
while (k < 30303) {
bit[k] += v;
k += k & -k;
}
}
int query(int k) {
k++;
int res = 0;
while (k > 0) {
res += bit[k];
k -= k & -k;
}
return res;
}
int main() {
int n;
scanf("%d", &n);
long long ans = 0;
for (int i = 0; i < n; i++) {
int m;
scanf("%d", &m);
ans += i - query(m);
update(m, 1);
}
printf("%lld\n", ans);
return 0;
}
poyompy