結果
問題 | No.404 部分門松列 |
ユーザー |
![]() |
提出日時 | 2016-09-12 09:28:12 |
言語 | C++11 (gcc 13.3.0) |
結果 |
CE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,514 bytes |
コンパイル時間 | 354 ms |
コンパイル使用メモリ | 51,680 KB |
最終ジャッジ日時 | 2024-11-14 19:49:29 |
合計ジャッジ時間 | 4,258 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function ‘void compress()’: main.cpp:36:9: error: ‘vector’ was not declared in this scope 36 | vector<int> v(a, a + n); | ^~~~~~ main.cpp:3:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’? 2 | #include <algorithm> +++ |+#include <vector> 3 | main.cpp:36:16: error: expected primary-expression before ‘int’ 36 | vector<int> v(a, a + n); | ^~~ main.cpp:37:14: error: ‘v’ was not declared in this scope 37 | sort(v.begin(), v.end()); | ^
ソースコード
#include <iostream>#include <algorithm>#define rep(i, n) for(int i = 0; i < (n); ++i)using namespace std;typedef long long ll;int n;int a[200000];int q;int l[200000];int h[200000];ll bf[200001];ll bb[200001];ll bs[200001];ll bq[200001];void badd(ll* b, int i, ll x){while(i <= 200000){b[i] += x;i += i & -i;}}ll bsum(ll* b, int i){ll s = 0;while(i > 0){s += b[i];i -= i & -i;}return s;}void compress(){vector<int> v(a, a + n);sort(v.begin(), v.end());v.erase(unique(v.begin(), v.end()), v.end());rep(i, n){a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin();}rep(i, q){l[i] = lower_bound(v.begin(), v.end(), l[i]) - v.begin();h[i] = upper_bound(v.begin(), v.end(), h[i]) - v.begin();}}void add_count(){rep(i, n){badd(bb, a[i] + 1, 1);}rep(i, n){badd(bf, a[i] + 1, 1);badd(bb, a[i] + 1, -1);ll c = (bsum(bf, a[i] + 1) - bsum(bf, a[i])) * (bsum(bb, a[i] + 1) - bsum(bb, a[i])) - (bsum(bs, a[i] + 1) - bsum(bs, a[i]));badd(bs, a[i] + 1, c);ll p = bsum(bf, a[i]) * bsum(bb, a[i]);ll q = (bsum(bf, n) - bsum(bf, a[i] + 1)) * (bsum(bb, n) - bsum(bb, a[i] + 1));ll r = (bsum(bs, n) - bsum(bs, a[i] + 1)) + bsum(bs, a[i]);badd(bq, a[i] + 1, p + q - r);}}void remove_count(){}int main(){cin >> n;rep(i, n){cin >> a[i];}cin >> q;rep(i, q){cin >> l[i] >> h[i];}compress();add_count();remove_count();rep(i, q){cout << bsum(bq, h[i]) - bsum(bq, l[i]) << endl;}return 0;}