i64 solve(vector<Rect> rects){ compress(rects); vector<Event> evs = eventsFromRect(rects); i64 total = 0; IntervalTree::Node root = {1, 0, (int)xs.size() - 2}; tree.init(root); for (size_t i = 0; i < evs.size(); i++){ Event &e = evs[i]; if (i != 0){ i64 s = tree.gao(0, (int)xs.size() - 2).query(root, k); //printf("%lld\n", s); total += s * (ys[evs[i].tick] - ys[evs[i - 1].tick]); } //e.debug(); //printf("%lu: %lld\n", i, total); tree.gao(e.from, e.to).add(root, e.inc); } return total; }
int main(){ int T; scanf("%d", &T); while (T--){ scanf("%d", &N); for (int i = 0; i < N; i++) scanf("%d %d", &x[i], &y[i]); ds.init(); citysTree.init(); stateTree.init(); int M; scanf("%d", &M); while (M--){ char cmd[32]; scanf("%s", cmd); if (!strcmp(cmd, "road")){ int A, B; scanf("%d%d", &A, &B); int pA = ds.find(A), pB = ds.find(B); if (pA != pB){ citysTree.gao(ds._min[pA], ds._max[pA] - 1).add(1, 0, maxrange, -ds._cnt[pA], false); stateTree.gao(ds._min[pA], ds._max[pA] - 1).add(1, 0, maxrange, -1, false); citysTree.gao(ds._min[pB], ds._max[pB] - 1).add(1, 0, maxrange, -ds._cnt[pB], false); stateTree.gao(ds._min[pB], ds._max[pB] - 1).add(1, 0, maxrange, -1, false); //cout << citysTree.gao(0, maxrange).query(1, 0, maxrange) << endl; int pC = ds.join(A, B); //cout << ds._cnt[pC] << ": " << ds._min[pC] << ", " << ds._max[pC] << endl; citysTree.gao(ds._min[pC], ds._max[pC] - 1).add(1, 0, maxrange, ds._cnt[pC], false); stateTree.gao(ds._min[pC], ds._max[pC] - 1).add(1, 0, maxrange, 1, false); //cout << citysTree.gao(0, maxrange).query(1, 0, maxrange) << endl; } }else{ assert(!strcmp(cmd, "line")); double dC; scanf("%lf", &dC); int C = floor(dC); //cout << C << endl; int citysNum = citysTree.gao(C, C).query(1, 0, maxrange); int stateNum = stateTree.gao(C, C).query(1, 0, maxrange); printf("%d %d\n", stateNum, citysNum); } } } }