QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#114748 | #6192. Interval Problem | std_abs# | WA | 247ms | 402712kb | C++14 | 2.9kb | 2023-06-23 14:16:36 | 2023-06-23 14:16:39 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
#define sz(a) ((int)a.size())
const int mod = 998244353, N = 400005;
typedef pair<int, int> pi;
int c[N];
struct seg {
int l, r, cnt, lz;
ll v;
seg *ch[2]{};
seg(int _l, int _r) : l(_l), r(_r), lz(0), v(0) {
if (l < r - 1)
ch[0] = new seg(l, l + r >> 1), ch[1] = new seg(l + r >> 1, r), cnt = ch[0]->cnt + ch[1]->cnt;
else
cnt = c[l];
}
seg(seg *oth) : l(oth->l), r(oth->r), cnt(oth->cnt), lz(oth->lz), v(oth->v), ch{oth->ch[0], oth->ch[1]} {}
void push() {
if (lz)
ch[0] = ch[0]->modify(l, r, lz), ch[1] = ch[1]->modify(l, r, lz), lz = 0;
}
void pull() {
v = ch[0]->v + ch[1]->v;
}
seg* modify(int _l, int _r, int d) {
seg* tmp = new seg(this);
if (_l <= l && r <= _r) {
tmp->lz += d;
tmp->v += 1ll * d * cnt;
return tmp;
}
tmp->push();
if (_l < l + r >> 1)
tmp->ch[0] = tmp->ch[0]->modify(_l, _r, d);
if (l + r >> 1 < _r)
tmp->ch[1] = tmp->ch[1]->modify(_l, _r, d);
tmp->pull();
return tmp;
}
};
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
pi a[n];
int id[2 * n];
ll ans[n];
for (int i = 0; i < n; ++i) {
cin >> a[i].first >> a[i].second;
id[--a[i].first] = id[--a[i].second] = i;
ans[i] = n - 1;
}
for (int i = 0; i < 2 * n; ++i)
c[i] = i == a[id[i]].first ? 1 : 0;
queue<int> q;
seg *rt = new seg(0, 2 * n);
vector<seg*> rts(n, nullptr);
int R = 2 * n;
for (int i = 2 * n - 1; ~i; --i) {
int x = id[i];
if (i == a[x].second) {
while (!q.empty() && a[q.front()].first > i)
q.pop();
if (q.empty())
rts[x] = rt, R = i;
else {
rts[x] = rts[q.front()]->modify(i + 1, R, 1);
ans[x] += rts[x]->v;
}
q.push(x);
}
}
while (!q.empty())
q.pop();
rts.assign(n, nullptr);
for (int i = 0; i < 2 * n; ++i)
c[i] = i == a[id[i]].second ? 1 : 0;
rt = new seg(0, 2 * n);
int L = 0;
for (int i = 0; i < 2 * n; ++i) {
int x = id[i];
if (i == a[x].first) {
while (!q.empty() && a[q.front()].second < i)
q.pop();
if (q.empty())
rts[x] = rt, L = i;
else {
rts[x] = rts[q.front()]->modify(L, i, 1);
ans[x] += rts[x]->v;
}
q.push(x);
}
}
for (int i = 0; i < n; ++i)
cout << ans[i] << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3460kb
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
Wrong Answer
time: 247ms
memory: 402712kb
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...
output:
200005 200012 200008 200001 200005 200023 199999 199999 199999 200009 200002 199999 200012 200009 200002 200004 199999 200010 200005 200002 199999 200002 199999 199999 199999 199999 200021 200023 200013 200000 199999 199999 200010 200013 200008 200003 200015 200003 200001 200002 199999 200006 200006...
result:
wrong answer 1st numbers differ - expected: '12', found: '200005'