0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 14:16:28 +00:00

#2319. 「NOIP2017」列队

https://loj.ac/s/1478707
This commit is contained in:
Baoshuo Ren 2022-06-09 09:39:51 +08:00
parent 1051c67cd8
commit 8ca2318103
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68
41 changed files with 198 additions and 0 deletions

78
LibreOJ/2319/2319.cpp Normal file
View File

@ -0,0 +1,78 @@
#include <iostream>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 3e5 + 5;
struct node {
int l, r, d;
node()
: l(0), r(0), d(0) {}
} tr[N << 4];
int n, m, q, max, cnt, root[N];
std::vector<long long> r[N];
int query(int u, int l, int r, int x) {
if (l == r) return l;
int mid = l + r >> 1;
int c = mid - l + 1 - tr[tr[u].l].d;
if (x <= c) return query(tr[u].l, l, mid, x);
return query(tr[u].r, mid + 1, r, x - c);
}
void remove(int &u, int l, int r, int x) {
if (!u) u = ++cnt;
tr[u].d++;
if (l == r) return;
int mid = l + r >> 1;
if (x <= mid) remove(tr[u].l, l, mid, x);
else remove(tr[u].r, mid + 1, r, x);
}
long long row(int x, int y) {
int p = query(root[x], 1, max, y);
remove(root[x], 1, max, p);
return p < m ? 1ll * (x - 1) * m + p : r[x][p - m];
}
long long col(int y) {
int p = query(root[0], 1, max, y);
remove(root[0], 1, max, p);
return p <= n ? 1ll * p * m : r[0][p - n - 1];
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m >> q;
max = std::max(n, m) + q;
for (int i = 1, x, y; i <= q; i++) {
cin >> x >> y;
long long p;
if (y == m) { // 最后一列
p = col(x);
r[0].push_back(p);
} else {
p = row(x, y);
r[0].push_back(p);
r[x].push_back(col(x));
}
cout << p << endl;
}
return 0;
}

BIN
LibreOJ/2319/data/phalanx1.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx10.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx11.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx11.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx12.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx12.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx13.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx13.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx14.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx14.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx15.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx15.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx16.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx16.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx17.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx17.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx18.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx18.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx19.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx19.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx2.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx20.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx20.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx3.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx4.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx5.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx6.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx7.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx8.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx9.ans (Stored with Git LFS) Normal file

Binary file not shown.

BIN
LibreOJ/2319/data/phalanx9.in (Stored with Git LFS) Normal file

Binary file not shown.