QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#449592 | #8301. Hold the Line | PetroTarnavskyi# | WA | 4128ms | 4944kb | C++20 | 1.7kb | 2024-06-21 15:10:28 | 2024-06-21 15:10:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int INF = 1e9 + 47;
int f(const set<int>& s, int h)
{
auto it = s.lower_bound(h);
int res = INF;
if (it != s.end())
res = min(res, *it - h);
if (it != s.begin())
res = min(res, h - *prev(it));
return res;
}
struct SegTree
{
int n;
vector<set<int>> t;
void init(int _n)
{
n = 1;
while (n < _n)
n *= 2;
t.clear();
t.resize(2 * n - 1);
}
void upd(int v, int tl, int tr, int pos, int h)
{
t[v].insert(h);
if (tl == tr - 1)
{
return;
}
int tm = (tl + tr) / 2;
upd(2 * v + 1, tl, tm, pos, h);
upd(2 * v + 2, tm, tr, pos, h);
}
int query(int v, int tl, int tr, int l, int r, int h)
{
if (r <= tl || tr <= l)
return INF;
if (l <= tl && tr <= r)
return f(t[v], h);
int tm = (tl + tr) / 2;
return min(query(2 * v + 1, tl, tm, l, r, h), query(2 * v + 2, tm, tr, l, r, h));
}
} st;
void solve()
{
int n, m;
cin >> n >> m;
st.init(n);
while (m--)
{
int t;
cin >> t;
if (t == 0)
{
int x, h;
cin >> x >> h;
x--;
st.upd(0, 0, st.n, x, h);
}
else
{
int l, r, h;
cin >> l >> r >> h;
l--;
int ans = st.query(0, 0, st.n, l, r, h);
cout << (ans == INF ? -1 : ans) << "\n";
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3736kb
input:
1 3 5 1 1 3 2 0 1 1 0 3 3 1 1 2 2 1 2 3 2
output:
-1 1 1
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 4128ms
memory: 4944kb
input:
3000 100 200 0 59 64091111 1 10 94 45205032 0 41 67249140 1 15 93 79570187 0 51 83215051 1 3 22 20062363 0 21 5188814 1 43 94 79642299 0 73 39313603 1 43 67 17001771 0 65 10784990 1 51 69 73368509 0 42 57377517 1 36 49 17483147 0 40 67280095 1 3 41 25139505 0 56 22833553 1 26 65 15640242 0 22 189761...
output:
18886079 12321047 44028748 3572752 11812957 6119369 6698157 14174098 4855252 2221206 1596905 1243665 3120922 6997364 2017635 494034 2499997 90484 977838 1193064 1144184 734969 3527915 4159424 2354329 774042 3211890 1785837 283130 3493739 1751056 1759085 845742 3218058 1098857 2028531 379947 2455095 ...
result:
wrong answer 3rd lines differ - expected: '-1', found: '44028748'