QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#373175#8311. Game on Sequencekevinyang#AC ✓299ms6324kbC++207.9kb2024-04-01 05:34:252024-04-01 05:34:26

Judging History

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

  • [2024-04-01 05:34:26]
  • 评测
  • 测评结果:AC
  • 用时:299ms
  • 内存:6324kb
  • [2024-04-01 05:34:25]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

/* Macros {{{ */
/*  A lot of this is from some of Benq's submissions
    [https://codeforces.com/profile/Benq]
    Ugly af to the eyes, but with vim fold its barable
    Hopefully c++20 concepts can make all this stuff must cleaner */

/* Basics {{{ */
using ll = long long;
using ld = long double;
using str = string;

using pi = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
#define mp make_pair
#define fi first
#define se second

#define arr array
#define ve vector
using vi = vector<int>;
using vll = vector<ll>;
using vld = vector<ld>;

using vpi = vector<pi>;
using vpll = vector<pll>;
using vpld = vector<pld>;

using vvi = vector<vi>;
using vvll = vector<vll>;
using vvld = vector<vld>;

using vvpi = vector<vpi>;
using vvpll = vector<vpll>;
using vvpld = vector<vpld>;

#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz size()
#define rsz(a) resize(a)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

#define For(i, a, b) for (int i = a; i < b; ++i)
#define Rof(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define rep(a) For(_, 0, a)
#define each(a, x) for (auto &a : x)
#define reach(a, x) for (auto a = x.rbegin(); a != x.rend(); ++a)

template <typename T, typename U>
inline void cmin(T &x, U y) {
    if (y < x) x = y;
}
template <typename T, typename U>
inline void cmax(T &x, U y) {
    if (x < y) x = y;
}
/*}}}*/

/* IO {{{ */

/* Template Macros {{{ */
#define tcT template <class T
#define tcTU tcT, class U
#define tcTUU tcT, class... U
/*}}}*/

inline namespace Helpers { /*{{{*/
tcT, class = void > struct is_iterable : false_type {};
tcT > struct is_iterable<
          T, void_t<decltype(begin(declval<T>())), decltype(end(declval<T>()))>>
    : true_type {};
tcT > constexpr bool is_iterable_v = is_iterable<T>::value;

tcT, class = void > struct is_readable : false_type {};
tcT > struct is_readable<T, typename std::enable_if_t<is_same_v<
                                decltype(cin >> declval<T &>()), istream &>>>
    : true_type {};
tcT > constexpr bool is_readable_v = is_readable<T>::value;

tcT, class = void > struct is_printable : false_type {};
tcT > struct is_printable<T, typename std::enable_if_t<is_same_v<
                                 decltype(cout << declval<T>()), ostream &>>>
    : true_type {};
tcT > constexpr bool is_printable_v = is_printable<T>::value;
} /* namespace Helpers */
/*}}}*/

inline namespace Input { /*{{{*/
tcT > constexpr bool needs_input_v = !is_readable_v<T> && is_iterable_v<T>;
tcTUU > void re(T &t, U &...u);
tcTU > void re(pair<T, U> &p); /* pairs */

/* re: read{{{ */
tcT > typename enable_if<is_readable_v<T>, void>::type re(T &x) {
    cin >> x;
} /* default */
tcT > typename enable_if<needs_input_v<T>, void>::type re(
          T &i);                                   // vectors, arrays, etc...
tcTU > void re(pair<T, U> &p) { re(p.fi, p.se); }  // pairs
tcT > typename enable_if<needs_input_v<T>, void>::type re(T &i) {
    each(x, i) re(x);
}
tcTUU > void re(T &t, U &...u) {
    re(t);
    re(u...);
} /* read multiple}}} */

/* rv: resize and read vectors{{{ */
void rv(size_t) {}
tcTUU > void rv(size_t N, ve<T> &t, U &...u);
template <class... U>
void rv(size_t, size_t N2, U &...u);
tcTUU > void rv(size_t N, ve<T> &t, U &...u) {
    t.rsz(N);
    re(t);
    rv(N, u...);
}
template <class... U>
void rv(size_t, size_t N2, U &...u) {
    rv(N2, u...);
} /*}}}*/

/* dumb shortcuts to read in ints{{{ */
void decrement() {} /* subtract one from each */
tcTUU > void decrement(T &t, U &...u) {
    --t;
    decrement(u...);
}
#define ints(...)    \
    int __VA_ARGS__; \
    re(__VA_ARGS__);
#define int1(...)      \
    ints(__VA_ARGS__); \
    decrement(__VA_ARGS__); /*}}}*/
} /* namespace Input */
/*}}}*/

