Language: C

#include <stdio.h>
#include <string.h>
#define ll long long
#include <algorithm>
#define clr(a,b) memset(a,b,sizeof(a))

using namespace std;
const int LMI=1000005;
const int Mod=1000000;
int N, M;ll X;
int val[LMI], bit[LMI];//扈溯ョ。 蛹コ髣エ豎ょ柱
// 謨ー謐ョ蟄俶叛莉?蠑?ァ?蛻晏ァ句喧 clr(av, 0);
int lowbit(int a) { return a & (-a);}
int query(int a) {
    int ret=0;  for(ret=0; a>0; ret+=val[a], a-=lowbit(a));  return ret;
}
void insert(int a, int add, int n) {
    for(; a<=n; val[a]+=add, a+=lowbit(a));//n譏ッ譛?、ァ闌?峩
}

int que(int a) {
    int ret=0;  for(ret=0; a>0; ret+=bit[a], a-=lowbit(a));  return ret;
}
void ins(int a, int add, int n) {
    for(; a<=n; bit[a]+=add, a+=lowbit(a));//n譏ッ譛?、ァ闌?峩
}
void build(int n){
	for(int i=1; i<=n; i++)
		bit[i]=lowbit(i);
}

int delro[1005], delco[1005], b[1005][1005], a[1005][1005], num[LMI], start[LMI];
struct node{
    int val, ro, co;
}B[LMI];

int cmp(node u, node v){
    if(u.val!=v.val) return u.val<v.val;
    else {
        if(u.ro!=v.ro) return u.ro<v.ro;
        else{
            if(u.co!=v.co) return u.co<v.co;
            else return 0;
        }
    }
}
int bsh1(int low, int high, int v){
    int mid;
	while (low<high){
		mid=(low+high)>>1;
		if(query(mid)<v)low=mid+1;	//螟ァ莠守ュ我コ思
	//	if(a[mid]<=v)low=mid+1;	//螟ァ莠思
		else high=mid;
	}
	return low;
}
int bsh2(int st, int low, int high, int v){
    int mid;
    st=que(st);
	while (low<high){
		mid=(low+high)>>1;
		if(que(mid) - st<v)low=mid+1;	//螟ァ莠守ュ我コ思
	//	if(a[mid]<=v)low=mid+1;	//螟ァ莠思
		else high=mid;
	}
	return low;
}
void solve(){
    for(int i=0; i<=N; i++) delro[i]=0;
    for(int i=0; i<=M; i++) delco[i]=0;

    int st=0, mv=-1;
    B[0].val=X; B[0].ro=B[0].co=0;
    a[0][0]=X;
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            if(st==0) {st++; continue;}
            B[st].ro=i;
            B[st].co=j;
            ll t=X*B[st].ro%Mod;
            X=1234*t*t + 5678*X*B[st].co + 91011;
            X=X%Mod + 1;
            B[st].val=X;
            a[i][j]=B[st].val;
            mv=max(mv, B[st].val);
            st++;
        }
    }

    sort(B, B+N*M, cmp);
    for(int i=0; i<=mv; i++) val[i]=0;
    build(N*M);

    int pre=-1, cnt;
    for(int i=0; i<M*N; i++){
        insert(B[i].val, 1, mv);
        if(B[i].val!=pre){
            if(pre!=-1) { num[pre]=cnt; };
            pre=B[i].val;
            cnt=1;
            start[B[i].val]=i+1;
            b[B[i].ro][B[i].co]=cnt;
        }else{
            cnt++;
            b[B[i].ro][B[i].co]=cnt;
        }
    }
    num[pre]=cnt;

    for(int tot=N*M; tot>0; ){
        int mid=(tot+1)/2;
        int x=bsh1(1, mv+1, mid);
        int yu=query(x)-mid;
        yu=num[x]-yu;
        int id=bsh2(start[x], start[x], N*M+1, yu-1);
        int ro=B[id-1].ro, co=B[id-1].co;
        int sum=0;
        for(int j=0; j<M; j++){
            if(!delco[j] && a[ro][j]!=0){
                insert(a[ro][j], -1, mv);
                ins(b[ro][j]+start[a[ro][j]]-1, -1, N*M);
                a[ro][j]=0;
                sum++;
            }
        }
        for(int i=0; i<N; i++){
            if(!delro[i] && a[i][co]!=0){
                insert(a[i][co], -1, mv);
                ins(b[i][co]+start[a[i][ro]]-1, -1, N*M);
                a[i][co]=0;
                sum++;
            }
        }
        delro[ro]=delco[co]=1;
        tot-=sum;
    }
}
int main(){
//#ifdef H403
   // freopen("c:\\in.txt","r",stdin);
//#endif
    int T;
    scanf("%d", &T);
    for(int cs=1; cs<=T; cs++){
        printf("Case #%d:\n", cs);
        scanf("%d%d%lld", &N, &M, &X);
        solve();
    }
    return 0;
}

Compiler output:
main.c:4:10: fatal error: algorithm: No such file or directory
    4 | #include <algorithm>
      |          ^~~~~~~~~~~
compilation terminated.