The recent schoolwork is heavy, which was inscribed for two days. Last night when I went to bed, I suddenly thought of the final solution.
I don't know if it should be called topology. It feels quite like it. The title is called the class topology. The method of the problem is to use a map to mark the existence of the state, and then using a similar topology method to constantly find the remaining stable after the block, I used two priority queue to maintain, respectively, take the maximum and minimum. Then it simulates the process and takes the block.
The code is as follows:
#include <iostream> #include <string.h> #include <math.h> #include <queue> #include < algorithm> #include <stdlib.h> #include <map> #include <set> #include <stdio.h>using namespace std; #define LL Long long#define pi ACOs ( -1.0) const int Mod=1e9+9;const int Inf=0x3f3f3f3f;const double eqs=1e-9; struct node{int x, y;} FEI[110000];p riority_queue<int,vector<int>,greater<int> >q1;priority_queue<int,vector< Int>,less<int> >q2;map<pair<int,int>, int> mp;int vis[110000];bool Check (int x, int y) {if ( Mp.find (Make_pair (x-1,y+1))!=mp.end ()) {if (Mp.find (Make_pair)) X-2,y () ==mp.end (&&mp.find (x -1,y)) ==mp.end ()) return 0; } if (Mp.find (Make_pair (x,y+1))!=mp.end ()) {if (Mp.find (Make_pair)) X-1,y () ==mp.end (M Ake_pair (X+1,y)) ==mp.end ()) return 0; } if (Mp.find (Make_pair (x+1,y+1))!=mp.end ()) {if (Mp.finD (Make_pair (x+1,y)) ==mp.end () &&mp.find (Make_pair (x+2,y)) ==mp.end ()) return 0; } return 1;} void topo (int n) {int I, J, k=0, U, x, Y, V; LL ans=0; Map<pair<int,int>,int>::iterator it; For (It=mp.begin (); It!=mp.end (); it++) {if (check (It->first.first,it->first.second)) { u=it->second; Q1.push (u); Q2.push (U); }} while (K<n) {if ((k&1) ==0) {while (!q2.empty ()) { U=q2.top (); Q2.pop (); if (!vis[u]&&check (FEI[U].X,FEI[U].Y)) {vis[u]=1; Break }}} else{while (!q1.empty ()) { U=q1.top (); Q1.pop (); if (!vis[u]&&check (FEI[U].X,FEI[U].Y)) {vis[u]=1; Break }}} ans= (Ans*n%mod+u)%mod; Mp.erase (Make_pair (FEI[U].X,FEI[U].Y)); printf ("%d\n", u); X=fei[u].x-1;y=fei[u].y-1; if (Mp.find (Make_pair (x, y)!=mp.end ()) {V=mp[make_pair (x, y)]; if (!vis[v]&&check (x, y)) {Q1.push (v); Q2.push (v); }} x=fei[u].x;y=fei[u].y-1; if (Mp.find (Make_pair (x, y)!=mp.end ()) {V=mp[make_pair (x, y)]; if (!vis[v]&&check (x, y)) {Q1.push (v); Q2.push (v); }} x=fei[u].x+1;y=fei[u].y-1; if (Mp.find (Make_pair (x, y)!=mp.end ()) {V=mp[make_pair (x, y)]; if (!vis[v]&&check (x, y)) {Q1.push (v); Q2.push (v); }} k++; } printf ("%i64d\n", ans);} int main () {int n, I, J, POS, x, y; scanf ("%d", &n); Mp.clear (); memset (vis,0,sizeof (VIS)); for (i=0;i<n;i++) {scanf ("%d%d", &fei[i].x,&fei[i].y); Mp[make_pair (FEI[I].X,FEI[I].Y)]=i; } topo (n); return 0;}
Codeforces Round #295 (Div. 1) B. Cubes (stl+ class topology)