QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#143236#6754. SelectionKidding_MaAC ✓2ms3600kbC++206.3kb2023-08-20 22:43:302023-08-20 22:43:32

Judging History

你现在查看的是最新测评结果

  • [2023-08-20 22:43:32]
  • 评测
  • 测评结果:AC
  • 用时:2ms
  • 内存:3600kb
  • [2023-08-20 22:43:30]
  • 提交

answer

#include "bits/stdc++.h"

using namespace std;
using i64 = long long;
using i128 = __int128;

namespace cpstd {
#define range(a) begin(a), end(a)

template <class T>
T max(const vector<T> &a) {
    return *std::max_element(a.begin(), a.end());
}

template <class T>
T min(const vector<T> &a) {
    return *std::min_element(a.begin(), a.end());
}

template <class T>
struct Fenwick {
    int n;
    std::vector<T> a;
    Fenwick(const int &n = 0) : n(n), a(n, T()) {}
    void modify(int i, T x) {
        for (i++; i <= n; i += i & -i) {
            a[i - 1] += x;
        }
    }
    T get(int i) {
        T res = T();
        for (; i > 0; i -= i & -i) {
            res += a[i - 1];
        }
        return res;
    }
    T sum(int l, int r) { // [l, r)
        return get(r) - get(l);
    }
    T kth(T k) {
        int x = 0;
        for (int i = 1 << std::__lg(n); i; i >>= 1) {
            if (x + i <= n && k >= a[x + i - 1]) {
                x += i;
                k -= a[x - 1];
            }
        }
        return x;
    }
};

template <class T>
T exgcd(T a, T b, T &x, T &y) {
    if (!b) {
        x = 1, y = 0;
        return a;
    }
    T g = exgcd(b, a % b, y, x);
    y -= a / b * x;
    return g;
}

template <class T>
T floor_sum(T n, T m, T a, T b) {
    T ans = 0;
    if (a < 0) {
        T a2 = (a % m + m) % m;
        ans -= n * (n - 1) / 2 * ((a2 - a) / m);
        a = a2;
    }
    if (b < 0) {
        T b2 = (b % m + m) % m;
        ans -= n * ((b2 - b) / m);
        b = b2;
    }
    while (1) {
        if (a >= m) {
            ans += n * (n - 1) / 2 * (a / m);
            a %= m;
        }
        if (b >= m) {
            ans += n * (b / m);
            b %= m;
        }
        T y_max = a * n + b;
        if (y_max < m) {
            break;
        }
        n = y_max / m;
        b = y_max % m;
        swap(m, a);
    }
    return ans;
}

template <class T, class U1, class U2>
T power(T a, U1 b, U2 p) {
    T res = 1;
    for (; b; b >>= 1, a = a * a % p) {
        if (b & 1) {
            res = res * a % p;
        }
    }
    return res;
}

template <class T, class U>
T power(T a, U b) {
    T res = 1;
    for (; b; b >>= 1, a = a * a) {
        if (b & 1) {
            res = res * a;
        }
    }
    return res;
}

__int128 abs(const __int128 &v) {
    return (v < 0 ? -v : v);
}

std::mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());

istream &operator>>(istream &is, __int128 &v) {
    std::string s;
    is >> s;
    v = 0;
    for (auto &si : s) {
        v = v * 10 + si - '0';
    }
    return is;
}

ostream &operator<<(ostream &os, const __int128 &v) {
    if (v <= 1000000000000000000) {
        return os << (long long) (v);
    }
    return os << (long long) (v / 1000000000000000000) << std::setw(18) << std::setfill('0') << (long long) (v % 1000000000000000000);
}

template <class T>
T crt(const vector<T> &r, const vector<T> &m) {
    int n = r.size();
    T r0 = 0, m0 = 1;
    for (int i = 0; i < n; i++) {
        T m1 = m[i];
        T r1 = r[i] % m1;
        if (r1 < 0) {
            r1 += m1;
        }
        if (m0 < m1) {
            std::swap(r0, r1);
            std::swap(m0, m1);
        }
        if (!(m0 % m1)) {
            if (r0 % m1 != r1) {
                return -1;
            }
            continue;
        }
        T x, y;
        T g = exgcd(m0, m1, x, y);
        if ((r1 - r0) % g) {
            return -1;
        }
        T u1 = m1 / g;
        r0 += (r1 - r0) / g % u1 * x % u1 * m0;
        m0 *= u1;
        if (r0 < 0) {
            r0 += m0;
        }
    }
    return r0;
}

constexpr int B = 777;
constexpr long long P = 100000000000031;

long long *p;

void initHash(int N) {
    p = new long long [N + 1];
    for (int i = 0; i <= N; i++) {
        p[i] = 0;
    }
    p[0] = 1;
    for (int i = 1; i <= N; i++) {
        p[i] = p[i - 1] * B % P;
    }
}

struct StringHash {
    std::vector<long long> h;
    StringHash() : h(1) {}
    void push_back(char ch) {
        h.push_back((h.back() * B + ch) % P);
    }
    long long get(int l, int r) { // [l, r)
        return (h[r] + __int128(h[l]) * (P - p[r - l])) % P;
    }
};

