QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#385720 | #5109. Spider Walk | SolitaryDream | WA | 201ms | 11372kb | C++17 | 4.0kb | 2024-04-11 00:43:13 | 2024-04-11 00:43:15 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int N = 8e5 + 10;
int n, m, s;
namespace Seg {
int L[N], R[N], tg[N];
inline void SetTag(int v, int z) {
tg[v] += z;
L[v] += z;
R[v] += z;
}
inline void PushDown(int v) {
if (tg[v]) {
SetTag(v << 1, tg[v]);
SetTag(v << 1 | 1, tg[v]);
tg[v] = 0;
}
}
inline void PushUp(int v) {
L[v] = L[v << 1];
R[v] = R[v << 1 | 1];
}
inline void Init(int v = 1, int l = 0, int r = n - 1) {
if (l == r) {
int d1 = (s - l + n) % n;
int d2 = (l - s + n) % n;
L[v] = R[v] = min(d1, d2);
return;
}
int mid = (l + r) >> 1;
Init(v << 1, l, mid); Init(v << 1 | 1, mid + 1, r);
PushUp(v);
}
inline int Ask(int x, int v = 1, int l = 0, int r = n - 1) {
if (l == r) return L[v];
int mid = (l + r) >> 1;
PushDown(v);
return x <= mid ? Ask(x, v << 1, l, mid) : Ask(x, v << 1 | 1, mid + 1, r);
}
inline void Set(int x, int z, int v = 1, int l = 0, int r = n - 1) {
if (l == r) { L[v] = R[v] = z; return; }
int mid = (l + r) >> 1;
PushDown(v);
if (x <= mid) Set(x, z, v << 1, l, mid); else Set(x, z, v << 1 | 1, mid + 1, r);
PushUp(v);
}
inline void Add(int x, int y, int z, int v, int l, int r) {
if (x > r || y < l) return;
if (x <= l && r <= y) { SetTag(v, z); return; }
int mid = (l + r) >> 1;
PushDown(v);
Add(x, y, z, v << 1, l, mid); Add(x, y, z, v << 1 | 1, mid + 1, r);
PushUp(v);
}
inline void UpdateInc(int x, int z, int v = 1, int l = 0, int r = n - 1) { // x..n-1
if (l == r) {
if (l >= x) L[v] = R[v] = min(L[v], z + (l - x));
return;
}
int mid = (l + r) >> 1;
PushDown(v);
if (mid < x) UpdateInc(x, z, v << 1 | 1, mid + 1, r);
else {
int vl = L[v << 1 | 1];
if (vl <= z + (mid + 1 - x)) UpdateInc(x, z, v << 1, l, mid);
else { Add(x, n - 1, -1, v << 1, l, mid); UpdateInc(x, z, v << 1 | 1, mid + 1, r); }
}
PushUp(v);
}
inline void UpdateDec(int x, int z, int v = 1, int l = 0, int r = n - 1) { // 0..x
if (x < l || R[v] <= z + (r - x)) return;
if (r <= x && R[v] == z + (r - x) + 1) { SetTag(v, z); return; }
if (l == r) {
if (l <= x) L[v] = R[v] = min(L[v], z + (x - l));
return;
}
int mid = (l + r) >> 1;
PushDown(v);
UpdateDec(x, z, v << 1, l, mid);
UpdateDec(x, z, v << 1 | 1, mid + 1, r);
PushUp(v);
}
inline void PrintAns(int v = 1, int l = 0, int r = n - 1) {
if (l == r) { cout << L[v] << '\n'; return; }
int mid = (l + r) >> 1;
PushDown(v);
PrintAns(v << 1, l, mid); PrintAns(v << 1 | 1, mid + 1, r);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> s;
--s;
vector<pii> ops;
for (int i = 1, x, y; i <= m; ++i) {
cin >> x >> y;
--y;
ops.push_back({x, y});
}
sort(ops.begin(), ops.end(), greater<pii>());
Seg::Init();
for (auto [_x, pb] : ops) {
// Seg::PrintAns();
// cout << endl;
int pa = (pb + n - 1) % n, pc = (pb + 1) % n, pd = (pc + 1) % n;
int vb = Seg::Ask(pb), vc = Seg::Ask(pc);
if (vb == vc) {
// pass
} else if (vb > vc) {
Seg::Set(pc, min(vb, Seg::Ask(pd) + 1));
// a[pb] = vc;
Seg::UpdateDec(pb, vc);
Seg::UpdateDec(n - 1, vc + pb + 1);
} else {
Seg::Set(pb, min(vc, Seg::Ask(pa) + 1));
// a[pc] = vb;
Seg::UpdateInc(pc, vb);
Seg::UpdateInc(0, vb + n - pc);
}
}
Seg::PrintAns();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 201ms
memory: 11372kb
input:
200000 500000 116205 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50...
output:
83794 83795 83795 83796 83797 83798 83799 83800 83801 83802 83803 83804 83805 83806 83807 83808 83809 83810 83811 83812 83813 83814 83815 83816 83817 83818 83819 83820 83821 83822 83823 83824 83825 83826 83827 83828 83829 83830 83831 83832 83833 83834 83835 83836 83837 83838 83839 83840 83841 83842 ...
result:
wrong answer 1st lines differ - expected: '2', found: '83794'