QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#188799 | #2559. Endless Road | Insert_Username_Here | WA | 6ms | 18912kb | C++20 | 4.4kb | 2023-09-26 14:27:11 | 2023-09-26 14:27:11 |
Judging History
answer
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
// copium
struct bit {
int bit[1 << 18];
void update(int i, int val) {
i++;
while(i <= (1 << 18)) {
bit[i] += val;
i += i & (-i);
}
}
int query(int i) {
i++;
int sum = 0;
while(i > 0) {
sum += bit[i];
i -= i & (-i);
}
return sum;
}
int query(int l, int r) {
if(l == 0) return query(r);
return query(r) - query(l - 1);
}
} sum;
const int N = 1 << 18;
pair<pair<int, int>, int> arr[250001];
struct seg {
pair<int, int> seg[N << 1];
int lazy[N << 1];
void kms(int i, int val) {
seg[i].f += val, lazy[i] += val;
}
void push(int i) {
if(lazy[i]) {
kms(2 * i, lazy[i]), kms(2 * i + 1, lazy[i]);
lazy[i] = 0;
}
}
void init(int i = 1, int l1 = 0, int r1 = N - 1) {
lazy[i] = 0;
if(l1 == r1) {
seg[i] = mp(2e9, 0);
return;
}
int mid = (l1 + r1) / 2;
init(2 * i, l1, mid);
init(2 * i + 1, mid + 1, r1);
pull(i);
}
void pull(int i) {
if(seg[2 * i].f == seg[2 * i + 1].f) {
if(arr[seg[2 * i].s].s < arr[seg[2 * i + 1].s].s) seg[i] = seg[2 * i];
else seg[i] = seg[2 * i + 1];
} else seg[i] = min(seg[2 * i], seg[2 * i + 1]);
}
void upd(int i, pair<int, int> val, int i1 = 1, int l1 = 0, int r1 = N - 1) {
if(l1 > i || r1 < i) return;
if(i == l1 && i == r1) {
seg[i1] = val;
return;
}
int mid = (l1 + r1) / 2;
push(i1);
upd(i, val, 2 * i1, l1, mid);
upd(i, val, 2 * i1 + 1, mid + 1, r1);
pull(i1);
}
void inc(int l, int r, int val, int i = 1, int l1 = 0, int r1 = N - 1) {
if(l1 > r || r1 < l) return;
if(l <= l1 && r1 <= r) {
kms(i, val);
return;
}
push(i);
int mid = (l1 + r1) / 2;
inc(l, r, val, 2 * i, l1, mid);
inc(l, r, val, 2 * i + 1, mid + 1, r1);
pull(i);
}
pair<int, int> query(int l, int r, int i = 1, int l1 = 0, int r1 = N - 1) {
if(l1 > r || r1 < l) return mp(2e9, 2e9);
if(l <= l1 && r1 <= r) return seg[i];
push(i);
int mid = (l1 + r1) / 2;
return min(query(l, r, 2 * i, l1, mid), query(l, r, 2 * i + 1, mid + 1, r1));
}
} seg1, seg2;
int n;
int wxzs[500001];
set<pair<int, int>> s;
set<int> bk;
void add(int i) {
seg1.upd(i, mp(sum.query(arr[i].f.f, arr[i].f.s - 1), i));
s.insert(mp(arr[i].f.s, i));
}
void del(int l, int r) {
auto it = bk.lower_bound(l);
while(it != bk.end() && *it < r) {
auto it2 = s.lower_bound(mp(*it + 1, 0));
if(it2 != s.end()) {
int idfk = lower_bound(arr, arr + n, mp(mp(*it, 0), 0)) - arr;
if(it2->s <= idfk) seg1.inc(it2->s, idfk, wxzs[*it] - wxzs[*it + 1]);
}
sum.update(*it, wxzs[*it] - wxzs[*it + 1]);
it = bk.erase(it);
if(it == bk.end()) return;
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
pair<int, int> idk[2 * n];
for(int i = 0; i < 2 * n; i++) {
cin >> idk[i].f;
idk[i].s = i;
}
sort(idk, idk + 2 * n);
int cur = 0;
int idfk[2 * n];
wxzs[0] = idk[0].f;
for(int i = 0; i < 2 * n; i++) {
if(i > 0 && idk[i].f != idk[i - 1].f) {
sum.update(cur, idk[i].f - idk[i - 1].f);
bk.insert(cur);
cur++;
wxzs[cur] = idk[i].f;
}
idfk[i] = cur;
}
for(int i = 0; i < 2 * n; i++) {
if(idk[i].s & 1) arr[idk[i].s / 2].f.s = idfk[i];
else arr[idk[i].s / 2].f.f = idfk[i];
arr[i / 2].s = i / 2 + 1;
}
sort(arr, arr + n);
seg1.init(), seg2.init();
cur = 2e9;
for(int i = n - 1; i >= 0; i--) {
if(arr[i].f.s < cur) {
cur = arr[i].f.s;
add(i);
}
else seg2.upd(i, mp(arr[i].f.s, i));
}
for(int i = 0; i < n; i++) {
// for(int j = 0; j < n; j++) cout << seg1.query(j, j).f << " " << arr[seg1.query(j, j).s].s << "\n";
cur = seg1.seg[1].s;
cout << arr[cur].s << " ";
del(arr[cur].f.f, arr[cur].f.s);
seg1.upd(cur, mp(2e9, 0));
auto it = s.erase(s.find(mp(arr[cur].f.s, cur)));
cur = -1;
if(it != s.begin()) cur = prev(it)->s;
int whar = 2e9;
if(it != s.end()) whar = it->f;
while(cur < n) {
auto thing = seg2.query(max(0, cur), n);
if(thing.f >= whar) break;
cur = thing.s;
add(cur);
seg2.upd(cur, mp(2e9, 0));
}
}
cout << "\n";
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 18452kb
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: 6ms
memory: 18912kb
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: 3ms
memory: 18736kb
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: 0ms
memory: 18456kb
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 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 39 19 20 21 22 23 24 25 26 27 28 32 33 37 38 40 29 30 31 57 73 34 47 71 35 36 41 42 58 43 44 46 51 66 52 77 89 53 54 45 48 62 49 64 80 50 60 79 91 55 65 63 83 56 59 61 67 72 82 86 90 96 68 75 81 93 69 74 84 92 70 87 88 94 97 99 76 78 85 95 98 100
result:
wrong answer 12th words differ - expected: '38', found: '12'