struct UnionFind {
    int n;
    std::vector<int> f, sz;
    UnionFind(const int &n = 0) : n(n), f(n), sz(n, 1) {
        std::iota(f.begin(), f.end(), 0);
    }
    int get(int x) {
        while (x != f[x]) {
            x = f[x] = f[f[x]];
        }
        return x;
    }
    bool unite(int x, int y) {
        x = get(x), y = get(y);
        if (x != y) {
            f[y] = x;
            sz[x] += sz[y];
            return 1;
        }
        return 0;
    }
    bool united(int x, int y) {
        return get(x) == get(y);
    }
    int size(int x) {
        x = get(x);
        return sz[x];
    }
};
}

using namespace cpstd;

void solve() {
    
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, q;
    cin >> n >> m >> q;
    vector<array<int, 2>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i][0] >> a[i][1];
    }
    while (q--) {
        int o;
        cin >> o;
        if (o == 1) {
            int x, y;
            cin >> x >> y;
            x--;
            a[x][1] = y;
        } else {
            int x;
            cin >> x;
            x--;
            int ok = 0;
            int mx = 0;
            for (int i = 0; i < n; i++) {
                if (a[i][1] == 1) {
                    ok = 1;
                    mx = max(mx, a[i][0]);
                }
            }
            if (a[x][0] == mx && a[x][1] == 1) {
                cout << "1\n";
            } else {
                int tm = m;
                if (ok) {
                    tm = m - 1;
                }
                for (int i = 0; i < n; i++) {
                    if (ok && a[i][0] == mx && a[i][1] == 1) {
                        continue;
                    }
                    if (i != x) {
                        if (a[i][0] > a[x][0]) {
                            tm--;
                        }
                    }
                }
                cout << (tm >= 1 ? 1 : 0) << '\n';  
            }

        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3520kb

input:

3 2 3
3 0
1 1
2 0
2 2
1 2 0
2 2

output:

1
0

result:

ok 2 number(s): "1 0"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3488kb

input:

1000 1 1000
617 0
199 0
776 0
536 1
258 0
311 1
579 0
844 0
356 1
587 0
564 0
782 0
37 1
717 1
612 1
245 1
444 1
750 0
52 1
92 1
741 0
266 1
71 1
189 1
419 1
580 1
585 1
268 1
255 0
490 1
70 1
497 1
829 1
469 1
641 0
929 1
379 1
507 0
474 1
407 0
221 1
985 0
815 1
217 0
445 1
386 0
132 0
154 0
736 1...

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

result:

ok 470 numbers

Test #3:

score: 0
Accepted
time: 2ms
memory: 3552kb

input:

1000 1 1000
541 1
236 1
583 1
99 0
324 0
107 0
459 0
854 0
772 0
426 1
717 1
806 0
335 0
503 0
860 0
463 1
306 1
813 0
947 1
989 0
736 1
713 0
65 1
222 0
428 0
680 0
652 1
681 1
661 0
595 1
474 1
70 1
641 1
688 0
591 0
20 1
330 1
563 0
38 1
638 1
391 1
979 1
488 0
829 0
956 1
395 1
694 0
669 0
567 0...

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 516 numbers

Test #4:

score: 0
Accepted
time: 2ms
memory: 3600kb

input:

1000 50 1000
950 0
163 0
276 0
422 1
449 0
81 0
245 1
995 1
908 1
466 0
123 0
848 1
749 0
370 1
86 1
299 1
384 0
570 1
678 0
713 0
360 0
737 0
627 0
60 1
250 1
88 1
915 1
145 0
863 0
925 1
742 0
409 1
858 1
441 0
803 0
811 1
575 0
47 0
271 1
107 1
431 0
677 1
704 0
340 0
160 0
856 1
176 0
488 1
832 ...

output:

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

result:

ok 511 numbers

Test #5:

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

input:

1000 1 1000
900 1
127 1
89 1
836 1
434 1
912 1
459 0
155 1
394 0
669 1
33 1
584 0
80 0
433 1
284 1
43 0
377 0
84 1
91 1
158 0
406 1
654 0
604 0
469 1
352 1
762 1
824 0
423 1
172 0
62 1
399 0
130 1
19 1
640 1
212 0
215 0
661 0
597 0
309 1
688 1
978 0
677 0
170 0
853 1
448 1
945 1
765 0
751 0
830 0
25...

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

result:

ok 467 numbers

Test #6:

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

input:

1000 10 1000
135 1
844 1
342 0
548 0
385 0
595 1
271 1
189 0
685 0
951 0
586 0
132 0
537 0
99 1
828 1
676 1
407 1
20 0
297 0
91 1
336 1
113 0
370 1
498 0
201 1
866 1
64 0
443 0
852 0
46 0
51 0
146 1
650 1
60 0
349 0
773 1
556 0
219 1
526 1
659 1
913 1
260 1
186 0
787 0
130 1
669 0
307 1
105 1
316 1
...

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

result:

ok 488 numbers