QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#618705 | #2559. Endless Road | Milkcat2009 | WA | 12ms | 39040kb | C++14 | 4.1kb | 2024-10-07 07:38:25 | 2024-10-07 07:38:26 |
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) cerr << "QWQ " << u << ' ' << v << '\n', 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 (l <= nl && nr <= r) { 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]);
});
REP(i, 1, n) {
int x = o[i]; v[x] = 2e9, mdf(rt, 1, n, L[x], m, x);
cerr << "S " << x << ' ' << L[x] << ' ' << R[x] << '\n';
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) cout << "DICK\n", exit(0);
} else {
for (int v : G[x])
if (!-- dg[v]) q.push(v);
}
}
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 39040kb
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: 4ms
memory: 38612kb
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: 12ms
memory: 38096kb
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: 3ms
memory: 38252kb
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:
DICK
result:
wrong answer 1st words differ - expected: '1', found: 'DICK'