QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#69554 | #5302. Useful Algorithm | magicduck | RE | 18ms | 152396kb | C++14 | 2.9kb | 2022-12-28 16:09:34 | 2022-12-28 16:09:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
template <typename T> inline void read(T &F) {
int R = 1; F = 0; char CH = getchar();
for(; !isdigit(CH); CH = getchar()) if(CH == '-') R = -1;
for(; isdigit(CH); CH = getchar()) F = F * 10 + CH - 48;
F *= R;
}
inline void file(string str) {
freopen((str + ".in").c_str(), "r", stdin);
freopen((str + ".out").c_str(), "w", stdout);
}
const int N = 1e5 + 10, Log = 18, M = 1 << 16;
struct segmenttree {
int mx[M * 4 + 110], ma[M * 4 + 110], mb[M * 4 + 110], id[M], len; multiset<int> sa[M], sb[M];
void build(int pos, int l, int r) {
ma[pos] = mb[pos] = -1e9;
if(l == r) {id[l] = pos; return;}
int mid = (l + r) >> 1;
build(pos << 1, l, mid), build(pos << 1 | 1, mid + 1, r);
}
void init(int x) {
len = 1 << x, build(1, 0, len / 2);
for(int i = 0; i <= len / 2; i++) sa[i].insert(-1e9), sb[i].insert(-1e9);
}
void push_up(int pos) {
ma[pos] = max(ma[pos << 1], ma[pos << 1 | 1]);
mb[pos] = max(mb[pos << 1], mb[pos << 1 | 1]);
mx[pos] = max(max(mx[pos << 1], mx[pos << 1 | 1]), ma[pos << 1 | 1] + max(ma[pos << 1], mb[pos << 1]));
}
void ins(int x, int y) {
x &= (len - 1); const int z = abs(x - len / 2);
if(x >= len / 2) sa[z].insert(y), ma[id[z]] = max(ma[id[z]], y);
if(x <= len / 2) sb[z].insert(y), mb[id[z]] = max(mb[id[z]], y);
x = id[z]; mx[x] = ma[x] + max(ma[x], mb[x]); x >>= 1; while(x) push_up(x), x >>= 1;
}
void del(int x, int y) {
x &= (len - 1); const int z = abs(x - len / 2);
if(x >= len / 2) sa[z].erase(sa[z].find(y)), ma[id[z]] = *sa[z].begin();
if(x <= len / 2) sb[z].erase(sb[z].find(y)), mb[id[z]] = *sb[z].begin();
x = id[z]; mx[x] = ma[x] + max(ma[x], mb[x]); x >>= 1; while(x) push_up(x), x >>= 1;
}
int qry() {
return mx[1];
}
}tr[Log];
int c[N], d[N], n, m, q, w[Log];
LL calc() {
LL ans = 0;
for(int i = 1; i <= m; i++)
ans = max(ans, 1LL * w[i] * tr[i].qry());
return ans;
}
int main() {
//file("");
read(n), read(m), read(q);
for(int i = 1; i <= m; i++) tr[i].init(i), read(w[i]);
for(int i = 1; i <= n; i++) read(c[i]);
for(int i = 1; i <= n; i++) read(d[i]);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++) tr[j].ins(c[i], d[i]);
LL lastans = calc(); cout << lastans << '\n';
for(int i = 1; i <= q; i++) {
LL x, a, b; read(x), read(a), read(b);
x ^= lastans, a ^= lastans, b ^= lastans;
for(int j = 1; j <= m; j++)
tr[j].del(c[x], d[x]), tr[j].ins(a, b);
c[x] = a, d[x] = b; lastans = calc();
cout << lastans << '\n';
}
#ifdef _MagicDuck
fprintf(stderr, "# Time: %.3lf s", (double)clock() / CLOCKS_PER_SEC);
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 18ms
memory: 152396kb
input:
5 3 3 1 2 4 0 0 1 2 7 10 10 5 3 1 27 24 29 20 16 19 13 8 9
output:
24 16 8 0
result:
ok 4 number(s): "24 16 8 0"
Test #2:
score: -100
Runtime Error
input:
10 3 10 927067928 939794644 439925712 4 7 6 2 4 2 0 7 0 7 207761141 796144622 434713413 101162902 804840394 950218456 666995722 154361380 192946720 522277478 1786020431157499334 1786020431157499335 1786020431397722754 1496424903210009138 1496424903210009136 1496424902707960940 981667153012455665 981...