QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#734364 | #4894. 学姐买瓜 | NineSuns | 0 | 1ms | 7772kb | C++14 | 2.2kb | 2024-11-11 09:24:39 | 2024-11-11 09:24:40 |
answer
#include <bits/stdc++.h>
#define pii pair <int, int>
#define fi first
#define se second
using namespace std;
const int N = 3e5+5, B = 555, b = 517, inf = 0x3f3f3f3f;
int n, m, nxt[N], nb[N], d[N], rk[N], lb[B], rb[B], o[B], od[B];
set <pii> st;
void reset (int bi, int l, int r, int k) {
if (o[bi]) {
for (int j = rb[bi];j >= lb[bi];j--) nxt[j] = od[bi];
o[bi] = 0;
}
for (int j = l;j <= r;j++) nxt[j] = k;
for (int j = rb[bi];j >= lb[bi];j--) {
if (nxt[j] > rb[bi]) nb[j] = nxt[j], d[j] = 1;
else nb[j] = nb[nxt[j]], d[j] = d[nxt[j]]+1;
}
}
void upd (int l, int r, int k) {
// cout << "MODIFY:" << l << " " << r << " " << k << endl;
int bl = rk[l], br = rk[r];
if (bl == br) {
return reset(bl, l, r, k);
}
reset(bl, l, rb[bl], k); reset(br, lb[br], r, k);
for (int j = bl+1;j < br;j++) assert(k > rb[j]), o[j] = 1, od[j] = k;
}
int getd (int l, int r) {
int k = 0;
while (1) {
if (o[rk[l]]) {
if (od[rk[l]] > r+1) break;
k++; l = od[rk[l]];
}
else {
if (nb[l] > r+1) break;
k += d[l]; l = nb[l];
}
}
while (1) {
if (o[rk[l]]) {
if (od[rk[l]] > r+1) break;
k++; l = od[rk[l]];
}
else {
if (nxt[l] > r+1) break;
k++; l = nxt[l];
}
}
// cout << "END\n";
return k;
}
int main () {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> m >> n;
for (int i = 1; ;i++) {
lb[i] = rb[i-1]+1; rb[i] = min(n, rb[i-1]+b);
for (int j = lb[i];j <= rb[i];j++) rk[j] = i;
if (rb[i] == n) break;
}
for (int i = 1;i <= n;i++) nxt[i] = nb[i] = inf;
while (m--) {
int o, l, r; cin >> o >> l >> r;
if (o == 1) {
auto it = st.upper_bound({r+1, 0});
if (it != st.begin()) {
--it;
if ((*it).se >= l) continue;
}
while (1) {
auto it = st.upper_bound({r, 0});
if (it == st.end()) break;
if ((*it).se <= l) st.erase(it); else break;
}
// cout << "INS:" << l << " " << r << endl;
st.insert({r, l});
it = st.lower_bound({r, l}); auto nx = st.upper_bound({r, l});
upd(it == st.begin() ? 1 : (*--it).se+1, l, r+1);
}
else {
cout << getd(l, r) << '\n';
}
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 20
Accepted
time: 1ms
memory: 5648kb
input:
11 13 2 4 4 1 11 12 1 1 5 1 2 3 1 2 10 2 2 8 1 6 6 2 2 10 1 6 11 2 2 3 2 2 13
output:
0 1 2 1 3
result:
ok 5 lines
Test #2:
score: 20
Accepted
time: 0ms
memory: 5736kb
input:
2000 2000 2 66 273 1 475 1570 2 51 958 2 731 1771 1 1286 1627 1 37 892 1 529 890 2 155 1486 1 87 1815 1 576 1872 2 1269 1515 2 1521 1794 2 634 1887 2 204 1668 1 351 1679 2 1571 1599 1 243 681 2 1 2000 2 1 2000 2 564 648 2 1215 1807 2 466 1617 1 1119 1348 1 497 886 2 1358 1487 2 173 1974 1 401 1294 2...
output:
0 0 0 1 0 0 1 2 0 2 2 0 1 1 0 2 1 1 0 1 0 1 0 0 1 2 1 1 1 2 1 1 0 0 2 2 0 2 2 0 1 3 0 0 4 0 0 2 2 5 2 0 4 0 2 0 2 3 3 0 0 1 3 2 0 3 6 1 0 1 1 4 0 8 0 8 1 3 1 8 1 4 9 2 2 0 4 5 2 9 3 0 9 1 3 8 9 1 0 7 0 8 5 7 0 1 0 6 10 2 6 0 1 0 6 4 6 5 4 4 4 0 10 0 6 2 8 9 1 10 5 7 8 10 1 10 8 5 2 6 1 5 10 8 10 5 3...
result:
ok 1020 lines
Test #3:
score: 20
Accepted
time: 1ms
memory: 5740kb
input:
2000 2000 2 66 273 1 475 1570 2 51 958 2 731 1771 1 1286 1627 1 37 892 1 529 890 2 155 1486 1 87 1815 1 576 1872 2 1269 1515 2 1521 1794 2 634 1887 2 204 1668 1 351 1679 2 1571 1599 1 243 681 2 1 2000 2 1 2000 2 564 648 2 1215 1807 2 466 1617 1 1119 1348 1 497 886 2 1358 1487 2 173 1974 1 401 1294 2...
output:
0 0 0 1 0 0 1 2 0 2 2 0 1 1 0 2 1 1 0 1 0 1 0 0 1 2 1 1 1 2 1 1 0 0 2 2 0 2 2 0 1 3 0 0 4 0 0 2 2 5 2 0 4 0 2 0 2 3 3 0 0 1 3 2 0 3 6 1 0 1 1 4 0 8 0 8 1 3 1 8 1 4 9 2 2 0 4 5 2 9 3 0 9 1 3 8 9 1 0 7 0 8 5 7 0 1 0 6 10 2 6 0 1 0 6 4 6 5 4 4 4 0 10 0 6 2 8 9 1 10 5 7 8 10 1 10 8 5 2 6 1 5 10 8 10 5 3...
result:
ok 1020 lines
Test #4:
score: 20
Accepted
time: 1ms
memory: 7772kb
input:
14 11 1 1 8 1 4 11 2 4 8 1 2 7 1 7 11 2 2 9 1 6 10 1 2 6 1 8 10 1 2 6 2 9 10 1 9 9 1 3 10 1 2 4
output:
0 1 0
result:
ok 3 lines
Test #5:
score: 0
Time Limit Exceeded
input:
2000 2000 1 1589 1640 1 1741 1765 2 191 1596 1 426 493 2 1434 1606 1 925 955 2 589 1148 2 1347 1608 2 686 1516 1 1535 1563 1 1835 1841 1 1513 1537 2 30 1710 2 123 171 2 1 2000 2 128 1310 2 270 879 1 1918 1941 2 965 1951 2 176 1452 1 1391 1421 1 614 664 2 1 2000 1 296 328 1 1378 1402 1 29 47 1 92 123...
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%