diff --git a/S2OJ/1787/1787.cpp b/S2OJ/1787/1787.cpp new file mode 100644 index 00000000..ea9b7466 --- /dev/null +++ b/S2OJ/1787/1787.cpp @@ -0,0 +1,72 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 2e5 + 5; + +class BIT { + private: + int data[N]; + + static int lowbit(int x) { + return x & -x; + } + + public: + void add(int x, int v) { + for (; x < N; x += lowbit(x)) { + data[x] += v; + } + } + + int query(int x) { + int ans = 0; + + for (; x; x -= lowbit(x)) { + ans += data[x]; + } + + return ans; + } +}; + +int n, a[N], pre_sm[N], suf_sm[N]; +long long ans; +BIT bit_pre, bit_suf; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n; + + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + + for (int i = 1; i <= n; i++) { + pre_sm[i] = bit_pre.query(a[i] - 1); + bit_pre.add(a[i], 1); + } + + for (int i = n; i; i--) { + suf_sm[i] = bit_suf.query(a[i] - 1); + bit_suf.add(a[i], 1); + } + + for (int i = 1; i <= n; i++) { + int pre_lg = i - pre_sm[i] - 1, + suf_lg = n - i - suf_sm[i]; + + ans += static_cast(pre_sm[i]) * suf_lg // 123 + + static_cast(pre_lg) * (pre_lg - 1) / 2 - static_cast(pre_lg) * suf_sm[i] // 231 = **1 - 321 + + static_cast(suf_sm[i]) * (suf_sm[i] - 1) / 2 - static_cast(pre_lg) * suf_sm[i] // 312 = 3** - 321 + ; + } + + cout << ans << endl; + + return 0; +} diff --git a/S2OJ/1787/data/counter1.ans b/S2OJ/1787/data/counter1.ans new file mode 100644 index 00000000..7d4cfc40 --- /dev/null +++ b/S2OJ/1787/data/counter1.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5824de0b014824a71a5241be5329ca1980226901c4322cd9083f699b1dbf007b +size 6 diff --git a/S2OJ/1787/data/counter1.in b/S2OJ/1787/data/counter1.in new file mode 100644 index 00000000..ec32192f --- /dev/null +++ b/S2OJ/1787/data/counter1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:375ba2d8ebfad4152b9b52f49c79fab298026272380e2e9536e38107c97da9b1 +size 296 diff --git a/S2OJ/1787/data/counter10.ans b/S2OJ/1787/data/counter10.ans new file mode 100644 index 00000000..f833fc28 --- /dev/null +++ b/S2OJ/1787/data/counter10.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cd85d72af46cc53b756f47317a04ada8fa66976d3b6693cbabd2e2151381ca5e +size 16 diff --git a/S2OJ/1787/data/counter10.in b/S2OJ/1787/data/counter10.in new file mode 100644 index 00000000..7a83d0f8 --- /dev/null +++ b/S2OJ/1787/data/counter10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:336464b983a5ba1f1776aa34c8ed0c76e75d55e34803f05864877acb63df10ea +size 1288902 diff --git a/S2OJ/1787/data/counter2.ans b/S2OJ/1787/data/counter2.ans new file mode 100644 index 00000000..345b2b86 --- /dev/null +++ b/S2OJ/1787/data/counter2.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8aeab13a57b19c39f8f7e33c34411b8ebc09b7ad135139d4009f12b59706f648 +size 6 diff --git a/S2OJ/1787/data/counter2.in b/S2OJ/1787/data/counter2.in new file mode 100644 index 00000000..01e41a86 --- /dev/null +++ b/S2OJ/1787/data/counter2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f682028b445635c1b7ca94fef5fc4f76ee21852632cdec8d332cee0b13de9bfd +size 296 diff --git a/S2OJ/1787/data/counter3.ans b/S2OJ/1787/data/counter3.ans new file mode 100644 index 00000000..500f09bc --- /dev/null +++ b/S2OJ/1787/data/counter3.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:33ca7f15c0b5c4e72efafe69fec335e3f4fcad12b3f46cf50f118e64e7fac237 +size 12 diff --git a/S2OJ/1787/data/counter3.in b/S2OJ/1787/data/counter3.in new file mode 100644 index 00000000..c1434668 --- /dev/null +++ b/S2OJ/1787/data/counter3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:17b94bf05395124525b93f460097ae4286a14a468e02d2786db987212f54dd42 +size 23898 diff --git a/S2OJ/1787/data/counter4.ans b/S2OJ/1787/data/counter4.ans new file mode 100644 index 00000000..a3e03943 --- /dev/null +++ b/S2OJ/1787/data/counter4.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:46307f2ebf00554a71511e3555f41610049f4beb315a8ee1df9bc56494f4da21 +size 12 diff --git a/S2OJ/1787/data/counter4.in b/S2OJ/1787/data/counter4.in new file mode 100644 index 00000000..b0768b5f --- /dev/null +++ b/S2OJ/1787/data/counter4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:51f2bf4301e9ee9a1a7669b7ee85a948a3eab65d3ffe310b47a49311b167db0d +size 23898 diff --git a/S2OJ/1787/data/counter5.ans b/S2OJ/1787/data/counter5.ans new file mode 100644 index 00000000..db5054df --- /dev/null +++ b/S2OJ/1787/data/counter5.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fe7dc74d2d92eec4099999be43319c7a3f66057ed3e6e018c2231e7ed9eefd09 +size 12 diff --git a/S2OJ/1787/data/counter5.in b/S2OJ/1787/data/counter5.in new file mode 100644 index 00000000..39895a84 --- /dev/null +++ b/S2OJ/1787/data/counter5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:49d109345bf6bb08ffe3963c8c12b48a58cd357abcb6fe2eb5da31553ccb7db6 +size 23898 diff --git a/S2OJ/1787/data/counter6.ans b/S2OJ/1787/data/counter6.ans new file mode 100644 index 00000000..fd697899 --- /dev/null +++ b/S2OJ/1787/data/counter6.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d78b25a8da6ec3bda37a8e6f082f8305b75d9da24aecee15af8118c73744da42 +size 12 diff --git a/S2OJ/1787/data/counter6.in b/S2OJ/1787/data/counter6.in new file mode 100644 index 00000000..8fd011c4 --- /dev/null +++ b/S2OJ/1787/data/counter6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1c1df60da6597b06edee4f89b025623df54bf83eaf150fb6185eff8ce7ecaf1c +size 23898 diff --git a/S2OJ/1787/data/counter7.ans b/S2OJ/1787/data/counter7.ans new file mode 100644 index 00000000..2f16f0ca --- /dev/null +++ b/S2OJ/1787/data/counter7.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:56b389bb8bf585da77354dcb9a06f398db0b94fb18630a64949b11c21f88dd8a +size 16 diff --git a/S2OJ/1787/data/counter7.in b/S2OJ/1787/data/counter7.in new file mode 100644 index 00000000..6b41ea0f --- /dev/null +++ b/S2OJ/1787/data/counter7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d3e17cbbd1ae359d74bbd7f098b34ab3501ca60eff73370f8b2eb882b629ae20 +size 1288902 diff --git a/S2OJ/1787/data/counter8.ans b/S2OJ/1787/data/counter8.ans new file mode 100644 index 00000000..06d212b9 --- /dev/null +++ b/S2OJ/1787/data/counter8.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8e5a83c981c905fd792bbed101f94fd168550a64659b665d367a12c14a848d0d +size 16 diff --git a/S2OJ/1787/data/counter8.in b/S2OJ/1787/data/counter8.in new file mode 100644 index 00000000..61599b2f --- /dev/null +++ b/S2OJ/1787/data/counter8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fb903e6dbea4d3fc690c918209c676ee10b47ba80d05d86085265cfa316b5319 +size 1288902 diff --git a/S2OJ/1787/data/counter9.ans b/S2OJ/1787/data/counter9.ans new file mode 100644 index 00000000..7f996548 --- /dev/null +++ b/S2OJ/1787/data/counter9.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0cf5e8c064939d2c6ed8d70eafc3c619d6b0e9f8076c0911fefc14c7ec47ee55 +size 16 diff --git a/S2OJ/1787/data/counter9.in b/S2OJ/1787/data/counter9.in new file mode 100644 index 00000000..731c647f --- /dev/null +++ b/S2OJ/1787/data/counter9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:25a63b943b45fb2a1f0c66796b431d563df81d1ae3e26de195cf004d185cdb2b +size 1288902 diff --git a/S2OJ/1787/data/problem.conf b/S2OJ/1787/data/problem.conf new file mode 100644 index 00000000..7d97e3c4 --- /dev/null +++ b/S2OJ/1787/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c0adf5220e70e076358500332b24a1fddd59434ce85e2985b66356ba5c55bd5d +size 185