QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#356685 | #8301. Hold the Line | FOY# | WA | 1052ms | 3808kb | C++14 | 1.7kb | 2024-03-18 09:18:36 | 2024-03-18 09:18:37 |
Judging History
answer
#include <vector>
#include <set>
#include <iostream>
using namespace std;
using ll = int;
const ll inf = -1e9;
struct X {
set<ll> vals;
};
ll closest(ll x, set<ll> &a) {
auto u = a.upper_bound(x);
auto l = a.lower_bound(x);
ll ans = -inf;
if (u != a.begin())
ans = *prev(u);
if (l != a.end())
if (abs(ans-x) > abs(*l-x)) ans = *l;
return ans;
}
ll closest(ll x, ll y, ll z) {
if (abs(x-y) < abs(x-z)) return y;
else return z;
}
struct Segtree {
ll n;
vector<X> tree;
Segtree(ll n): n(n), tree(4*n) {
}
void insert(ll idx, ll val, ll cl = 0, ll cr = -1, ll k = 1) {
if (cr == -1) cr = n;
tree[k].vals.insert(val);
if (cl == cr-1) return;
ll mid = (cl+cr)/2;
if (idx < mid) insert(idx, val, cl, mid, k*2);
else insert(idx, val, mid, cr, k*2+1);
}
ll act(ll l, ll r, ll targ, ll cl = 0, ll cr = -1, ll k = 1) {
if (cr == -1) cr = n;
if (cr <= l || r <= cl) return -inf;
if (l <= cl && r >= cr) {
return closest(targ, tree[k].vals);
}
ll mid = (cl+cr)/2;
ll a = act(l, r, targ, cl, mid, k*2);
ll b = act(l, r, targ, mid, cr, k*2+1);
return closest(targ, a, b);
}
};
void solve() {
int n, m; cin >> n >> m;
Segtree s(n);
for (int i = 0; i < m; i++) {
ll type; cin >> type;
if (type == 0) {
ll x, h; cin >> x>> h;
s.insert(x-1, h);
}
else {
ll l, r, h; cin >> l >> r >> h;
l--;
ll ans = s.act(l, r, h);
if (ans == -inf) cout << -1 << endl;
else cout << abs(ans-h) << endl;
}
}
}
int main() {
int t; cin >> t;
while (t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3808kb
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: 1052ms
memory: 3672kb
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 -1 3572752 47089340 9277398 39894370 19950691 4855252 2221206 1596905 -1 3120922 34260194 3353597 -1 2499997 -1 15114024 1193064 49448136 734969 3981124 4159424 5836824 61155540 5163746 -1 283130 3982548 -1 -1 -1 9647216 2356693 8711627 379947 70230536 2637615 7856589 153976 148089...
result:
wrong answer 830th lines differ - expected: '102096970', found: '-1'