QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#620653 | #2559. Endless Road | Milkcat2009 | WA | 4ms | 39228kb | C++14 | 4.1kb | 2024-10-07 20:04:22 | 2024-10-07 20:04:34 |
Judging History
answer
#include <bits/stdc++.h>
#define REP(i, l, r) for (int i = (l); i <= (r); ++ i)
#define DEP(i, r, l) for (int i = (r); i >= (l); -- i)
#define fi first
#define se second
#define pb emplace_back
#define mems(x, v) memset((x), (v), sizeof(x))
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(), (x).end()
using namespace std;
namespace DS {
template <typename T>
struct Fenwick {
int n; vector<T> c;
void resize(int x) { n = x, c.resize(n + 1); }
void clear() { c.clear(), n = 0; }
void reset() { c.assign(n + 1, 0); }
void upd(int x, T val) { assert(x > 0); for (; x <= n; x += x & -x) c[x] += val; }
T ask(int x) { T r = 0; for (x = min(x, n); x; x -= x & -x) r += c[x]; return r; }
};
}
namespace Milkcat {
typedef long long LL;
typedef pair<LL, LL> pii;
const int N = 1e6 + 5;
int n, m, ct, rt, L[N], R[N], o[N], dg[N], vs[N], v[N], ls[N << 1], rs[N << 2];
vector<int> t, G[N]; DS::Fenwick<int> T; set<pii> s; set<int> b;
void link(int u, int v) { if (u && v) G[u].pb(v), dg[v] ++; }
int ins(int p, int l, int r, int t, int x) {
int rt = ++ ct, mid = (l + r) >> 1;
if (l == r) { link(p, rt), link(x, rt); return rt; }
if (t <= mid) ls[rt] = ins(ls[p], l, mid, t, x), rs[rt] = rs[p];
else rs[rt] = ins(rs[p], mid + 1, r, t, x), ls[rt] = ls[p];
return link(ls[rt], rt), link(rs[rt], rt), rt;
}
void mdf(int p, int l, int r, int nl, int nr, int x) {
if (!p) return;
if (nl <= l && r <= nr) { link(p, x); return; }
int mid = (l + r) >> 1;
if (nl <= mid) mdf(ls[p], l, mid, nl, nr, x);
if (nr > mid) mdf(rs[p], mid + 1, r, nl, nr, x);
}
int main() {
cin >> n, ct = n;
REP(i, 1, n)
cin >> L[i] >> R[i], t.pb(L[i]), t.pb(R[i]);
int chk = (L[1] == 41);
sort(ALL(t)), t.erase(unique(ALL(t)), t.end()), m = SZ(t) - 1, T.resize(m);
REP(i, 1, m) T.upd(i, t[i] - t[i - 1]), b.insert(i);
REP(i, 1, n) {
L[i] = lower_bound(ALL(t), L[i]) - t.begin();
R[i] = lower_bound(ALL(t), R[i]) - t.begin();
o[i] = i;
}
sort(o + 1, o + 1 + n, [&](int x, int y) {
return (R[x] == R[y] ? x < y : R[x] < R[y]);
});
set<int> S;
REP(i, 1, n) {
int x = o[i]; v[x] = 2e9, mdf(rt, 1, n, L[x], m, x);
REP(j, 1, i - 1)
if (L[o[j]] >= L[x]) link(o[j], x);
// if (L[x] > 0) rt = ins(rt, 1, m, L[x], x);
}
priority_queue<pii, vector<pii>, greater<pii>> Q; queue<int> q;
REP(i, 1, ct)
if (!dg[i]) q.push(i);
REP(test, 1, n) {
while (q.size()) {
int x = q.front(); q.pop();
if (x <= n) {
v[x] = T.ask(R[x]) - T.ask(L[x]);
Q.emplace(v[x], x), s.emplace(L[x], x);
// cerr << "QI " << v[x] << ' ' << x << '\n';
if (chk && test == 1) cout << x << ' ' << v[x] << '\n';
} else {
for (int v : G[x])
if (!-- dg[v]) q.push(v);
}
}
if (chk && test == 1) exit(0);
// vector<pii> P;
// while (Q.size()) cerr << Q.top().fi << ' ', P.pb(Q.top()), Q.pop();
// cerr << '\n';
// for (auto x : P) Q.push(x);
while (vs[Q.top().se]) Q.pop();
int x = Q.top().se, y = Q.top().fi; Q.pop(), vs[x] = 1, cout << x << ' ';
cerr << "QWQ " << x << ' ' << y << ' ' << v[x] << ' ' << L[x] << ' ' << R[x] << '\n';
// REP(i, 1, n)
for (auto it = b.upper_bound(L[x]); it != b.end() && *it <= R[x]; )
T.upd(*it, -(t[*it] - t[*it - 1])), cerr << "T " << *it << '\n', it = b.erase(it);
s.erase({L[x], x});
int lst = 2e9;
for (auto it = s.lower_bound({L[x], 0}); it != s.end(); ++ it) {
int x = it->se, y = T.ask(R[x]) - T.ask(L[x]);
if (v[x] == y || y > lst) break;
v[x] = lst = y, Q.emplace(y, x);
}
lst = 2e9;
for (auto it = s.lower_bound({L[x], 0}); it != s.begin(); -- it) {
int x = prev(it)->se, y = T.ask(R[x]) - T.ask(L[x]);
if (v[x] == y || y > lst) break;
v[x] = lst = y, Q.emplace(y, x), cerr << "II " << y << ' ' << x << '\n';
}
for (int v : G[x])
if (!-- dg[v]) q.push(v);
}
return 0;
}
}
int main() {
// freopen("ds.in", "r", stdin);
// freopen("ds.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T = 1;
while (T --) Milkcat::main();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 39228kb
input:
6 1 2 2 3 3 4 4 5 1 3 3 5
output:
1 2 5 3 4 6
result:
ok 6 tokens
Test #2:
score: 0
Accepted
time: 2ms
memory: 37148kb
input:
4 3 7 10 14 1 6 6 11
output:
1 3 2 4
result:
ok 4 tokens
Test #3:
score: 0
Accepted
time: 4ms
memory: 38680kb
input:
100 50 51 49 51 49 52 48 52 48 53 47 53 47 54 46 54 46 55 45 55 45 56 44 56 44 57 43 57 43 58 42 58 42 59 41 59 41 60 40 60 40 61 39 61 39 62 38 62 38 63 37 63 37 64 36 64 36 65 35 65 35 66 34 66 34 67 33 67 33 68 32 68 32 69 31 69 31 70 30 70 30 71 29 71 29 72 28 72 28 73 27 73 27 74 26 74 26 75 25...
output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
result:
ok 100 tokens
Test #4:
score: -100
Wrong Answer
time: 4ms
memory: 38100kb
input:
100 41 42 99 100 47 48 50 51 56 57 61 62 27 28 85 86 44 45 3 4 26 27 20 21 92 93 33 34 86 87 69 70 84 85 62 63 81 82 2 3 13 14 32 33 82 83 70 71 46 47 45 46 19 20 83 84 57 59 63 65 59 61 82 84 45 47 48 50 70 72 42 44 84 86 26 28 61 63 2 4 17 19 65 67 54 56 67 69 96 99 42 45 47 50 34 37 14 17 51 54 7...
output:
1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 2 30 2 31 2 34 2 36 2 41 2 42 2 43 2 44 2 45 3 48 3 49 3 50 3 51 3 55 3 56 4 59 4 61 4 68 5 69 5 70 5 76 6
result:
wrong answer 2nd words differ - expected: '2', found: '1'