LOJ,T了。
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define maxn 500005
#define pb push_back
#define lc u<<1
#define rc u<<1|1
using namespace std;
char cb[1<<15],*cs=cb,*ct=cb;
#define getc() (cs==ct&&(ct=(cs=cb)+fread(cb,1,1<<15,stdin),cs==ct)?0:*cs++)
void read(int &res){
char ch;
for(;!isdigit(ch=getc()););
for(res=ch-'0';isdigit(ch=getc());res=res*10+ch-'0');
}
int n,m,K,x[maxn],y[maxn],rx[maxn],ry[maxn],F[maxn],siz[maxn],ans[maxn],tim[maxn],c[maxn],pos[maxn],cnt,qcnt;
int Find(int u){