結果

問題 No.2319 Friends+
ユーザー Jerry LiJerry Li
提出日時 2023-12-26 03:09:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,783 bytes
コンパイル時間 2,104 ms
コンパイル使用メモリ 177,228 KB
実行使用メモリ 223,708 KB
最終ジャッジ日時 2024-09-27 14:52:34
合計ジャッジ時間 21,391 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
142,396 KB
testcase_01 AC 36 ms
134,296 KB
testcase_02 AC 769 ms
141,464 KB
testcase_03 WA -
testcase_04 AC 705 ms
143,300 KB
testcase_05 AC 716 ms
143,180 KB
testcase_06 WA -
testcase_07 AC 893 ms
216,920 KB
testcase_08 AC 944 ms
216,920 KB
testcase_09 AC 940 ms
216,916 KB
testcase_10 AC 918 ms
217,172 KB
testcase_11 AC 939 ms
216,916 KB
testcase_12 AC 38 ms
138,940 KB
testcase_13 AC 38 ms
139,196 KB
testcase_14 WA -
testcase_15 AC 39 ms
138,940 KB
testcase_16 WA -
testcase_17 AC 37 ms
137,016 KB
testcase_18 AC 2,769 ms
217,020 KB
testcase_19 AC 950 ms
217,020 KB
testcase_20 TLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long
typedef int uci;
#define int long long
#define F first
#define S second
typedef complex<double> cd;

seed_seq seq{
    (uint64_t) chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count(),
    (uint64_t) __builtin_ia32_rdtsc(),
    (uint64_t) (uintptr_t) make_unique<char>().get()
};
mt19937 rng(seq);
 mt19937_64 lrng(seq);

struct debugger{
    template <typename T>
    debugger& operator<<(T &a){
        #ifdef DEBUG
            cerr << a;
        #endif
        return *this;
    }
    template <typename T>
    debugger& operator<<(T &&a){
        #ifdef DEBUG
            cerr << a;
        #endif
        return *this;
    }
} deb;

const double PI = acos(-1.0);
const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;

//! function insert

//THINK FIRST, CODE SECOND
//DON'T GET STUCK ON ONE STRATEGY
//CALM DOWNNN FOR ONCE IN YOUR LIFE
//REDUCE
//COUGH E??!?!?!! O.O
//uwu i see you ryan

 struct custom_hash {
     static uint64_t splitmix64(uint64_t x) {
         // http://xorshift.di.unimi.it/splitmix64.c
         x += 0x9e3779b97f4a7c15;
         x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
         x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
         return x ^ (x >> 31);
     }
     size_t operator()(uint64_t x) const {
         static const uint64_t FIXED_RANDOM = lrng();
         return splitmix64(x + FIXED_RANDOM);
     }
 };
int adj[20000][320];
ar<int, 2> edges[200000];
int curr[20000];
int place[20000];
int bits[20000];
ar<int, 2> qs[200000];
bool out[200000];
int from_room[500];
int to_room[500];
int counts[20000][500];
int upc[20000][500];
int colorc[20000];
int colorup[20000];
void solve() {
    memset(adj, 0, sizeof(adj));
    memset(out, 0, sizeof(out));
    memset(upc, -1, sizeof(upc));
    memset(colorup, -1, sizeof(colorup));
    int n, m;
    cin >> n >> m;
    for(int i{}; i < n; ++i){
        cin >> curr[i];
    }

    for(int i{}; i < n; ++i)
        place[i] = i/64;
    for(int i{}; i < n; ++i)
        bits[i] = (1<<(i%64));
    for(int i{}; i < m; ++i){
        cin >> edges[i][0] >> edges[i][1];
        edges[i][0]--, edges[i][1]--;
        adj[edges[i][0]][place[edges[i][1]]] |= bits[edges[i][1]];
        adj[edges[i][1]][place[edges[i][0]]] |= bits[edges[i][0]];
    }

    int q;
    cin >> q;
    for(int i{}; i < q; ++i){
        cin >> qs[i][0] >> qs[i][1];
        qs[i][0]--, qs[i][1]--;
    }

    int sq = sqrt(q);
    for(int i{}; i < q; i += sq){
        int last = min(q, i+sq);
        int c{};
        for(int j = i; j < last; ++j){
            if(colorup[curr[qs[j][1]]] != i){
                colorc[curr[qs[j][1]]] = c++;
                colorup[curr[qs[j][1]]] = i;
            }
        }
        for(int j{}; j < m; ++j){
            if(colorup[curr[edges[j][0]]] == i){
                if(upc[edges[j][1]][colorc[curr[edges[j][0]]]] != i){
                    upc[edges[j][1]][colorc[curr[edges[j][0]]]] = i;
                    counts[edges[j][1]][colorc[curr[edges[j][0]]]] = 1;
                }else
                    counts[edges[j][1]][colorc[curr[edges[j][0]]]]++;
            }
            if(colorup[curr[edges[j][1]]] == i){
                if(upc[edges[j][0]][colorc[curr[edges[j][1]]]] != i){
                    upc[edges[j][0]][colorc[curr[edges[j][1]]]] = i;
                    counts[edges[j][0]][colorc[curr[edges[j][1]]]] = 1;
                }else
                    counts[edges[j][0]][colorc[curr[edges[j][1]]]]++;
            }
        }
        for(int j = i; j < last; ++j){
            int f_room = curr[qs[j][0]];
            int t_room = curr[qs[j][1]];
            if(f_room == t_room)
                continue;
            int st = upc[qs[j][0]][colorc[t_room]] == i ? counts[qs[j][0]][colorc[t_room]] : 0;
            for(int k = i; k < j; ++k){
                if(out[k] && ((adj[qs[j][0]][place[qs[k][0]]])&(bits[qs[k][0]]))){
                    if(from_room[k-i] == t_room)
                        st--;
                    if(to_room[k-i] == t_room)
                        st++;
                }
            }
            if(st > 0){
                out[j] = true;
                from_room[j-i] = f_room;
                to_room[j-i] = t_room;
                curr[qs[j][0]] = t_room;
            }
        }
    }
    for(int i{}; i < q; ++i){
        if(!out[i])
            cout << "No\n";
        else
            cout << "Yes\n";
    }
}

uci main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

        // cout << "Case #" << t  << ": ";
        solve();
}

/*
    random number generator stuff
    num = rng(); gives integer number
    num = uniform_int_distribution<int>(a, b)(rng); -> bounds [a, b]
    num = uniform_real_distribution<double>(a, b)(rng); -> bounds [a, b)
    can also instantiate distributions and call on generator:
    uniform_int_distribution<int> thing(a, b);
    num = thing(rng);
*/
// struct custom_hash {
//     static uint64_t splitmix64(uint64_t x) {
//         // http://xorshift.di.unimi.it/splitmix64.c
//         x += 0x9e3779b97f4a7c15;
//         x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
//         x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
//         return x ^ (x >> 31);
//     }
//     size_t operator()(uint64_t x) const {
//         static const uint64_t FIXED_RANDOM = lrng();
//         return splitmix64(x + FIXED_RANDOM);
//     }
// };
0