/* ID: espr1t TASK: KEYWORDS: */ #include #include #include #include #include #include using namespace std; FILE* in = stdin; FILE* out = stdout; const int MAX = 100100; const int TREE = 262144; const int INF = 1000000001; struct Point { int id; int x, y, t; bool operator < (const Point& r) const { if (y != r.y) return y > r.y; if (x != r.x) return x < r.x; return t < r.t; } }; int n; Point a[MAX]; int ans[MAX]; int tree[TREE]; void update(int idx, int val) { idx += (TREE >> 1); while (idx) { tree[idx] = max(tree[idx], val); idx >>= 1; } } int searchRight(int idx, int limit) { if (idx * 2 >= TREE) return idx - (TREE >> 1); if (tree[(idx << 1) | 0] >= limit) return searchRight((idx << 1) | 0, limit); return searchRight((idx << 1) | 1, limit); } int queryRight(int idx, int limit) { idx += (TREE >> 1); if (tree[idx] >= limit) return idx; bool isLeft = !(idx & 1); idx >>= 1; while (idx) { if (isLeft && tree[(idx << 1) | 1] >= limit) return searchRight((idx << 1) | 1, limit); isLeft = !(idx & 1); idx >>= 1; } return MAX - 1; } int searchLeft(int idx, int limit) { if (idx * 2 >= TREE) return idx - (TREE >> 1); if (tree[(idx << 1) | 1] >= limit) return searchLeft((idx << 1) | 1, limit); return searchLeft((idx << 1) | 0, limit); } int queryLeft(int idx, int limit) { idx += (TREE >> 1); if (tree[idx] >= limit) return idx; bool isRight = (idx & 1); idx >>= 1; while (idx) { if (isRight && tree[(idx << 1) | 0] >= limit) return searchLeft((idx << 1) | 0, limit); isRight = (idx & 1); idx >>= 1; } return 0; } void solve() { sort(a, a + n); memset(tree, -1, sizeof(tree)); int lastY = -1; vector add; for (int i = 0; i < n; i++) { if (a[i].y != lastY) { for (int c = 0; c < (int)add.size(); c++) update(a[add[c]].x, a[add[c]].t); add.clear(); lastY = a[i].y; } add.push_back(i); // To the left int minLeft = queryLeft(a[i].x, a[i].t); // To the right int maxRight = queryRight(a[i].x, a[i].t); // fprintf(stderr, "At point (%d, %d) with temp = %d: possible interval [%d, %d]\n", // a[i].x, a[i].y, a[i].t, minLeft, maxRight); if (minLeft >= a[i].x || maxRight <= a[i].x) { ans[a[i].id] = -INF; continue; } if (minLeft == 0 || maxRight == MAX - 1) { ans[a[i].id] = INF; continue; } ans[a[i].id] = maxRight - minLeft; } } int main(void) { in = fopen("magnet.in", "rt"); out = fopen("magnet.out", "wt"); fscanf(in, "%d", &n); for (int i = 0; i < n; i++) { a[i].id = i; fscanf(in, "%d %d %d", &a[i].x, &a[i].y, &a[i].t); } solve(); for (int i = 0; i < n; i++) { if (ans[i] == -INF) fprintf(out, "0\n"); else if (ans[i] == INF) fprintf(out, "inf\n"); else fprintf(out, "%d\n", ans[i]); } return 0; }