QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#831360 | #3299. Advertisement Matching | ucup-team2172# | WA | 2ms | 14000kb | C++23 | 3.2kb | 2024-12-25 14:04:23 | 2024-12-25 14:04:23 |
Judging History
answer
#include <bits/stdc++.h>
#define inf (0x7f7f7f7f)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
int ch = 0, f = 0; x = 0;
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
if(f) x = -x;
}
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using Oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int maxn = 2.5e5 + 5;
int n, m, q;
long long sum[maxn], sumb[maxn];
class SegmentTree{
public:
static const int siz = 262144;
long long dat[siz << 1], tag[siz << 1];
void build(int x = 1, int l = 0, int r = siz - 1) {
if (l == r) {
if (l >= 1 && l <= n) dat[x] = sum[l];
return;
}
int md = l + r >> 1;
build(x << 1, l, md), build(x << 1 | 1, md + 1, r);
return;
}
void update(int s, int t, int k, int x = 1, int l = 0, int r = siz - 1) {
if (l >= s && r <= t) {
tag[x] += k;
dat[x] += k;
return;
}
int md = l + r >> 1;
if (s <= md) update(s, t, k, x << 1, l, md);
if (t > md) update(s, t, k, x << 1 | 1, md + 1, r);
dat[x] = min(dat[x << 1], dat[x << 1 | 1]) + tag[x];
}
} seg;
int a[maxn], b[maxn];
Oset<pair<int, int> > A;
int main(){
vector<int> veca, vecb;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) scanf("%d", a + i), veca.push_back(a[i]);
for (int i = 1; i <= m; ++i) scanf("%d", b + i), vecb.push_back(b[i]);
for (int i = 1; i <= n; ++i) A.insert(make_pair(-a[i], i));
sort(vecb.begin(), vecb.end());
sort(veca.begin(), veca.end()); reverse(veca.begin(), veca.end());
for (int i = 0; i < m; ++i) sumb[i] = (i ? sumb[i - 1] : 0) + vecb[i];
for (int k = 1; k <= n; ++k) sum[k] = sum[k - 1] - veca[k - 1];
for (int k = 1; k <= n; ++k) {
int p = lower_bound(vecb.begin(), vecb.end(), k) - vecb.begin();
sum[k] += (p ? sumb[p - 1] : 0);
sum[k] += 1ll * k * (m - p);
}
// for (int k = 1; k <= n; ++k) printf("%lld ", sum[k]); puts("");
seg.build();
scanf("%d", &q);
for (int j = 1; j <= q; ++j) {
int op, i; scanf("%d%d", &op, &i);
if (op == 1 || op == 2) {
A.erase(make_pair(-a[i], i));
if (op == 1) ++a[i];
else --a[i];
A.insert(make_pair(-a[i], i));
int k = A.order_of_key(make_pair(-a[i], i)) + 1;
if (op == 1) seg.update(k, n, -1);
else seg.update(k, n, 1);
}
else {
if (op == 3) {
++b[i];
if (max(b[i], 1) <= n) seg.update(max(b[i], 1), n, 1);
}
else {
if (max(b[i], 1) <= n) seg.update(max(b[i], 1), n, -1);
--b[i];
}
}
int res = seg.dat[1];
if (res >= 0) puts("1");
else puts("0");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11944kb
input:
5 5 1 5 2 4 3 3 3 3 3 3 5 4 2 3 5 2 2 1 1 1 4
output:
0 1 1 1 0
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 2ms
memory: 12196kb
input:
100 100 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 13 1...
output:
1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 100 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 11972kb
input:
100 100 42 28 42 64 42 29 72 64 72 29 28 72 28 72 29 42 64 42 72 29 64 29 72 28 42 64 72 64 28 42 72 42 29 64 72 64 72 29 72 29 64 42 64 72 29 28 42 64 72 64 72 28 42 64 64 42 64 64 28 28 72 29 28 64 28 64 64 72 64 28 42 29 64 42 64 42 72 64 64 64 28 64 42 72 64 29 64 29 64 64 72 29 29 28 42 72 64 7...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 100 lines
Test #4:
score: 0
Accepted
time: 2ms
memory: 11892kb
input:
100 100 13 40 46 59 64 64 3 34 64 13 46 13 13 46 46 16 64 48 26 13 59 50 16 46 41 5 59 13 64 16 20 43 41 26 14 16 34 64 59 41 73 71 64 50 14 48 71 50 71 26 43 59 5 50 16 71 77 77 59 14 3 41 71 7 41 40 16 13 50 13 64 64 16 59 40 5 26 50 64 59 3 5 40 41 16 5 13 46 40 14 40 34 40 59 46 14 26 41 43 64 2...
output:
1 0 1 1 0 1 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 100 lines
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 14000kb
input:
100 100 69 81 86 84 48 31 42 27 14 18 7 8 61 41 97 9 38 88 24 48 52 92 60 28 18 61 51 64 98 9 72 13 35 97 32 8 17 79 54 5 100 1 76 21 11 12 52 5 98 25 61 37 82 4 18 22 96 10 23 68 92 63 40 25 27 67 39 36 44 82 6 31 17 3 7 90 21 80 62 9 73 26 75 57 20 20 86 35 46 45 89 40 18 43 16 68 4 6 89 75 37 1 7...
output:
0 1 0 1 1 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
result:
wrong answer 83rd lines differ - expected: '1', found: '0'