QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#880854#3299. Advertisement MatchingNianFengWA 75ms24240kbC++145.2kb2025-02-03 21:41:202025-02-03 21:41:20

Judging History

This is the latest submission verdict.

  • [2025-02-03 21:41:20]
  • Judged
  • Verdict: WA
  • Time: 75ms
  • Memory: 24240kb
  • [2025-02-03 21:41:20]
  • Submitted

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(rs);
      _build(ls);
      
      _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; }

#ifdef DEBUG
   i64 query(int pos) {
      static int rt, l, r;

      for (rt = 1, l = 0, r = n; l < r; ) {
         _pushDown(rt);

         if (pos <= mid)
            rt = lc, r = mid;
         else
            rt = rc, l = mid + 1;
      }

      return _tr[rt].mn;
   }
#endif
} 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
      std::cerr << tr.query() << ' ' << s << std::endl;

      std::cerr << tr.query(5) << std::endl;
#endif
   }

#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: 11856kb

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: 11720kb

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: 11856kb

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: 0ms
memory: 11848kb

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: 0
Accepted
time: 0ms
memory: 11848kb

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

result:

ok 100 lines

Test #6:

score: 0
Accepted
time: 1ms
memory: 11848kb

input:

1000 1000
885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 885 88...

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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 1000 lines

Test #7:

score: 0
Accepted
time: 0ms
memory: 11640kb

input:

1000 1000
499 499 499 499 917 670 499 499 947 670 917 670 917 917 917 670 556 556 947 499 670 947 556 670 499 947 556 917 947 499 556 947 556 499 670 947 947 670 947 556 499 917 670 556 556 917 947 499 947 670 947 917 670 917 556 499 670 947 556 947 499 670 947 947 947 917 556 556 670 499 499 917 55...

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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 1000 lines

Test #8:

score: 0
Accepted
time: 0ms
memory: 11852kb

input:

1000 1000
16 517 918 174 148 253 293 596 438 217 566 362 984 507 690 320 253 144 971 74 157 981 547 802 39 765 264 771 846 745 539 906 743 39 242 266 568 660 118 352 509 278 500 481 929 502 375 315 599 756 217 159 606 39 967 50 145 863 412 7 780 320 745 942 99 52 510 560 184 669 596 50 477 236 7 507...

output:

1
0
1
0
0
0
0
0
0
0
0
0
0
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
0
0
1
1
1
1
1
1
0
0
0
0
0
0
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 1000 lines

Test #9:

score: 0
Accepted
time: 0ms
memory: 11852kb

input:

1000 1000
397 930 346 818 646 400 677 961 999 158 382 242 136 712 460 432 622 282 297 428 708 432 100 768 51 140 776 934 479 531 307 542 498 520 961 155 984 664 45 398 831 581 638 130 248 476 88 238 584 959 838 270 574 402 248 267 562 281 839 422 528 729 299 809 562 723 93 102 371 46 173 13 500 313 ...

output:

1
1
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 1000 lines

Test #10:

score: 0
Accepted
time: 63ms
memory: 24240kb

input:

250000 250000
505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 505 50...

output:

0
0
0
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
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
0
0
0
0
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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 250000 lines

Test #11:

score: -100
Wrong Answer
time: 75ms
memory: 24164kb

input:

250000 250000
95999 84922 84922 84922 84922 192441 95999 95999 84922 84922 157215 95999 95999 84922 84922 192441 84922 157215 95999 95999 84922 134374 134374 95999 157215 157215 157215 134374 95999 95999 192441 84922 157215 95999 134374 134374 157215 84922 84922 157215 157215 192441 157215 192441 84...

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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
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:

wrong answer 1st lines differ - expected: '1', found: '0'