#include #include #include #include using namespace std; #define FUMP(x, y) ((x)+(y)*64) typedef long long ll; const int maxn = 200009*64; ll arr[200009]; set> ranges[64]; int p[maxn]; int r[maxn]; int Find(int a) { if(p[a] == a) return a; p[a] = Find(p[a]); return p[a]; } void Union(int a, int b) { //printf("Union of %d,%d and %d,%d\n", a%64, a/64, b%64, b/64); a = Find(a); b = Find(b); if(a == b) return; if(r[a] > r[b]) { p[b] = a; } else if(r[a] < r[b]) { p[a] = b; } else { p[b] = a; r[a]++; } } void insert(pair p1, pair p2) { for (int x=p1.first; x<=p2.first; x++) { int L = p1.second; int R = p2.second; pair newrange{L, R}; if (arr[L-1] & (1ll<<(x))) { Union(FUMP(x, L), FUMP(x, L-1)); } while (Lfirst, it->second); newrange.first = min(newrange.first, it->first); newrange.second = max(newrange.second, it->second); arr[L] |= 1ll<second; ranges[x].erase(it); } arr[L] |= 1ll< p1, pair p2) { bool same = (Find(FUMP(p1.first, p1.second)) == Find(FUMP(p2.first, p2.second))); printf("%d\n", same); } int main() { for (int i=0; i x2) swap(x1, x2); if (y1 > y2) swap(y1, y2); pair p1{x1, y1}, p2{x2, y2}; if (t == 0) insert(p1, p2); else query(p1, p2); } }