QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#840798#9905. 哈夫曼树SorahISA#30 217ms3876kbC++2311.5kb2025-01-03 03:24:212025-01-03 03:24:21

Judging History

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

  • [2025-01-03 03:24:21]
  • 评测
  • 测评结果:30
  • 用时:217ms
  • 内存:3876kb
  • [2025-01-03 03:24:21]
  • 提交

answer

#ifndef SorahISA
#define SorahISA
#include SorahISA __FILE__ SorahISA

void solve() {
    int N, Q; cin >> N >> Q;
    
    vector<int> A(2*N);
    for (int i = 1; i <= N; ++i) cin >> A[i];
    
    vector<array<int, 2>> ch(2*N, {0, 0});
    for (int i = N+1; i <= 2*N-1; ++i) cin >> ch[i][0] >> ch[i][1];
    
    auto chk = [&]() -> bool {
        vector<int> seq;
        for (int i = N+1; i <= 2*N-1; ++i) A[i] = A[ch[i][0]] + A[ch[i][1]], seq.eb(A[i]);
        sort(ALL(seq));
        
        vector<int> min_seq;
        prior<int> pq;
        for (int i = 1; i <= N; ++i) pq.ee(A[i]);
        while (SZ(pq) >= 2) {
            int a = pq.top(); pq.pop();
            int b = pq.top(); pq.pop();
            min_seq.eb(a + b), pq.ee(a + b);
        }
        
        return (seq == min_seq);
    };
    
    print(chk() ? "YES" : "NO");
    for (int q = 1; q <= Q-1; ++q) {
        int p, v; cin >> p >> v;
        A[p] = v;
        print(chk() ? "YES" : "NO");
    }
}

int32_t main() {
    fastIO();
    
    int t = 1; // cin >> t;
    for (int _ = 1; _ <= t; ++_) {
        // cout << "Case #" << _ << ": ";
        solve();
    }
    
    return 0;
}

#else

#ifdef local
#define _GLIBCXX_DEBUG 1
#endif
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
// #include <bits/extc++.h>
// #include <tr2/dynamic_bitset>

using i64 = long long;
using i128 = __int128;
#define int i64
using f80 = long double;
using f128 = __float128;
#define double f80
using pii = pair<int, int>;
template <typename T> using Prior = std::priority_queue<T>;
template <typename T> using prior = std::priority_queue<T, vector<T>, greater<T>>;

// #define X first
// #define Y second
#define eb emplace_back
#define ef emplace_front
#define ee emplace
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define SZ(x) ((int)(x).size())
#define popcnt(x) __builtin_popcountll(x)

// template <size_t D, typename T> struct Vec : vector<Vec<D-1, T>> {
//     static_assert(D >= 1, "Vector dimension must be greater than zero!");
//     template <typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D-1, T>>(n, Vec<D-1, T>(args...)) {}
// };

// template <typename T> struct Vec<1, T> : vector<T> {
//     Vec(int n = 0, const T& val = T()) : vector<T>(n, val) {}
// };

template <typename T> ostream& operator << (ostream &os, const vector<T> &vec)
{ for (size_t i = 0; i < size(vec); ++i) { if (i) os << " "; os << vec[i]; } return os; }