inline namespace ToString { /*{{{*/
tcT > constexpr bool needs_output_v = !is_printable_v<T> && is_iterable_v<T>;

/* ts: string representation to print */
tcT > typename enable_if<is_printable_v<T>, str>::type ts(T v) {
    stringstream ss;
    ss << fixed << setprecision(15) << v;
    return ss.str();
} /* default */
tcT > str bit_vec(T t) { /* bit vector to string */
    str res = "{";
    For(i, 0, t.sz) res += ts(t[i]);
    res += "}";
    return res;
}
str ts(ve<bool> v) { return bit_vec(v); }
template <size_t SZ>
str ts(bitset<SZ> b) {
    return bit_vec(b);
} /* bit vector */
tcTU > str ts(pair<T, U> p); /* pairs */
tcT > typename enable_if<needs_output_v<T>, str>::type ts(
          T v); /* vectors, arrays */
tcTU > str ts(pair<T, U> p) { return "(" + ts(p.fi) + ", " + ts(p.se) + ")"; }
tcT > typename enable_if<is_iterable_v<T>, str>::type ts_sep(T v, str sep) {
    /* convert container to string w/ separator sep */
    bool fst = 1;
    str res = "";
    for (const auto &x : v) {
        if (!fst) res += sep;
        fst = 0;
        res += ts(x);
    }
    return res;
}
tcT > typename enable_if<needs_output_v<T>, str>::type ts(T v) {
    return "{" + ts_sep(v, ", ") + "}";
}

/* for nested DS */
template <int, class T>
typename enable_if<!needs_output_v<T>, ve<str>>::type ts_lev(const T &v) {
    return {ts(v)};
}
template <int lev, class T>
typename enable_if<needs_output_v<T>, ve<str>>::type ts_lev(const T &v) {
    if (lev == 0 || !v.sz) return {ts(v)};
    ve<str> res;
    for (const auto &t : v) {
        if (res.sz) res.back() += ",";
        ve<str> tmp = ts_lev<lev - 1>(t);
        res.insert(end(res), all(tmp));
    }
    For(i, 0, res.sz) {
        str bef = " ";
        if (i == 0) bef = "{";
        res[i] = bef + res[i];
    }
    res.back() += "}";
    return res;
}
} /* namespace ToString */
/*}}}*/

inline namespace Output { /*{{{*/
template <class T>
void pr_sep(ostream &os, str, const T &t) {
    os << ts(t);
}
template <class T, class... U>
void pr_sep(ostream &os, str sep, const T &t, const U &...u) {
    pr_sep(os, sep, t);
    os << sep;
    pr_sep(os, sep, u...);
}
/* print w/ no spaces */
template <class... T>
void pr(const T &...t) {
    pr_sep(cout, "", t...);
}
/* print w/ spaces, end with newline */
void ps() { cout << "\n"; }
template <class... T>
void ps(const T &...t) {
    pr_sep(cout, " ", t...);
    ps();
}
/* debug to cerr */
template <class... T>
void dbg_out(const T &...t) {
    pr_sep(cerr, " | ", t...);
    cerr << endl;
}
void loc_info(int line, str names) {
    cerr << "Line(" << line << ") -> [" << names << "]: ";
}
template <int lev, class T>
void dbgl_out(const T &t) {
    cerr << "\n\n" << ts_sep(ts_lev<lev>(t), "\n") << "\n" << endl;
}
} /* namespace Output */
/*}}}}}}}}}*/

