QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#114747 | #6192. Interval Problem | std_abs# | WA | 283ms | 466092kb | C++14 | 2.8kb | 2023-06-23 14:12:10 | 2023-06-23 14:12:12 |
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);
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;
else {
rts[x] = rts[q.front()]->modify(i + 1, 2 * n, 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);
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;
else {
rts[x] = rts[q.front()]->modify(0, 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: 3444kb
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: 283ms
memory: 466092kb
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:
428743 772456 588982 365175 399994 1328528 399996 399997 266047 606777 792738 199999 756491 599989 594148 575159 399996 439302 599987 363931 399996 461289 199999 241335 199999 399996 692065 1023403 419356 527177 212083 199999 697333 529128 407465 226931 894155 412527 599993 599988 399997 483593 7136...
result:
wrong answer 1st numbers differ - expected: '12', found: '428743'