QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#42722 | #4429. Gebyte's Grind | Antistar | TL | 0ms | 0kb | C++20 | 5.7kb | 2022-08-03 15:59:54 | 2022-08-03 15:59:56 |
Judging History
answer
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
using ll = long long;
const int N = 2000001;
const ll INF = 1e13;
struct fun {
int tp;
ll b, l, r;
};
ll cal(int x, const vector<fun> &s) {
/* cout << "cal " << x << endl; */
for (auto v : s) {
if (x >= v.l && x <= v.r) {
/* cout << "range " << v.l << ' ' << v.r << " " << v.tp << ' ' << v.b << endl; */
if (v.tp == 0)
return v.b;
else
return x + v.b;
}
}
assert(0);
}
vector<fun> compo(const vector<fun> &a, const vector<fun> &b) {
if (a.empty())
return b;
if (b.empty())
return a;
/* cout << endl; */
/* cout << "compo " << a.size() << " " << b.size() << endl; */
vector<fun> s;
for (auto v : a) {
if (v.tp == 0) {
for (auto p : b) {
if (p.l <= v.b && p.r >= v.b) {
/* cout << p.l << " " << p.r << " b: " << v.b << endl; */
if (p.tp == 0) {
s.push_back({0, p.b, v.l, v.r});
/* cout << "case11 " << v.l << " " << v.r << " " << 0 << " " << p.b << endl; */
}
else {
s.push_back({0, p.b + v.b, v.l, v.r});
/* cout << "case12 " << v.l << " " << v.r << " " << 0 << " " << p.b << " " << v.b << endl; */
}
break;
}
}
}
else {
for (auto p : b) {
if (p.l <= v.b + v.r && p.r >= v.b + v.l) {
ll ql = p.l - v.b, qr = p.r - v.b;
if (p.tp == 0)
s.push_back({0, p.b, max(v.l, ql), min(v.r, qr)});
else
s.push_back({1, v.b + p.b, max(v.l, ql), min(v.r, qr)});
/* cout << "case2 " << max(v.l, ql) << " " << min(v.r, qr) << endl; */
}
}
}
}
vector<fun> t;
for (auto v : s) {
if (!t.empty() && (t.back().tp == v.tp && t.back().b == v.b)) {
t.back().r = v.r;
}
else
t.push_back(v);
}
return t;
}
vector<fun> t[N << 2];
void setx(int x, int tp, ll v) {
if (tp == 0) {
t[x] = vector<fun>(2);
t[x][0] = {0, 0, -INF, v};
t[x][1] = {1, -v, v + 1, INF};
}
else if (tp == 1) {
t[x] = vector<fun>(2);
t[x][0] = {0, 0, -INF, v - 1};
t[x][1] = {0, v, v, INF};
}
else {
t[x] = vector<fun>(3);
t[x][0] = {0, 0, -INF, 0};
t[x][1] = {0, v, 1, v};
t[x][2] = {1, 0, v + 1, INF};
}
}
void pr(int x) {
/* for (auto v : t[x]) { */
/* cout << "range " << v.l << " " << v.r << " type " << v.tp << " b " << v.b << endl; */
/* } */
/* cout << endl; */
}
void pr(int x, int l, int r) {
/* cout << x << " " << l << " " << r << endl; */
pr(x);
if (l == r) {
}
else {
int mid = (l + r) / 2;
if (l <= mid)
pr(x << 1, l, mid);
if (r > mid)
pr(x << 1 | 1, mid + 1, r);
}
}
void build(int x, int l, int r, const vector<int> &tp, const vector<ll> &v) {
if (l == r) {
setx(x, tp[l], v[l]);
/* cout << x << " " << l << " " << r << endl; */
pr(x);
}
else {
int mid = (l + r) / 2;
if (l <= mid)
build(x << 1, l, mid, tp, v);
if (r > mid)
build(x << 1 | 1, mid + 1, r, tp, v);
t[x] = compo(t[x << 1], t[x << 1 | 1]);
/* cout << x << " " << l << " " << r << endl; */
pr(x);
}
}
pair<vector<fun>, int> lower_bound(int x, int l, int r, int L,
const vector<fun> &prev, const int cx) {
if (L <= l) {
/* cout << endl; */
/* cout << "append " << x << " " << l << " " << r << endl; */
/* for (auto v : prev) */
/* cout << v.l << " " << v.r << ' ' << v.tp << " " << v.b << endl; */
/* for (auto v : t[x]) */
/* cout << v.l << " " << v.r << ' ' << v.tp << " " << v.b << endl; */
auto vv = compo(prev, t[x]);
/* for (auto v : vv) */
/* cout << v.l << " " << v.r << ' ' << v.tp << " " << v.b << endl; */
if (cal(cx, vv) != 0) {
/* cout << "seccess" << endl; */
return {vv, r};
}
}
if (r == l)
return {prev, l - 1};
else {
int mid = (l + r) / 2;
if (mid < L) {
return lower_bound(x << 1 | 1, mid + 1, r, L, prev, cx);
}
else {
auto la = lower_bound(x << 1, l, mid, L, prev, cx);
if (la.second < mid)
return la;
else
return lower_bound(x << 1 | 1, mid + 1, r, L, la.first, cx);
}
}
};
void modify(int x, int l, int r, int pos, int tp, ll v) {
if (l == r) {
setx(x, tp, v);
}
else {
int mid = (l + r) / 2;
if (pos <= mid)
modify(x << 1, l, mid, pos, tp, v);
else
modify(x << 1 | 1, mid + 1, r, pos, tp, v);
t[x] = compo(t[x << 1], t[x << 1 | 1]);
}
}
void Main() {
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
vector<int> tp(n + 1);
vector<ll> v(n + 1);
char s[5];
for (int i = 1; i <= n; i++) {
scanf("%s%lld", s, &v[i]);
if (s[0] == 'B')
tp[i] = 0;
if (s[0] == 'K')
tp[i] = 1;
if (s[0] == 'C')
tp[i] = 2;
}
build(1, 1, n, tp, v);
/* pr(1,1,n); */
for (int i = 1; i <= m; i++) {
scanf("%s", s);
if (s[0] == 'Z') {
int idx;
scanf("%d", &idx);
scanf("%s%lld", s, &v[idx]);
if (s[0] == 'B')
tp[idx] = 0;
if (s[0] == 'K')
tp[idx] = 1;
if (s[0] == 'C')
tp[idx] = 2;
modify(1, 1, n, idx, tp[idx], v[idx]);
}
else {
pr(1, 1, n);
int idx;
scanf("%d", &idx);
auto [funs, r] = lower_bound(1, 1, n, idx, vector<fun>(), k);
if (r < idx)
puts("-1");
else
printf("%d\n", r);
}
}
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
Main();
}
}
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
1 2000000 4000000 1000000000000 B 2982992025 B 1226542907 B 2299259203 B 1223702056 B 1407121251 B 340783317 B 1259091208 B 2101980047 B 2611543443 B 2010658889 B 4233714406 B 3112120167 B 2311876255 B 2789960428 B 3008572010 B 1 B 2464951378 B 1364240867 B 2829584762 B 2511437438 B 692948679 B 1113...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...