結果
問題 | No.1115 二つの数列 / Two Sequences |
ユーザー |
|
提出日時 | 2020-07-18 14:22:38 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 58 ms / 2,000 ms |
コード長 | 768 bytes |
コンパイル時間 | 610 ms |
コンパイル使用メモリ | 47,872 KB |
最終ジャッジ日時 | 2025-01-12 00:17:29 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 35 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:24:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | int N; scanf("%d", &N); | ~~~~~^~~~~~~~~~ main.cpp:27:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 27 | scanf("%d", &a[i]); | ~~~~~^~~~~~~~~~~~~ main.cpp:30:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 30 | int bi; scanf("%d", &bi); | ~~~~~^~~~~~~~~~~
ソースコード
#include <cstdint>#include <cstdio>#include <vector>using namespace std;using i64 = int64_t;template <class T>class BIT {int N;vector<T> dat;public:explicit BIT(int n) : N(n+2), dat(N) {}void add(int k, T x) {for(int i=k+1; i<N; i+=i&-i) { dat[i] += x; }}T sum(int k) {T res = 0;for(int i=k; i; i-=i&-i) { res += dat[i]; }return res;}};int main(void) {int N; scanf("%d", &N);vector<int> a(N), v(N);for(int i=0; i<N; ++i) {scanf("%d", &a[i]);}for(int i=0; i<N; ++i) {int bi; scanf("%d", &bi);v[--bi] = i;}i64 res = 0;BIT<int> tree(N);for(int i=0; i<N; ++i) {int wi = v[--a[i]];res += i - tree.sum(wi);tree.add(wi, 1);}printf("%ld\n", res);return 0;}