Language: C

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

const int INF = ~0U>>1;
const int MAX_N = 500005;
const int N = 200005;
const int M = 200005;
struct Q{
    int ask, x, y;
    Q(int _ask = 0, int _x = 0, int _y = 0){
        ask = _ask;
        x = _x;
        y = _y;
    }
    void go();
} que[N];

struct Node{
    Node*ch[2], *p;
    int size, val;
    Node(){
        size = 0;
        val = -INF;
    }
    bool d(){
        return this == p->ch[1];
    }
    void setc(Node*c, int d){
        ch[d] = c;
        c->p = this;
    }
    void relax(){
    }
    void upd(){
        size = ch[0]->size + ch[1]->size + 1;
    }
} Tnull, *null = &Tnull;
Node mem[MAX_N], *C = mem, *rt[MAX_N], *q[MAX_N];

Node*make(int v) {
	C->ch[0] = C->ch[1] = null;
	C->size = 1;
	C->val = v;
	return C++;
}

void rot(Node*&root, Node*t) {
	Node*p = t->p;
	p->relax();
	t->relax();
	int d = t->d();
	p->p->setc(t, p->d());
	p->setc(t->ch[!d], d);
	t->setc(p, !d);
	p->upd();
	if (p == root)
		root = t;
}

void splay(Node*&root, Node*t, Node*f = null){
    while(t->p != f){
        if(t->p->p == f)
            rot(root, t);
        else
            t->d() == t->p->d() ? (rot(root, t->p), rot(root,t)) : (rot(root,t), rot(root,t));
    }
    t->upd();
}

Node* select(Node*&root, int k) {
	for (Node*t = root;;) {
		t->relax();
		int c = t->ch[0]->size;
		if (k == c)
			return t;
		if (k > c)
			k -= c + 1, t = t->ch[1];
		else
			t = t->ch[0];
	}
}

int getr(Node *&root, int val){
    Node*t = root;
    int cnt = 0;
    while(t != null){
        t->relax();
        if(t->val > val){
            t = t->ch[0];
        }
        else{
            cnt += t->size - t->ch[1]->size;
            t = t->ch[1];
        }
    }
    return cnt;
}

Node*&get(Node*&root, int l, int r) { //[l,r)
	Node*L = select(root, l - 1);
	Node*R = select(root, r);
	splay(root, L);
	splay(root, R, L);
	return R->ch[0];
}

void del(Node*&root, int val){
    int rk = getr(root, val);
    Node* t = get(root, rk,rk+1)->p;
    t->setc(null, 0);
    splay(root, t);
}

void ins(Node*&root, int val){
    int rk = getr(root, val);
    Node* t = get(root, rk+1,rk+1)->p;
    t->setc(make(val), 0);
    splay(root, t->ch[0]);
}

int fa[N];
int getf(int u){
    return u==fa[u]? u : fa[u] = getf(fa[u]);
}

void merge(int x, int y){
    int l, r;
    x = getf(x);
    y = getf(y);
    if(x == y) return;
    if(rt[x]->size < rt[y]->size) swap(x, y);
    q[l = r = 1] = rt[y];
    while(l<=r){
        Node* u = q[l++];
        if(u != null)
            ins(rt[x], u->val);
        for(int i = 0; i < 2; ++i)
        if(u->ch[i] != null)
            q[++r] = u->ch[i];
    }
}

int sumc, sum, a[N];
void Q::go(){
    if(ask == 0){
        merge(x,y);
    } else
    if(ask == 1){
        sumc++;
        Node*t = select(rt[x], rt[x]->size - y);
        sum += t->val;
    } else{
        del(rt[x], a[x]);
        a[x] = y;
        ins(rt[x], y);
    }
}

pair<int,int> e[M];
bool mark[M];
char s[5];
int main(){
    freopen("1.txt","r",stdin);
    int n, m, i, x, y, cal = 0;
    while(~scanf("%d%d",&n,&m)&&(n+m)){
        for(i = 1; i <= n; ++i){
            scanf("%d",&a[i]);
            rt[i] = make(a[i]);
            rt[i]->setc(null,0);
            rt[i]->setc(null,1);
            rt[i]->upd();
        }
        memset(mark, 0, sizeof(mark));
        for(i = 1; i <= m; ++i)
            scanf("%d%d",&e[i].first,&e[i].second);
        int cnt = 0;
        while(~scanf("%s",s)&&s[0]!='E'){
            if(s[0] == 'D'){
                scanf("%d",&x);
                mark[x] = 1;
                que[cnt++] = Q(0,x);
            } else
            if(s[0] == 'Q'){
                scanf("%d%d",&x,&y);
                que[cnt++] = Q(1,x,y);
            } else
            if(s[0] == 'C'){
                scanf("%d%d",&x,&y);
                que[cnt++] = Q(2,x,y);
            }
        }

        for(i = 1; i <= m; ++i)
        if(!mark[i])
            merge(e[i].first, e[i].second);

        sum = 0;
        sumc = 0;
        for(i = cnt-1; i >= 0; --i)
            que[i].go();
        printf("Case #%d: %.6f\n",++cal,sum*1.0/sumc);
    }
    return 0;
}

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