0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 18:48:48 +00:00

#1787. 【2017.3长乐省选集训Day8T2】朗格拉日计数

https://sjzezoj.com/submission/65357
This commit is contained in:
Baoshuo Ren 2022-12-04 11:05:37 +08:00
parent 810be8ed7d
commit 06d8a23596
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
22 changed files with 135 additions and 0 deletions

72
S2OJ/1787/1787.cpp Normal file
View File

@ -0,0 +1,72 @@
#include <iostream>
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<long long>(pre_sm[i]) * suf_lg // 123
+ static_cast<long long>(pre_lg) * (pre_lg - 1) / 2 - static_cast<long long>(pre_lg) * suf_sm[i] // 231 = **1 - 321
+ static_cast<long long>(suf_sm[i]) * (suf_sm[i] - 1) / 2 - static_cast<long long>(pre_lg) * suf_sm[i] // 312 = 3** - 321
;
}
cout << ans << endl;
return 0;
}

BIN
S2OJ/1787/data/counter1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1787/data/counter1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1787/data/counter10.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1787/data/counter10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1787/data/counter2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1787/data/counter2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1787/data/counter3.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1787/data/counter3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1787/data/counter4.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1787/data/counter4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1787/data/counter5.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1787/data/counter5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1787/data/counter6.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1787/data/counter6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1787/data/counter7.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1787/data/counter7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1787/data/counter8.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1787/data/counter8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1787/data/counter9.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1787/data/counter9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
S2OJ/1787/data/problem.conf (Stored with Git LFS) Normal file

Binary file not shown.