結果
問題 | No.404 部分門松列 |
ユーザー | ei1333333 |
提出日時 | 2016-07-23 00:25:41 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 300 ms / 2,000 ms |
コード長 | 1,747 bytes |
コンパイル時間 | 1,614 ms |
コンパイル使用メモリ | 168,160 KB |
実行使用メモリ | 14,584 KB |
最終ジャッジ日時 | 2024-06-28 16:58:01 |
合計ジャッジ時間 | 8,652 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 125 ms
8,112 KB |
testcase_14 | AC | 137 ms
9,324 KB |
testcase_15 | AC | 125 ms
8,304 KB |
testcase_16 | AC | 150 ms
11,048 KB |
testcase_17 | AC | 187 ms
10,844 KB |
testcase_18 | AC | 87 ms
5,376 KB |
testcase_19 | AC | 64 ms
6,400 KB |
testcase_20 | AC | 165 ms
12,188 KB |
testcase_21 | AC | 186 ms
10,936 KB |
testcase_22 | AC | 109 ms
5,504 KB |
testcase_23 | AC | 192 ms
12,920 KB |
testcase_24 | AC | 257 ms
14,584 KB |
testcase_25 | AC | 300 ms
14,456 KB |
testcase_26 | AC | 292 ms
14,312 KB |
testcase_27 | AC | 59 ms
5,376 KB |
testcase_28 | AC | 147 ms
7,424 KB |
testcase_29 | AC | 225 ms
12,596 KB |
testcase_30 | AC | 158 ms
8,800 KB |
testcase_31 | AC | 31 ms
5,376 KB |
testcase_32 | AC | 176 ms
10,656 KB |
testcase_33 | AC | 177 ms
9,040 KB |
testcase_34 | AC | 193 ms
10,544 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:31:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 31 | scanf("%d", &N); | ~~~~~^~~~~~~~~~ main.cpp:32:35: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 32 | for(int i = 0; i < N; i++) scanf("%d", &A[i]); | ~~~~~^~~~~~~~~~~~~ main.cpp:33:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 33 | scanf("%d", &Q); | ~~~~~^~~~~~~~~~ main.cpp:34:35: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 34 | for(int i = 0; i < Q; i++) scanf("%d %d", &L[i], &R[i]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long int64; 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 L[200005], R[200005]; int ans[200005]; int LL[200005], RR[200005]; int main() { scanf("%d", &N); for(int i = 0; i < N; i++) scanf("%d", &A[i]); scanf("%d", &Q); for(int i = 0; i < Q; i++) scanf("%d %d", &L[i], &R[i]); vector< int > nums; nums.push_back(-1); nums.push_back(1 << 30); 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()), 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], 1LL * (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], 1LL * 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]]); } for(int i = 0; i < Q; i++) { L[i] = lower_bound(begin(nums), end(nums), L[i]) - begin(nums); R[i] = upper_bound(begin(nums), end(nums), R[i]) - begin(nums); printf("%lld\n", result.sum(R[i] - 1) - result.sum(L[i] - 1)); } }