結果
| 問題 | No.1054 Union add query |
| コンテスト | |
| ユーザー |
👑 tails
|
| 提出日時 | 2023-03-13 18:57:26 |
| 言語 | C90(gcc15) (gcc 15.2.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,414 bytes |
| 記録 | |
| コンパイル時間 | 99 ms |
| コンパイル使用メモリ | 29,320 KB |
| 最終ジャッジ日時 | 2026-02-24 01:13:18 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.c:6:1: error: C++ style comments are not allowed in ISO C90
6 | //#define rd() ({int _v=0,_c;while(_c=*rp++-48,_c>=0)_v=_v*10+_c;_v;})
| ^
main.c:6:1: note: (this will be reported only once per input file)
main.c:22:14: error: expected ';' before 'int'
22 | static inline int getuint(char**rpp) {
| ^~~~
| ;
main.c:34:14: error: expected ';' before 'int'
34 | static inline int getint(char**rpp) {
| ^~~~
| ;
main.c: In function 'uf_init':
main.c:45:9: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
45 | for(int i=0;i<UFSIZE;++i){
| ^~~
main.c:45:9: note: use option '-std=c99', '-std=gnu99', '-std=c11' or '-std=gnu11' to compile your code
ソースコード
#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