QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#880819 | #3299. Advertisement Matching | NianFeng | WA | 0ms | 11852kb | C++14 | 4.8kb | 2025-02-03 21:12:03 | 2025-02-03 21:12:04 |
Judging History
answer
/* 年挽红枫,溪傍芦荻。*/
#ifdef DEBUG
#include <iostream>
#include <cmath>
#include <ctime>
bool Mbe;
void _Dihan();
#endif
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
typedef long long i64;
typedef unsigned long long ull;
typedef double f32;
typedef long double ldb;
typedef __int128 i28;
typedef unsigned uit;
template <typename T> bool chkMx(T &x, T y) { return x < y ? x = y, true : false; }
template <typename T> bool chkMn(T &x, T y) { return x > y ? x = y, true : false; }
namespace IO {
#define file(s) freopen(#s".in", "r", stdin), freopen(#s".out", "w", stdout)
constexpr int SIZE = 1 << 21;
char ibuf[SIZE], *p1 = ibuf, *p2 = ibuf, obuf[SIZE], *p3 = obuf;
#define flush() (fwrite(obuf, 1, p3 - obuf, stdout), p3 = obuf)
#define gc() (p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, SIZE, stdin), p1 == p2) ? EOF : *p1++)
#define pc(ch) (p3 == obuf + SIZE && flush(), *p3++ = ch)
class Flush { public: ~Flush() { flush(); } } _;
template <typename T> inline void read(T &x) {
static char c; static int f;
x = f = 0;
while (!isdigit(c = gc())) f |= c == '-';
while (isdigit(c)) x = x * 10 + (c ^ 48), c = gc();
f && (x = -x);
}
template <typename T> inline T read() {
T x; read(x); return x;
}
template <typename T> inline void write(T x) {
static char s[20]; static int t;
x < 0 && (pc('-'), x = -x), t = 0;
do s[++t] = x % 10 ^ 48; while (x /= 10);
while (t) pc(s[t--]);
}
inline void write(char c) { pc(c); }
template <typename T> inline void write(T *s) { while (*s) pc(*s++); }
template <typename T, typename ...Args>
inline void read(T &first, Args &...args) { read(first), read(args...); }
template <typename T, typename ...Args>
inline void write(T first, Args ...args) { write(first), write(args...); }
}
using namespace IO;
constexpr int N = 2.5e5 + 5;
int n, m, a[N], b[N], q;
int c[N], d[N];
i64 preA[N], preB[N], s;
class SegmentTree {
private:
struct Node {
i64 mn, lz;
} _tr[N << 2];
#define mid (l + r >> 1)
#define lc rt << 1
#define rc rt << 1 | 1
#define ls lc, l, mid
#define rs rc, mid + 1, r
void _pushUp(const int &rt) {
_tr[rt].mn = std::min(_tr[lc].mn, _tr[rc].mn);
}
void _lazy(const int &rt, const i64 &k) {
_tr[rt].mn += k;
_tr[rt].lz += k;
}
void _pushDown(const int &rt) {
if (!_tr[rt].lz) return;
_lazy(lc, _tr[rt].lz);
_lazy(rc, _tr[rt].lz);
_tr[rt].lz = 0;
}
void _build(const int &rt, const int &l, const int &r) {
if (l == r) {
static int p;
while (p < n && b[p + 1] < n - l) ++p;
return _tr[rt].mn = preA[l] + preB[p]
+ (n - l) * (n - p), void();
}
_build(ls);
_build(rs);
_pushUp(rt);
}
void _update(
const int &rt, const int &l, const int &r,
const int &L, const int &R, const int &k
) {
if (L <= l && r <= R) return _lazy(rt, k);
_pushDown(rt);
if (L <= mid) _update(ls, L, R, k);
if (mid < R) _update(rs, L, R, k);
_pushUp(rt);
}
public:
void build() { _build(1, 0, n); }
void update(int l, int r, int k) {
if (l > r) return;
_update(1, 0, n, l, r, k);
}
i64 query() { return _tr[1].mn; }
} tr;
int main() {
#ifdef DEBUG
file(cur);
#endif
read(n, m);
for (int i = 1; i <= n; ++i)
read(a[i]);
for (int i = 1; i <= m; ++i)
read(b[i]);
read(q);
memcpy(c + 1, a + 1, n * sizeof(int));
memcpy(d + 1, b + 1, m * sizeof(int));
std::sort(a + 1, a + n + 1);
std::sort(b + 1, b + m + 1);
for (int i = 1; i <= n; ++i)
preA[i] = preA[i - 1] + a[i];
for (int i = 1; i <= m; ++i)
preB[i] = preB[i - 1] + b[i];
tr.build(), s = preA[n];
while (q--) {
static int opt, x;
read(opt, x);
switch (opt) {
int p;
case 1:
p = std::upper_bound(a + 1, a + n + 1, c[x]) - a - 1;
++c[x], ++a[p], ++s;
tr.update(p, n, 1);
break;
case 2:
p = std::lower_bound(a + 1, a + n + 1, c[x]) - a;
--c[x], --a[p], --s;
tr.update(p, n, -1);
break;
case 3:
tr.update(0, n - d[x] - 1, 1);
++d[x];
break;
case 4:
tr.update(0, n - d[x], -1);
--d[x];
break;
}
write((char){'0' ^ (tr.query() >= s)}, '\n');
}
#ifdef DEBUG
_Dihan();
#endif
return 0;
}
#ifdef DEBUG
bool Med;
void _Dihan() {
std::cerr << "Memory: " << abs(&Med - &Mbe) / 1048576.0 << " MB\n";
std::cerr << "Time: " << 1e3 * clock() / CLOCKS_PER_SEC << " ms\n";
}
#endif
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 11812kb
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: 0ms
memory: 11784kb
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: -100
Wrong Answer
time: 0ms
memory: 11852kb
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 1 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 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0
result:
wrong answer 2nd lines differ - expected: '0', found: '1'