QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#105745 | #6192. Interval Problem | Melacau | TL | 1ms | 5344kb | C++17 | 2.3kb | 2023-05-15 10:59:32 | 2023-05-15 10:59:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using s64 = long long;
const int N = 2e5 + 5;
const int M = 4e5 + 5;
const int T = 1 << 20;
int n, m, cnt[M], tag[M];
struct Seg{int l, r, k;}seg[N];
s64 ans[N];
void solve() {
sort(seg, seg + n, [](const Seg& a, const Seg& b){
return a.l == b.l ? a.r > b.r : a.l < b.l;
});
fill(cnt, cnt + m + 1, 0);
fill(tag, tag + m + 1, 0);
for (int i = 0; i < n; ++i) ++cnt[seg[i].r], ++tag[seg[i].r];
s64 res = 0;
for (int i = 0, j = 0, curR = -1; j < n && i < m; ++i) {
if (seg[j].l == i && seg[j].r > curR) curR = seg[j].r;
cerr << i << ' ' << res << ' ' << curR << ' ' << tag[i] << endl;
while (j < n && seg[j].l == i) {
ans[seg[j].k] += res;
++j;
}
if (curR == i) {res = 0; curR = -1;}
else {
tag[curR] += tag[i];
res += cnt[i];
res += tag[i];
}
}
// cerr << endl;
}
void solveint() {
sort(seg, seg + n, [](const Seg& a, const Seg& b){
return a.r > b.r;
});
fill(cnt, cnt + m + 1, 0);
static int lcnt[M] = {0};
for (int i = 0; i < n; ++i) ++cnt[seg[i].r];
for (int i = 1; i < m; ++i) cnt[i] += cnt[i - 1];
for (int i = 0, j, now = 0, x = m; i < n; i = j) {
for (j = i; j < n && seg[j].r == seg[i].r; ++j) ++lcnt[seg[j].l];
for (; x > seg[i].r; --x) now -= lcnt[x];
for (int k = i; k < j; ++k) {
ans[seg[k].k] += cnt[seg[k].r] - (seg[k].l == 0 ? 0 : cnt[seg[k].l - 1]);
ans[seg[k].k] += now;
}
now += j - i;
}
}
void reverse() {
for (int i = 0; i < n; ++i) {
swap(seg[i].l, seg[i].r);
seg[i].l = m - seg[i].l - 1;
seg[i].r = m - seg[i].r - 1;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cin >> n; m = n << 1;
for (int i = 0; i < n; ++i) {
cin >> seg[i].l >> seg[i].r;
--seg[i].l; --seg[i].r;
seg[i].k = i;
}
solve();
// for (int i = 0; i < n; ++i)
// cerr << ans[i] << " \n"[i + 1 == n];
solveint();
reverse();
// for (int i = 0; i < n; ++i)
// cerr << ans[i] << " \n"[i + 1 == n];
solve();
for (int i = 0; i < n; ++i)
cout << ans[i] - 1 << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5344kb
input:
5 2 3 6 7 1 9 5 10 4 8
output:
7 5 4 5 5
result:
ok 5 number(s): "7 5 4 5 5"
Test #2:
score: -100
Time Limit Exceeded
input:
200000 342504 342505 248314 248317 259328 259334 234817 234821 225726 225732 371424 371425 260562 260565 34752 34753 132098 132100 262130 262134 7254 7255 228491 228492 43488 43492 188408 188410 11691 11692 350334 350335 327350 327352 360684 360685 182051 182052 72131 72135 194666 194668 61303 61313...