QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#177330 | #6881. The Mine of Abyss | PPP# | AC ✓ | 822ms | 14212kb | C++17 | 3.0kb | 2023-09-12 20:57:09 | 2023-09-12 20:57:10 |
Judging History
answer
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n, q;
const int maxN = 5e4 + 10;
int a[maxN], b[maxN];
typedef vector<pair<ll,ll>> node;
node t[4 * maxN];
node merge(const node& a, const node& b) {
node c;
for (auto& x : a) {
for (auto& y : b) {
// cout << x.first << " " << y.first << " " << x.second << " " << y.second << endl;
c.emplace_back(x.first + y.first, x.second + y.second + 1);
}
}
sort(c.begin(), c.end());
node ans;
ll max_r = -1e18;
ll L = -1e18;
for (auto& it : c) {
if (it.first > max_r) {
if (max_r >= 0) {
ans.emplace_back(L, max_r - 1);
}
L = it.first;
max_r = it.second;
}
else {
max_r = max(max_r, it.second);
}
}
if (max_r >= 0) {
ans.emplace_back(L, max_r - 1);
}
return ans;
}
void build(int v, int tl, int tr) {
if (tl == tr) {
t[v] = {{0, 0}, {a[tl], b[tl]}};
return;
}
int tm = (tl + tr) / 2;
build(2 * v, tl, tm);
build(2 * v + 1, tm + 1, tr);
t[v] = merge(t[2 * v], t[2 * v + 1]);
}
void upd(int v, int tl, int tr, int pos) {
if (tl == tr) {
t[v] = {{0, 0}, {a[tl], b[tl]}};
return;
}
int tm = (tl + tr) / 2;
if (pos <= tm) upd(2 * v, tl, tm, pos);
else upd(2 * v + 1, tm + 1, tr, pos);
t[v] = merge(t[2 * v], t[2 * v + 1]);
}
node get(int v, int tl, int tr, int l, int r) {
if (tr < l || tl > r) {
node p = {{0, 0}};
return p;
}
if (l <= tl && tr <= r) {
// cout << " HI " << l << " " << r << " " << tl << " " << tr << endl;
return t[v];
}
int tm = (tl + tr) / 2;
return merge(get(2 * v, tl, tm, l, r), get(2 * v + 1, tm + 1, tr, l, r));
}
void solve() {
cin >> n >> q;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
}
build(1, 1, n);
while (q--) {
int tp;
cin >> tp;
if (tp == 1) {
int k, x, y;
cin >> k >> x >> y;
a[k] = x;
b[k] = y;
upd(1, 1, n, k);
}
else {
int l, r;
cin >> l >> r;
// cout << l << " " << r << " ???? " << endl;
auto nd = get(1, 1, n, l, r);
ll ans = 0;
for (auto& it : nd) {
// cout << it.first << " " << it.second << " ??? " << endl;
ans += it.second - it.first + 1;
}
// exit(0);
cout << ans << '\n';
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
int tst;
cin >> tst;
while (tst--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 822ms
memory: 14212kb
input:
5 50000 50000 66335693 455373104 899598534 953840292 368422768 959249831 322335641 856660797 480850713 530968323 444246089 548960441 177553896 210027481 240619910 965196933 107673862 824855024 92241752 129406040 4394331 263058383 165733990 352925680 548298523 585259106 87906940 102933202 56167973 68...
output:
6347314288230 13412326698823 14303672645309 10014078679793 3207056352395 17712636872598 6895088186582 2708865372007 13359299717471 7521970208616 29403542534309 19086646921794 22131828538506 3925621911951 8121263956040 2791149376358 11044093486507 7978219310275 3019861426855 7716880379924 66583487561...
result:
ok 125000 lines