提交记录 6957
提交时间 |
评测时间 |
2018-11-23 20:49:18 |
2020-08-01 00:55:11 |
#include <cstdio>
#include <vector>
using namespace std;
typedef long long ll;
struct Modify {
int qid, x;
Modify() {}
Modify(int qid, int x) : qid(qid), x(x) {}
};
const int N = 300010, FW = 1 << 21;
int n, m, q;
int qCnt;
int qx[N], qy[N];
int ind[N * 2];
int fw[FW];
vector<Modify> mr[N], mc;
vector<ll> rr[N], rc;
int rmv(int k);
void change(int k);
int lowBit(int k);
int main() {
for (int i = 1; i < FW; ++i)
fw[i] = lowBit(i);
scanf("%d%d%d", &n, &m, &q);
for (int i = 1; i <= q; ++i) {
scanf("%d%d", &qx[i], &qy[i]);
if (qy[i] == m)
mc.push_back(Modify(++qCnt, qx[i]));
else {
mr[qx[i]].push_back(Modify(++qCnt, qy[i]));
mc.push_back(Modify(++qCnt, qx[i]));
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < mr[i].size(); ++j) {
ind[mr[i][j].qid] = rmv(mr[i][j].x);
}
for (int j = 0; j < mr[i].size(); ++j)
change(ind[mr[i][j].qid]);
}
for (int j = 0; j < mc.size(); ++j)
ind[mc[j].qid] = rmv(mc[j].x);
qCnt = 0;
for (int i = 1; i <= q; ++i) {
ll v;
if (qy[i] == m) {
++qCnt;
if (ind[qCnt] <= n)
v = ind[qCnt] * (ll)m;
else
v = rc[ind[qCnt] - n - 1];
rc.push_back(v);
printf("%lld\n", v);
} else {
++qCnt;
if (ind[qCnt] < m)
v = ind[qCnt] + (qx[i] - 1) * (ll)m;
else
v = rr[qx[i]][ind[qCnt] - m];
printf("%lld\n", v);
rc.push_back(v);
++qCnt;
if (ind[qCnt] <= n)
v = ind[qCnt] * (ll)m;
else
v = rc[ind[qCnt] - n - 1];
rr[qx[i]].push_back(v);
}
}
return 0;
}
int lowBit(int k) {
return k & -k;
}
void change(int k) {
for (; k < FW; k += lowBit(k))
++fw[k];
}
int rmv(int k) {
int ret = 0;
--k;
for (int l = 20; l >= 0; --l)
if (fw[ret | (1 << l)] <= k)
k -= fw[ret |= (1 << l)];
++ret;
for (k = ret; k < FW; k += lowBit(k))
--fw[k];
return ret;
}
Compilation | N/A | N/A | Compile OK | Score: N/A | 显示更多 |
Testcase #1 | 4.189 ms | 21 MB + 824 KB | Accepted | Score: 5 | 显示更多 |
Testcase #2 | 4.132 ms | 21 MB + 824 KB | Accepted | Score: 5 | 显示更多 |
Testcase #3 | 4.188 ms | 21 MB + 824 KB | Accepted | Score: 5 | 显示更多 |
Testcase #4 | 4.17 ms | 21 MB + 828 KB | Accepted | Score: 5 | 显示更多 |
Testcase #5 | 4.198 ms | 21 MB + 824 KB | Accepted | Score: 5 | 显示更多 |
Testcase #6 | 4.212 ms | 21 MB + 828 KB | Accepted | Score: 5 | 显示更多 |
Testcase #7 | 4.266 ms | 21 MB + 828 KB | Accepted | Score: 5 | 显示更多 |
Testcase #8 | 4.338 ms | 21 MB + 832 KB | Accepted | Score: 5 | 显示更多 |
Testcase #9 | 4.337 ms | 21 MB + 832 KB | Accepted | Score: 5 | 显示更多 |
Testcase #10 | 4.313 ms | 21 MB + 832 KB | Accepted | Score: 5 | 显示更多 |
Testcase #11 | 55.865 ms | 27 MB + 1004 KB | Accepted | Score: 5 | 显示更多 |
Testcase #12 | 55.33 ms | 27 MB + 552 KB | Accepted | Score: 5 | 显示更多 |
Testcase #13 | 175.818 ms | 44 MB + 176 KB | Accepted | Score: 5 | 显示更多 |
Testcase #14 | 166.145 ms | 43 MB + 460 KB | Accepted | Score: 5 | 显示更多 |
Testcase #15 | 168.571 ms | 41 MB + 8 KB | Accepted | Score: 5 | 显示更多 |
Testcase #16 | 176.177 ms | 41 MB + 636 KB | Accepted | Score: 5 | 显示更多 |
Testcase #17 | 67.736 ms | 29 MB + 28 KB | Accepted | Score: 5 | 显示更多 |
Testcase #18 | 65.604 ms | 28 MB + 816 KB | Accepted | Score: 5 | 显示更多 |
Testcase #19 | 220.982 ms | 43 MB + 608 KB | Accepted | Score: 5 | 显示更多 |
Testcase #20 | 219.965 ms | 43 MB + 908 KB | Accepted | Score: 5 | 显示更多 |
Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:21:51 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