結果
問題 | No.404 部分門松列 |
ユーザー | ei1333333 |
提出日時 | 2016-07-23 00:32:24 |
言語 | C++11 (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,979 bytes |
コンパイル時間 | 1,604 ms |
コンパイル使用メモリ | 169,660 KB |
実行使用メモリ | 12,960 KB |
最終ジャッジ日時 | 2024-11-06 12:26:17 |
合計ジャッジ時間 | 9,848 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 2 ms
6,820 KB |
testcase_05 | AC | 2 ms
6,816 KB |
testcase_06 | AC | 2 ms
6,816 KB |
testcase_07 | AC | 2 ms
6,820 KB |
testcase_08 | AC | 2 ms
6,816 KB |
testcase_09 | AC | 2 ms
6,816 KB |
testcase_10 | AC | 2 ms
6,816 KB |
testcase_11 | AC | 2 ms
6,820 KB |
testcase_12 | AC | 2 ms
6,820 KB |
testcase_13 | WA | - |
testcase_14 | AC | 121 ms
7,816 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 146 ms
10,800 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 54 ms
6,816 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 29 ms
6,820 KB |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:83:16: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘int’ [-Wformat=] 83 | printf("%lld\n", result.query(--R) - result.query(--L)); | ~~~^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | | | long long int int | %d main.cpp:51:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 51 | scanf("%d", &N); | ~~~~~^~~~~~~~~~ main.cpp:52:35: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 52 | for(int i = 0; i < N; i++) scanf("%d", &A[i]); | ~~~~~^~~~~~~~~~~~~ main.cpp:53:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 53 | scanf("%d", &Q); | ~~~~~^~~~~~~~~~ main.cpp:80:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 80 | scanf("%d %d", &L, &R); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long int64; struct CumulativeSum { vector< int64 > data; CumulativeSum(int sz): data(++sz, 0) {}; inline void add(int k, int64 x) { data[k] += x; } void build() { for(int i = 1; i < data.size(); i++) { data[i] += data[i - 1]; } } inline int query(int64 k) { return(data[k]); } }; struct BinaryIndexedTree { vector< int64 > data; BinaryIndexedTree(int sz) { data.assign(++sz, 0); } int64 sum(int k) { int64 ret = 0; for(++k; k > 0; k -= k & -k) ret += data[k]; return(ret); } void add(int k, int64 x) { for(++k; k < data.size(); k += k & -k) data[k] += x; } }; int N, A[200005], Q; int LL[200005], RR[200005]; int main() { scanf("%d", &N); for(int i = 0; i < N; i++) scanf("%d", &A[i]); scanf("%d", &Q); vector< int > nums; nums.push_back(-1); for(int i = 0; i < N; i++) nums.push_back(A[i]); sort(begin(nums), end(nums)); for(int i = 0; i < N; i++) { A[i] = lower_bound(begin(nums), end(nums), A[i]) - begin(nums); } BinaryIndexedTree rest(nums.size()), left(nums.size()), right(nums.size()); CumulativeSum result(nums.size()); for(int i = 0; i < N; i++) ++RR[A[i]], right.add(A[i], 1); for(int i = 0; i < N; i++) { --RR[A[i]]; rest.add(A[i], -LL[A[i]]); right.add(A[i], -1); result.add(A[i], (right.sum(nums.size() - 1) - right.sum(A[i])) * (left.sum(nums.size() - 1) - left.sum(A[i])) - (rest.sum(nums.size() - 1) - rest.sum(A[i]))); result.add(A[i], right.sum(A[i] - 1) * left.sum(A[i] - 1) - rest.sum(A[i] - 1)); ++LL[A[i]]; left.add(A[i], 1); rest.add(A[i], RR[A[i]]); } result.build(); for(int i = 0; i < Q; i++) { int L, R; scanf("%d %d", &L, &R); L = lower_bound(begin(nums), end(nums), L) - begin(nums); R = upper_bound(begin(nums), end(nums), R) - begin(nums); printf("%lld\n", result.query(--R) - result.query(--L)); } }