#ifdef local
#define fastIO() void()
#define debug(...) \
    _color.emplace_back("\u001b[31m"), \
    fprintf(stderr, "%sAt [%s], line %d: (%s) = ", _color.back().c_str(), __FUNCTION__, __LINE__, #__VA_ARGS__), \
    _do(__VA_ARGS__), _color.pop_back(), \
    fprintf(stderr, "%s", _color.back().c_str())
#define print(...) \
    fprintf(stdout, "%s", "\u001b[36m"), \
    _P(__VA_ARGS__), \
    fprintf(stdout, "%s", "\u001b[0m")

deque<string> _color{"\u001b[0m"};

template <typename T> concept is_string = is_same_v<T, string&> or is_same_v<T, const string&>;
template <typename T> concept is_iterable = requires (T _t) { begin(_t); };

template <typename T> inline void _print_err(T &&_t);
template <typename T> inline void _print_err(T &&_t) requires is_iterable<T> and (not is_string<T>);
template <size_t I, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(const tuple<U...> &);
template <size_t I, typename ...U> inline typename enable_if<I <  sizeof...(U), void>::type _print_err(const tuple<U...> &_t);
template <size_t I, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(tuple<U...> &);
template <size_t I, typename ...U> inline typename enable_if<I <  sizeof...(U), void>::type _print_err(tuple<U...> &_t);
template <typename T, typename U> ostream& operator << (ostream &os, const pair<T, U> &_tu);

inline void _do() { cerr << "\n"; }
template <typename T> inline void _do(T &&_t) { _print_err(_t), cerr << "\n"; }
template <typename T, typename ...U> inline void _do(T &&_t, U &&..._u) { _print_err(_t), cerr << ", ", _do(_u...); }
#else
#define fastIO() cin.tie(0)->sync_with_stdio(0)
#define debug(...) void()
#define print(...) _P(__VA_ARGS__)
#endif

inline void _P() { cout << "\n"; }
template <typename T> inline void _P(T &&_t) { cout << _t << "\n"; }
template <typename T, typename ...U> inline void _P(T &&_t, U &&..._u) { cout << _t << " ", _P(_u...); }

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

inline int getRand(int L, int R) {
    if (L > R) swap(L, R);
    return (int)(rng() % ((uint64_t)R - L + 1) + L);
}

template <typename T, typename U> bool chmin(T &lhs, U rhs) { return lhs > rhs ? lhs = rhs, 1 : 0; }
template <typename T, typename U> bool chmax(T &lhs, U rhs) { return lhs < rhs ? lhs = rhs, 1 : 0; }

template <typename T> void make_unique(vector<T> &vec) {
    if (not is_sorted(ALL(vec))) sort(ALL(vec));
    vec.erase(unique(ALL(vec)), end(vec));
}

/// below are Fast I/O and _print_err templates ///

/*
/// Fast I/O by FHVirus ///
/// https://fhvirus.github.io/blog/2020/fhvirus-io/ ///

#include <unistd.h>

const int S = 65536;

int OP = 0;
char OB[S];

inline char RC() {
    static char buf[S], *p = buf, *q = buf;
    return p == q and (q = (p = buf) + read(0, buf, S)) == buf ? -1 : *p++;
}

inline int RI() {
    static char c;
    int a;
    while (((c = RC()) < '0' or c > '9') and c != '-' and c != -1);
    if (c == '-') {
        a = 0;
        while ((c = RC()) >= '0' and c <= '9') a *= 10, a -= c ^ '0';
    }
    else {
        a = c ^ '0';
        while ((c = RC()) >= '0' and c <= '9') a *= 10, a += c ^ '0';
    }
    return a;
}

inline void WI(int n, char c = '\n') {
    static char buf[20], p;
    if (n == 0) OB[OP++] = '0';
    p = 0;
    if (n < 0) {
        OB[OP++] = '-';
        while (n) buf[p++] = '0' - (n % 10), n /= 10;
    }
    else {
        while (n) buf[p++] = '0' + (n % 10), n /= 10;
    }
    for (--p; p >= 0; --p) OB[OP++] = buf[p];
    OB[OP++] = c;
    if (OP > S-20) write(1, OB, OP), OP = 0;
}

/// Fast I/O by FHVirus ///
/// https://fhvirus.github.io/blog/2020/fhvirus-io/ ///
*/

#ifdef local

template <typename T> inline void _print_err(T &&_t) { cerr << _t; }

template <typename T> inline void _print_err(T &&_t) requires is_iterable<T> and (not is_string<T>) {
    _color.emplace_back(_color.back()), ++_color.back()[3];
    cerr << _color.back() << "[";
    for (bool _first = true; auto &_x : _t) {
        if (!_first) cerr << ", ";
        _print_err(_x), _first = false;
    }
    cerr << "]" << (_color.pop_back(), _color.back());
}

template <typename T, typename U> ostream& operator << (ostream &os, const pair<T, U> &_tu) {
    _color.emplace_back(_color.back()), ++_color.back()[3];
    cerr << _color.back() << "(";
    _print_err(_tu.first), cerr << ", ", _print_err(_tu.second);
    cerr << ")" << (_color.pop_back(), _color.back());
    return os;
}

template <size_t I = 0, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(const tuple<U...> &) {
    cerr << ")" << (_color.pop_back(), _color.back());
}

template <size_t I = 0, typename ...U> inline typename enable_if<I <  sizeof...(U), void>::type _print_err(const tuple<U...> &_t) {
    if (!I) {
        _color.emplace_back(_color.back()), ++_color.back()[3];
        cerr << _color.back();
    }
    cerr << (I ? ", " : "("), _print_err(get<I>(_t)), _print_err<I+1, U...>(_t);
}

template <size_t I = 0, typename ...U> inline typename enable_if<I == sizeof...(U), void>::type _print_err(tuple<U...> &) {
    cerr << ")" << (_color.pop_back(), _color.back());
}

template <size_t I = 0, typename ...U> inline typename enable_if<I <  sizeof...(U), void>::type _print_err(tuple<U...> &_t) {
    if (!I) {
        _color.emplace_back(_color.back()), ++_color.back()[3];
        cerr << _color.back();
    }
    cerr << (I ? ", " : "("), _print_err(get<I>(_t)), _print_err<I+1, U...>(_t);
}

#endif

#endif

/**
 *                                                                                                                 
 *                                                                                                                 
 *                                                                                                                 
 *                            iiiiii         iiiiiiiiii       iiiiiiiiiiiiii                                       
 *                       iiiiiiiiiiiii   iiiiiii    iiii    iiiiiiiiiiiiiii                          ii   iiii     
 *                    iiiiiiii     iiiiiiiii         iiii       iiii iii              iii          iiiiiiiiii      
 *                 iiiiiii          iiiiii           iiii    iiii   ii           iiiiiiiiii      iiii iiii         
 *               iiiiii            iiiii             iiii iiii        iii      iiii    iiiiiiiiiiiiiiiii  ii       
 *             iiiiii            iiiiiii            iiiiiii       iiiiiiii   iii    iiiiiiiiiiiiii iii  iiii       
 *           iiiiii             iiiiiii            iiiii   ii   iiii       iiiiiiiiiii iiii  iii iiii iiii      iii
 *          iiiii              iiiiiiii       ii        iiiii iiii    iiiiiiiii        iii iii  iii  iii  ii  iiii 
 *        iiiiii              iiiiiiii      iiiii     iiiii iiiiiiiiiiiiiiii         iii  iii  ii  iii  iii iiii   
 *       iiiii                 iiiiii     iiii     iiiiii iiiiiii    iii iii       iiii  ii   i   ii  iii  iii     
 *     iiiiii                            iiii  iiiiiiiiiiiiiii       iii iiii   iiiii  iii  ii  iii  iii  ii       
 *    iiiii                              iiiiiiii iiiiiiiiii       iiii   iiiiiiiii            ii  iii  ii         
 *   iiiii                                     iiiiii  iiii      iiiii              iii      ii   ii  i            
 * iiiiii                                  iiiiiiii   iiiii    iiiii                        ii  ii   ii            
 * iiiii                                iiii  iiii    iiiiiiiiiiii                             ii                  
 *  iii                              iiii   iiii       iiiiiiii                                                    
 *                                iiiii   iiii                                                                     
 *                              iiii     iiii                                                                      
 *                            iiii    iiiii                                                                        
 *                          iii     iiiii                                                                          
 *                        iii     iiiii                                                                            
 *                       iii   iiiiii                                                                              
 *                       iiiiiiiii                                                                                 
 *                       iiiiii                                                                                    
 *                                                                                                                 
 *                                                                                                                 
 *                                                                                                                 
**/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 30
Accepted

Test #1:

score: 30
Accepted
time: 0ms
memory: 3876kb

input:

3 4
1 1 1
2 3
1 4
2 2
1 2
3 3

output:

YES
NO
YES
NO

result:

ok 4 token(s): yes count is 2, no count is 2

Test #2:

score: 30
Accepted
time: 0ms
memory: 3628kb

input:

8 5
5 3 4 2 2 6 5 5
1 8
4 5
10 3
11 9
7 2
6 13
14 12
7 3
6 8
4 2
2 5

output:

NO
YES
YES
YES
NO

result:

ok 5 token(s): yes count is 3, no count is 2

Test #3:

score: 30
Accepted
time: 1ms
memory: 3604kb

input:

5 1000
193989534544158 57483670601746 183281373434588 92196008024549 197513473286508
1 5
4 2
7 3
8 6
2 65545142774024
4 67957472319495
5 131478473459166
2 102185858570152
3 191441353035940
5 186000528093501
2 63201184033501
2 77481806092413
3 159789430863849
4 92773786021894
1 194598667478593
3 1458...

output:

YES
YES
YES
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
NO
NO
NO
NO
YES
NO
YES
YES
YES
YES
YES
YES
NO
NO
NO
NO
YES
YES
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
YES
YES
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES
...

result:

ok 1000 token(s): yes count is 375, no count is 625

Test #4:

score: 30
Accepted
time: 1ms
memory: 3804kb

input:

7 1000
88159166205053 95998544558881 48231159865354 231786835189365 84291070100955 225941839972605 33315221625793
2 5
6 4
7 3
1 10
8 11
9 12
6 150843468162951
2 75759088055460
1 86133344610051
4 140694127444493
1 63070113756930
1 90150689680608
6 147790469610032
7 46561924657801
2 103953340734616
6 ...

output:

NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
N...

result:

ok 1000 token(s): yes count is 86, no count is 914

Test #5:

score: 30
Accepted
time: 1ms
memory: 3640kb

input:

7 1000
5 6 7 3 2 5 5
4 7
3 5
1 2
10 6
8 9
12 11
5 2
5 1
5 1
1 2
3 2
5 1
5 2
6 3
4 2
4 1
2 1
5 1
5 1
5 1
7 1
1 2
5 1
5 1
6 3
6 3
5 1
2 2
7 2
7 1
7 1
2 2
1 2
4 2
4 1
1 1
3 1
5 1
2 2
2 2
4 1
2 1
7 2
6 1
2 1
6 2
5 2
1 1
1 1
6 3
7 2
6 3
4 1
1 1
5 1
2 2
7 2
5 1
4 2
5 2
7 2
7 1
4 1
3 2
3 2
1 1
7 2
5 2
1 1
...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO...

result:

ok 1000 token(s): yes count is 199, no count is 801

Test #6:

score: 30
Accepted
time: 1ms
memory: 3872kb

input:

8 1000
172480280419267 212072146993988 23147786306112 161006134777989 37963466387491 50018942108886 18649770050090 50499101532214
7 3
2 1
5 8
9 6
12 11
4 13
10 14
5 57899673021751
7 22087918088240
1 236990257757485
3 21994370580136
7 26427284121647
8 54391900162086
7 27709763713585
6 59631479929866
...

output:

NO
NO
NO
YES
YES
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES...

result:

ok 1000 token(s): yes count is 119, no count is 881

Test #7:

score: 30
Accepted
time: 1ms
memory: 3672kb

input:

6 1000
20326746134626 98517002313418 165556087937310 116347939244398 130872245741329 136674587230071
2 3
6 7
8 1
9 5
10 4
4 31902652070998
2 20697837065544
3 14389422108471
5 45879772826060
2 23505088168423
6 7588643182717
2 13873224035289
4 3462171437780
6 12963735380517
6 3348685354818
3 141429739...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO...

result:

ok 1000 token(s): yes count is 12, no count is 988

Test #8:

score: 30
Accepted
time: 3ms
memory: 3644kb

input:

72 1000
2 10946 610 987 139583862445 20365011074 5 1597 196418 377 267914296 44945570212853 956722026041 5702887 39088169 75025 27777890035288 12586269025 4181 1 53316291173 144 1548008755920 63245986 1 225851433717 6557470319842 832040 2504730781961 102334155 55 3 46368 7778742049 6765 165580141 72...

output:

YES
NO
YES
NO
YES
NO
YES
NO
YES
YES
YES
NO
YES
NO
YES
NO
YES
YES
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
YES
YES
NO
YES
NO
YES
NO
YES
YES
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
YES
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
N...

result:

ok 1000 token(s): yes count is 598, no count is 402

Test #9:

score: 30
Accepted
time: 3ms
memory: 3728kb

input:

70 1000
31322671994689 1078810887856 579849 254672704401 136883 4713 4569916255830 11964196083506 19970 22963823428 157396387326 488813369 12341 1 61 1799 162 82003819900560 221480 5421023350 44076273 37 261 347373755513422 6430641 938216 71316908 687 7394279827673 302103276 2456284 32311 1745552683...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
...

result:

ok 1000 token(s): yes count is 986, no count is 14

Test #10:

score: 30
Accepted
time: 125ms
memory: 3708kb

input:

1000 1000
696394773309 108383178182 819893348793 723784375461 931503257800 952660789032 100236017416 539829053718 209653090976 981815062655 964960614840 961643834067 369486282052 800646303984 387416608811 261777906950 172691588923 485971148690 453102872226 770561490733 375803723200 861225005889 1185...

output:

YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
NO
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
NO
NO
YES
YES
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
NO
NO
NO
NO
...

result:

ok 1000 token(s): yes count is 290, no count is 710

Test #11:

score: 30
Accepted
time: 128ms
memory: 3652kb

input:

1000 1000
328753409716 63174357177 116706499724 751756098545 913879475315 309225707947 610363994448 928602608183 298378305770 255654307269 444288397875 332511908079 297834684008 532592347055 268793918986 782156365515 316531786356 584037378094 809660826672 456709928147 277332 603219716866 60062165567...

output:

YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
...

result:

ok 1000 token(s): yes count is 124, no count is 876

Test #12:

score: 30
Accepted
time: 126ms
memory: 3648kb

input:

1000 1000
596779917266 859728384612 790999537569 946122172426 539615683280 616114813176 675147442971 523252967306 989540738771 880850130723 850501333358 858531013132 700803829612 642617589194 814265292894 799430766156 589454900606 735369030885 797404510621 602718454036 883696282103 974675349909 7793...

output:

YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok 1000 token(s): yes count is 3, no count is 997

Test #13:

score: 30
Accepted
time: 137ms
memory: 3708kb

input:

1000 1000
12340874 29443 42 12492 139286 153819 53474891 4999 5513602 15 15542744701 367380 19381 1390668 27542397298 328751473 10398280 3528202605 126026926 21552 4031001 14293341319 140519268911 360904 1422 28 13089 32427234919 457240409937 17711545787 39539446 51 355784231 810175146335 916553144 ...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
YES
YES
NO
NO
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
Y...

result:

ok 1000 token(s): yes count is 749, no count is 251

Test #14:

score: 30
Accepted
time: 116ms
memory: 3692kb

input:

1000 1000
19 27 18 26 41 49 29 27 46 24 43 25 50 4 17 25 15 15 4 33 24 35 10 7 27 3 39 43 36 28 29 5 20 5 42 43 33 17 11 26 43 21 38 31 12 33 48 33 14 29 48 49 15 37 16 4 16 44 25 45 41 17 37 49 32 40 9 12 8 22 2 24 9 21 14 16 34 45 47 25 28 16 26 7 11 42 26 29 35 32 34 44 11 30 20 47 13 6 41 19 37 ...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
N...

result:

ok 1000 token(s): yes count is 468, no count is 532

Test #15:

score: 30
Accepted
time: 116ms
memory: 3720kb

input:

1000 1000
996069901379 940888328260 925342655682 923520191546 877076702411 855421610507 842224729549 837033687452 810175146335 792646717951 752993949814 717579080665 711089804069 708221643771 699280599587 697696794210 670880120082 641841749136 631447339331 619769332589 617930141820 586690159836 5636...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok 1000 token(s): yes count is 0, no count is 1000

Subtask #2:

score: 0
Time Limit Exceeded

Test #16:

score: 0
Time Limit Exceeded

input:

10000 10000
85117964119 41472951000 61693640396 66409648221 91978532661 62922448518 92497200794 43837348258 45577855926 38256001396 79446271832 95289903258 62510175551 97599809584 56162244722 87617641117 64010325734 56604859803 58544571483 40687963085 38627694508 64665875035 62273927372 73014847094 ...

output:


result:


Subtask #3:

score: 0
Time Limit Exceeded

Test #20:

score: 0
Time Limit Exceeded

input:

50000 50000
16394396247 17456058492 11358090355 13208121167 8612535629 2853817504 18100755237 18603321637 1618810635 7615832530 13631222424 7817630977 10963098997 19654927084 645638016 9352759139 17939720223 15106346489 14475376391 2122412099 15482023637 11224675857 15931143509 4240408932 1270948838...

output:


result:


Subtask #4:

score: 0
Time Limit Exceeded

Test #24:

score: 20
Accepted
time: 217ms
memory: 3816kb

input:

70 100000
66748 126 1 91045172 3605661959574 274077743637349 147314183 8209537 740253 6920630855 25494 1377240316614 15756 6 108000 18118446805 169389361127761 29316262755 48 2643445763 5834083602536 3 9439745562111 29 3719 10 47434709561 11197815949 6018 325122336074 851181326345 1633739329 1527382...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
...

result:

ok 100000 token(s): yes count is 98093, no count is 1907

Test #25:

score: 0
Time Limit Exceeded

input:

100000 100000
7549638646 8066727970 9672316362 9615802181 6376690689 416134043 5288164622 2316444041 8423663950 1806779510 3010692396 7782858557 4229348735 1361364214 9005774175 6382408188 8174082766 8406340542 8599848784 3178078732 1395839441 5310497981 6807939596 2743315129 3143071583 3636776799 5...

output:


result: