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

#2551. 「JSOI2018」列队

https://loj.ac/s/1703080
This commit is contained in:
Baoshuo Ren 2023-02-16 16:52:50 +08:00
parent 3fb12c8dbe
commit 6391fbdaf6
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
21 changed files with 151 additions and 0 deletions

91
LibreOJ/2551/2551.cpp Normal file
View File

@ -0,0 +1,91 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 5e5 + 5,
K = 1e6 + 5;
int n, m, a[N], cnt, root[N];
struct node {
int l, r, siz;
long long sum;
} tr[N << 5];
int build(int l, int r) {
int p = ++cnt;
if (l == r) return p;
int mid = l + r >> 1;
tr[p].l = build(l, mid);
tr[p].r = build(mid + 1, r);
return p;
}
int insert(int p, int l, int r, int x) {
int q = ++cnt;
tr[q] = tr[p];
tr[q].siz++;
tr[q].sum += x;
if (l == r) return q;
int mid = l + r >> 1;
if (x <= mid) {
tr[q].l = insert(tr[p].l, l, mid, x);
} else {
tr[q].r = insert(tr[p].r, mid + 1, r, x);
}
tr[q].siz = tr[tr[q].l].siz + tr[tr[q].r].siz;
tr[q].sum = tr[tr[q].l].sum + tr[tr[q].r].sum;
return q;
}
long long query(int p, int q, int l, int r, int f, int k) {
int siz = tr[p].siz - tr[q].siz;
long long sum = tr[p].sum - tr[q].sum;
if (!siz) return 0;
if (l >= k + f) return sum - static_cast<long long>(2 * k + 2 * f + siz - 1) * siz / 2;
if (r <= k + f + siz - 1) return static_cast<long long>(2 * k + 2 * f + siz - 1) * siz / 2 - sum;
int siz_l = tr[tr[p].l].siz - tr[tr[q].l].siz;
int mid = l + r >> 1;
return query(tr[p].l, tr[q].l, l, mid, f, k)
+ query(tr[p].r, tr[q].r, mid + 1, r, f + siz_l, k);
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
root[0] = build(1, 1000000);
for (int i = 1; i <= n; i++) {
root[i] = insert(root[i - 1], 1, 1000000, a[i]);
}
for (int i = 1, l, r, k; i <= m; i++) {
cin >> l >> r >> k;
cout << query(root[r], root[l - 1], 1, 1000000, 0, k) << endl;
}
return 0;
}

BIN
LibreOJ/2551/data/line1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2551/data/line1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2551/data/line10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2551/data/line10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2551/data/line2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2551/data/line2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2551/data/line3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2551/data/line3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2551/data/line4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2551/data/line4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2551/data/line5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2551/data/line5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2551/data/line6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2551/data/line6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2551/data/line7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2551/data/line7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2551/data/line8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2551/data/line8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2551/data/line9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2551/data/line9.out (Stored with Git LFS) Normal file

Binary file not shown.