#include 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 cd; seed_seq seq{ (uint64_t) chrono::duration_cast(chrono::high_resolution_clock::now().time_since_epoch()).count(), (uint64_t) __builtin_ia32_rdtsc(), (uint64_t) (uintptr_t) make_unique().get() }; mt19937 rng(seq); mt19937_64 lrng(seq); struct debugger{ template debugger& operator<<(T &a){ #ifdef DEBUG cerr << a; #endif return *this; } template 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][313]; ar edges[200000]; int curr[20000]; int place[20000]; int bits[20000]; vector a[20000]; ar qs[200000]; bool out[200000]; unordered_map counts[20000]; int from_room[500]; int to_room[500]; int orig_room[20000]; void solve() { memset(adj, 0, sizeof(adj)); memset(out, 0, sizeof(out)); int n, m; cin >> n >> m; for(int i{}; i < n; ++i){ cin >> curr[i]; orig_room[i] = curr[i]; } for(int i{}; i < n; ++i) place[i] = i/64; for(int i{}; i < n; ++i) bits[i] = (1<> 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]]; a[edges[i][0]].push_back(edges[i][1]); a[edges[i][1]].push_back(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 j{}; j < m; ++j){ counts[edges[j][0]][curr[edges[j][1]]]++; counts[edges[j][1]][curr[edges[j][0]]]++; } for(int i{}; i < q; i += sq){ int last = min(q, i+sq); 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 = counts[qs[j][0]][t_room]; 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--; else 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 j{}; j < n; ++j){ if(orig_room[j] != curr[j]){ for(int k : a[j]){ counts[k][orig_room[j]]--; if(counts[k][orig_room[j]] == 0) counts[k].erase(orig_room[j]); counts[k][curr[j]]++; } } orig_room[j] = curr[j]; } } 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(a, b)(rng); -> bounds [a, b] num = uniform_real_distribution(a, b)(rng); -> bounds [a, b) can also instantiate distributions and call on generator: uniform_int_distribution 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); // } // };