結果
| 問題 |
No.1054 Union add query
|
| コンテスト | |
| ユーザー |
tails
|
| 提出日時 | 2023-03-13 18:57:26 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 26 ms / 2,000 ms |
| コード長 | 2,414 bytes |
| コンパイル時間 | 1,766 ms |
| コンパイル使用メモリ | 27,904 KB |
| 実行使用メモリ | 12,416 KB |
| 最終ジャッジ日時 | 2024-09-18 07:39:01 |
| 合計ジャッジ時間 | 1,873 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:104:9: warning: implicit declaration of function ‘write’ [-Wimplicit-function-declaration]
104 | write(1,wbuf,wp-wbuf);
| ^~~~~
main.c:105:9: warning: implicit declaration of function ‘_exit’ [-Wimplicit-function-declaration]
105 | _exit(0);
| ^~~~~
main.c:105:9: warning: incompatible implicit declaration of built-in function ‘_exit’ [-Wbuiltin-declaration-mismatch]
ソースコード
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#define rd_init() char*rp=({char*mmap();mmap(0l,1l<<25,1,2,0,0ll);})
#define rd_skip() while(*rp++>=48)
//#define rd() ({int _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;})
//#define rd_signed() ({int _s=*rp=='-'&&++rp,_v=rd();_s?-_v:_v;})
#define rd() getuint(&rp)
#define rd_signed() getint(&rp)
#define WTHI(v) {unsigned _z=v;int _n=0;ulong _d=0;while(++_n,_d=_d<<8|0x30|_z%10,_z/=10);*(ulong*)wp=_d;wp+=_n;}
#define WTLO(v) {unsigned _z=v;int _n=8;ulong _d=0;while(_d=_d<<8|0x30|_z%10,_z/=10,--_n);*(ulong*)wp=_d;wp+=8;}
#define wt(v) if(v>=100000000){WTHI(v/100000000);WTLO(v);}else{WTHI(v);}
typedef unsigned long ulong;
// https://yukicoder.me/submissions/482915
const ulong ma0 = 1157442765409226768;
const ulong ma1 = 1085102592571150095;
const ulong ma2 = 71777214294589695;
const ulong ma3 = 281470681808895;
const ulong ma4 = 4294967295;
static inline int getuint(char**rpp) {
char*rp=*rpp;
ulong tmp = *(ulong*)rp;
int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzl((tmp & ma0) ^ ma0) : 0;
tmp = tmp << dig & ma1;
tmp = tmp * 10 + (tmp >> 8) & ma2;
tmp = tmp * 100 + (tmp >> 16) & ma3;
tmp = tmp * 10000 + (tmp >> 32) & ma4;
rp += (72 - dig >> 3);
*rpp=rp;
return tmp;
}
static inline int getint(char**rpp) {
char*rp=*rpp;
int pn = *rp=='-'&&++rp;
int tmp=getuint(&rp);
*rpp=rp;
return pn?-tmp:tmp;
}
#define UFSIZE 500002
struct{int u,v;}ufbuf[UFSIZE];
void uf_init(){
for(int i=0;i<UFSIZE;++i){
ufbuf[i].u=-1;
ufbuf[i].v=0;
}
}
int uf_root(int a){
int b,t=a;
int y,z=0;
while(b=ufbuf[t].u,b>=0) z+=ufbuf[t].v,t=b;
while(b=ufbuf[a].u,b>=0) y=ufbuf[a].v,ufbuf[a].v=z,z-=y,ufbuf[a].u=t,a=b;
return t;
}
void uf_unite(int a,int b){
a=uf_root(a);
b=uf_root(b);
if(a!=b){
if(ufbuf[a].u<ufbuf[b].u){
ufbuf[b].v-=ufbuf[a].v;
ufbuf[a].u+=ufbuf[b].u;
ufbuf[b].u=a;
}else{
ufbuf[a].v-=ufbuf[b].v;
ufbuf[b].u+=ufbuf[a].u;
ufbuf[a].u=b;
}
}
}
char wbuf[1<<25];
int main(){
uf_init();
rd_init();
int n=rd();
rd_skip();
char*wp=wbuf;
while(*rp){
int t=*rp; rp+=2;
int a=rd();
if(t=='1'){
int b=rd();
uf_unite(a,b);
}
if(t=='2'){
int b=rd_signed();
ufbuf[uf_root(a)].v+=b;
}
if(t=='3'){
rp+=2;
int z=0;
while(z+=ufbuf[a].v,a=ufbuf[a].u,a>=0);
if(z<0){
*wp++='-';
z=-z;
}
wt(z);
*wp++='\n';
}
}
write(1,wbuf,wp-wbuf);
_exit(0);
}
tails