int const V=256, K=8, NM=4e5+100;

int n, m;
vi a;
vpi quer;
vi lst;


// always optimal to go to the last index containing the specific value


int can_win(int i) {
    int res = 0;

    if(i != lst[a[i]]) res |= (1^can_win(lst[a[i]]));

    for(int k=0; k<K; ++k) if(i < (lst[a[i] ^ (1<<k)])) res |= (1^can_win(lst[a[i] ^ (1<<k)]));

    return res;
}


void solve() {
    re(n, m), rv(n, a), rv(m, quer);

    lst.assign(V, -1);
    for(int i=0; i<n; ++i) lst[a[i]] = i;

    for(auto [op, k] : quer) {
        if(op == 1) {
            int i = a.size();
            a.pb(k);
            lst[a[i]] = i;
        } else if(op == 2) {
            int res = can_win(k-1);
            ps(res ? "Grammy" : "Alice");
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    /* cout << fixed << setprecision(6); */
    int t = 1;
    // cin >> t;
    for (int i = 0; i < t; i++) solve();

    return 0;
    // you should actually read the stuff at the bottom
}

/* stuff you should look for
 * int overflow, array bounds
 * special cases (n=1?)
 * do smth instead of nothing and stay organized
 * WRITE STUFF DOWN
 * DON'T GET STUCK ON ONE APPROACH
 */

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 5
1 2 3 4 5
1 6
2 5
1 7
2 5
2 1

output:

Alice
Grammy
Alice

result:

ok 3 lines

Test #2:

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

input:

10 10
12 114 132 7 133 53 128 159 34 92
2 5
1 254
2 3
2 11
1 92
2 11
1 33
1 230
1 181
2 11

output:

Alice
Grammy
Alice
Alice
Alice

result:

ok 5 lines

Test #3:

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

input:

100 100
57 58 24 217 80 0 241 175 19 138 231 17 8 19 22 100 133 205 178 67 55 92 127 254 156 89 87 22 136 208 168 195 164 194 243 110 234 164 78 55 43 223 227 112 137 78 111 31 253 194 196 128 210 129 71 129 40 195 114 69 114 52 83 162 248 117 12 162 86 155 81 6 251 174 237 190 171 44 61 114 254 131...

output:

Grammy
Grammy
Alice
Alice
Grammy
Grammy
Alice
Alice
Grammy
Alice
Grammy
Grammy
Grammy
Alice
Grammy
Alice
Alice
Alice
Alice
Grammy
Alice
Grammy
Alice
Grammy
Alice
Grammy
Grammy
Alice
Grammy
Grammy
Alice
Alice
Grammy
Grammy
Grammy
Alice
Alice
Grammy
Alice
Grammy
Grammy
Grammy
Grammy
Alice
Grammy
Grammy

result:

ok 46 lines

Test #4:

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

input:

200 200
56 236 246 71 3 39 174 73 229 150 161 184 163 240 96 38 57 65 238 184 84 105 70 169 217 155 211 197 92 224 245 239 170 146 131 155 63 225 68 84 208 81 117 55 195 58 70 118 178 71 93 215 236 248 81 51 244 32 48 247 0 103 249 166 123 200 35 84 131 20 21 45 108 110 171 236 59 206 184 100 43 126...

output:

Grammy
Alice
Alice
Grammy
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Alice
Grammy
Alice
Alice
Grammy
Grammy
Alice
Alice
Grammy
Grammy
Alice
Grammy
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Alice
Alice
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Alice...

result:

ok 101 lines

Test #5:

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

input:

300 300
54 158 213 181 183 78 108 227 182 162 92 95 62 204 169 232 236 181 43 45 114 118 12 84 21 222 78 116 48 240 67 26 175 97 19 200 149 30 57 113 118 196 6 255 253 38 29 206 104 203 245 46 7 110 91 228 192 124 237 169 142 153 159 170 253 27 58 6 176 141 216 84 220 46 106 26 202 112 50 87 89 121 ...

output:

Grammy
Grammy
Grammy
Alice
Alice
Alice
Alice
Grammy
Alice
Grammy
Alice
Grammy
Grammy
Grammy
Alice
Grammy
Grammy
Grammy
Alice
Grammy
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Alice
Grammy
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Alice
Grammy
Alice
Alice
Grammy...

result:

ok 155 lines

Test #6:

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

input:

1000 1000
88 174 158 173 160 193 246 152 104 28 88 9 127 191 219 89 232 253 13 117 89 254 110 96 189 62 243 175 178 12 132 11 12 12 126 179 80 182 49 247 58 213 98 190 55 8 203 1 235 68 151 77 173 80 230 69 6 71 79 30 54 26 89 34 175 12 0 46 152 52 55 51 75 254 96 184 215 170 213 86 126 204 99 59 56...

output:

Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Alice
Grammy
Alice
Grammy
Grammy
Alice
Alice
Grammy
Grammy
Grammy
Alice
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Alice
Grammy
Grammy
Grammy
Grammy
Alice
Grammy
Grammy
Alice
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Alice
Alice
Alic...

result:

ok 506 lines

Test #7:

score: 0
Accepted
time: 26ms
memory: 3932kb

input:

20000 20000
57 18 228 217 20 96 113 67 96 16 189 26 199 140 91 192 101 209 147 110 74 241 221 175 252 145 106 227 242 107 155 189 26 205 135 197 84 25 122 215 244 67 112 163 68 86 158 43 255 239 234 71 216 192 110 36 241 15 249 193 100 52 141 112 190 30 226 91 126 207 226 253 155 219 43 165 251 237 ...

output:

Grammy
Grammy
Grammy
Alice
Alice
Grammy
Grammy
Grammy
Grammy
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Gram...

result:

ok 9915 lines

Test #8:

score: 0
Accepted
time: 299ms
memory: 6240kb

input:

200000 200000
38 224 25 219 240 25 127 46 150 104 78 69 165 37 77 64 192 217 151 179 28 196 29 40 3 88 34 155 81 187 189 252 250 73 90 176 130 16 57 17 131 83 238 233 43 8 223 251 187 90 202 122 9 39 60 144 255 130 26 217 26 50 28 229 235 50 77 185 153 47 141 78 94 13 15 17 6 98 219 98 115 250 77 21...

output:

Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Alice
Grammy
Grammy
Grammy
Alice
Grammy
Grammy
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Alice
Grammy
Grammy
Grammy
Grammy
Alice
Grammy
Grammy
Alice
Alice
Grammy
Alice
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
G...

result:

ok 99929 lines

Test #9:

score: 0
Accepted
time: 267ms
memory: 5420kb

input:

1 200000
178
2 1
2 1
1 43
2 2
2 1
1 210
2 1
1 110
2 3
1 37
1 170
2 1
1 161
2 5
1 243
2 4
2 7
2 1
1 245
2 4
1 254
2 7
2 3
2 8
1 24
1 195
1 74
2 10
2 10
2 10
1 104
1 122
2 9
1 206
2 16
2 16
1 38
1 111
1 192
2 13
2 16
2 11
1 53
2 19
2 16
1 23
1 60
2 16
1 159
2 20
2 14
2 3
1 153
2 4
2 5
2 9
2 18
1 202
2...

output:

Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Grammy
Grammy
Alice
Alice
Alice
Alice
Alice
Grammy
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Alice
Grammy
Alice
Grammy
A...

result:

ok 100023 lines

Test #10:

score: 0
Accepted
time: 6ms
memory: 3844kb

input:

200000 1
61 83 233 161 113 83 59 13 165 46 90 65 231 185 141 221 88 1 112 246 174 195 114 148 179 242 86 52 195 52 182 70 82 102 123 176 100 20 102 73 19 1 139 95 13 165 208 50 20 170 115 118 124 111 129 213 176 133 96 107 173 52 70 72 132 247 191 242 221 252 43 224 111 165 61 0 137 9 125 49 140 115...

output:

Grammy

result:

ok single line: 'Grammy'

Test #11:

score: 0
Accepted
time: 277ms
memory: 5528kb

input:

100000 200000
189 101 194 145 97 254 75 51 137 14 5 232 78 247 155 244 16 253 64 188 242 199 40 73 92 226 12 204 121 62 170 20 183 175 67 25 73 109 28 117 168 148 253 230 14 165 181 206 249 4 147 179 174 119 239 191 180 173 159 64 85 181 130 41 32 131 249 144 106 110 104 46 200 181 186 226 150 245 2...

output:

Grammy
Grammy
Grammy
Alice
Grammy
Alice
Grammy
Grammy
Grammy
Alice
Grammy
Alice
Grammy
Grammy
Alice
Grammy
Grammy
Grammy
Alice
Grammy
Alice
Grammy
Grammy
Alice
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Alice
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Ali...

result:

ok 100006 lines

Test #12:

score: 0
Accepted
time: 290ms
memory: 6324kb

input:

200000 200000
109 183 127 127 150 131 50 33 108 121 94 117 193 9 214 187 138 101 212 57 97 6 115 185 6 37 52 6 218 67 122 115 98 161 14 83 202 201 155 130 95 3 51 218 20 225 200 191 254 180 180 148 216 19 50 68 128 91 226 186 120 42 73 104 102 228 78 196 148 46 191 199 112 118 202 108 13 104 132 55 ...

output:

Alice
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Alice
Grammy
Alice
Grammy
Grammy
Alice
Alice
Alice
Alice
Grammy
Grammy
Grammy
Grammy
Alice
Grammy
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Alice
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Alic...

result:

ok 100100 lines

Test #13:

score: 0
Accepted
time: 287ms
memory: 6240kb

input:

200000 200000
205 228 201 164 156 188 1 149 120 47 53 52 91 74 105 168 244 236 150 42 38 72 41 136 135 101 129 163 226 161 116 241 181 42 202 252 180 132 193 224 68 6 136 209 1 92 196 147 56 6 13 0 109 216 114 134 215 120 241 166 223 228 0 118 165 233 7 32 123 172 227 97 103 37 101 11 165 159 209 13...

output:

Grammy
Alice
Grammy
Grammy
Grammy
Alice
Grammy
Grammy
Grammy
Alice
Grammy
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Alice
Grammy
Grammy
Grammy
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Alice
Grammy
Grammy
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Alice
Grammy
G...

result:

ok 100026 lines

Test #14:

score: 0
Accepted
time: 281ms
memory: 6308kb

input:

200000 200000
45 16 19 202 162 245 209 9 131 230 13 244 245 139 252 149 95 114 88 27 234 137 222 87 8 166 206 64 234 255 110 111 8 178 135 164 158 62 230 63 41 8 221 199 237 216 191 103 114 89 103 108 3 156 178 200 46 149 0 146 70 157 183 132 228 238 192 124 98 42 8 251 95 213 0 169 62 214 30 207 16...

output:

Grammy
Grammy
Grammy
Alice
Grammy
Grammy
Grammy
Grammy
Alice
Alice
Grammy
Alice
Alice
Alice
Alice
Grammy
Alice
Grammy
Grammy
Grammy
Grammy
Alice
Alice
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Alice
Alice
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Grammy
Alice
Alice
Grammy
Grammy
Grammy
Grammy
...

result:

ok 100127 lines

Extra Test:

score: 0
Extra Test Passed