QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#446162 | #8301. Hold the Line | lym | WA | 147ms | 4016kb | C++20 | 2.2kb | 2024-06-16 22:49:55 | 2024-06-16 22:49:55 |
Judging History
answer
#include<bits/stdc++.h>
using i64 = long long;
const int inf = 1e9 + 10;
struct Block {
int n, b;
std::vector<int> blo, a;
std::vector<std::set<int> > v;
std::vector<std::set<int> > st;
void init(int n) {
this -> n = n;
this -> b = (int) std::pow(n, 0.48);
blo.assign(n + 1, 0);
v.assign(n + 1, {});
a.assign(n + 1, 0);
//st.assign(n + 1, {});
for (int i = 1; i <= n; i ++) {
blo[i] = (i - 1) / b + 1;
}
}
void add(int x, int c) {
int p = blo[x];
v[p].insert(c);
a[x] = c;
//st[p].insert(x);
}
int query(int l, int r, int c) {
int res = inf, p = blo[l], q = blo[r];
/*auto L = st[p].lower_bound(l);
while (L != st[p].end() && *L <= r) {
res = std::min(res, std::abs(a[*L] - c));
L = next(L);
}*/
for (int i = l; i <= std::min(r, p * b); i ++) {
if (a[i]) {
res = std::min(res, std::abs(a[i] - c));
}
}
if (p == q) return res;
/*auto R = st[q].begin();
while (R != st[q].end() && *R <= r) {
res = std::min(res, std::abs(a[*R] - c));
R = next(R);
}*/
for (int i = (q - 1) * b + 1; i <= q * b; i ++) {
if (a[i]) {
res = std::min(res, std::abs(a[i] - c));
}
}
for (int i = p + 1; i < q; i ++) {
auto it = v[i].lower_bound(c);
if (it != v[i].end()) {
res = std::min(res, std::abs(*it - c));
}
if (it != v[i].begin()) {
it = prev(it);
res = std::min(res, std::abs(*it - c));
}
}
return res;
}
};
int read(){
int red=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){ if(ch=='-') f=-f;ch=getchar();}
while(ch>='0'&&ch<='9') red=red*10+ch-48,ch=getchar();
return red*f;
}
void solve() {
int n, m;
n = read();
m = read();
Block t;
t.init(n);
while (m --) {
int op;
//std::cin >> op;
op = read();
if (op & 1) {
int l, r, v;
//std::cin >> l >> r >> v;
l = read();
r = read();
v = read();
int res = t.query(l, r, v);
if (res == inf) {
res = -1;
}
std::cout << res << '\n';
} else {
int x, v;
//std::cin >> x >> v;
x = read();
v = read();
t.add(x, v);
}
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
t = read();
while (t --) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3876kb
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: 147ms
memory: 4016kb
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 29985193 15114024 1193064 49448136 734969 3981124 4159424 5836824 61155540 3211890 -1 283130 3982548 -1 -1 -1 5047211 2356693 8711627 379947 70230536 2637615 7856589 153976 ...
result:
wrong answer 18th lines differ - expected: '-1', found: '29985193'