提出 #49501026


ソースコード 拡げる

#include<cstdio>
typedef long long ll;
constexpr int N(200010);
int n,head[N],to[N<<1],nxt[N<<1],fa[N],dfn[N],siz[N];ll bit[2][N];
void add(const int flg,int i,const ll x){
  for(;i<=n;i+=i&-i)bit[flg][i]+=x;}
ll query(const int flg,int i){
  ll res(0);for(;i;i-=i&-i)res+=bit[flg][i];return res;}
void dfs(const int i){
  static int dfc;dfn[i]=++dfc;
  for(int j(head[i]);j;j=nxt[j])if(j!=fa[i])
    fa[to[j]]=j^1,dfs(to[j]),siz[i]+=siz[to[j]];}
int main(){scanf("%d",&n);
  for(int i(1),u,v;i<n;++i)scanf("%d%d",&u,&v),
    to[i<<1]=u,nxt[i<<1]=head[v],head[v]=i<<1,
    to[i<<1|1]=v,nxt[i<<1|1]=head[u],head[u]=i<<1|1;
  for(int i(1);i<=n;++i)siz[i]=1;
  dfs(1);for(int i(1);i<=n;++i){
    ll x(i-1-query(0,dfn[i]+siz[i]-1)+query(0,dfn[i]-1));
    add(1,dfn[i],x);add(1,dfn[i]+siz[i],-x);
    for(int j(head[i]);j;j=nxt[j])if(j!=fa[i])
      x=query(0,dfn[to[j]]+siz[to[j]]-1)-query(0,dfn[to[j]]-1),
      add(1,1,x),add(1,dfn[to[j]],-x),add(1,dfn[to[j]]+siz[to[j]],x);
    add(0,dfn[i],1);}
  for(int i(1);i<=n;++i)printf("%lld ",query(1,dfn[i]));
  return 0;}

提出情報

提出日時
問題 G - Tree Inversion
ユーザ danielqf
言語 C++ 20 (gcc 12.2)
得点 600
コード長 1091 Byte
結果 AC
実行時間 126 ms
メモリ 24408 KiB

コンパイルエラー

Main.cpp: In function ‘int main()’:
Main.cpp:13:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 | int main(){scanf("%d",&n);
      |            ~~~~~^~~~~~~~~
Main.cpp:14:33: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |   for(int i(1),u,v;i<n;++i)scanf("%d%d",&u,&v),
      |                            ~~~~~^~~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 3
AC × 72
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt, 01_random_53.txt, 01_random_54.txt, 01_random_55.txt, 01_random_56.txt, 01_random_57.txt, 01_random_58.txt, 01_random_59.txt, 01_random_60.txt, 01_random_61.txt, 01_random_62.txt, 01_random_63.txt, 02_handmade_64.txt, 02_handmade_65.txt, 02_handmade_66.txt, 02_handmade_67.txt, 02_handmade_68.txt, 02_handmade_69.txt, 02_handmade_70.txt, 02_handmade_71.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 1744 KiB
00_sample_01.txt AC 1 ms 1672 KiB
00_sample_02.txt AC 1 ms 1756 KiB
01_random_03.txt AC 73 ms 11088 KiB
01_random_04.txt AC 104 ms 23100 KiB
01_random_05.txt AC 112 ms 11336 KiB
01_random_06.txt AC 100 ms 11256 KiB
01_random_07.txt AC 72 ms 11004 KiB
01_random_08.txt AC 112 ms 19256 KiB
01_random_09.txt AC 98 ms 11208 KiB
01_random_10.txt AC 100 ms 11248 KiB
01_random_11.txt AC 74 ms 11088 KiB
01_random_12.txt AC 113 ms 23000 KiB
01_random_13.txt AC 116 ms 11316 KiB
01_random_14.txt AC 104 ms 11292 KiB
01_random_15.txt AC 71 ms 11104 KiB
01_random_16.txt AC 107 ms 19648 KiB
01_random_17.txt AC 97 ms 11252 KiB
01_random_18.txt AC 126 ms 11308 KiB
01_random_19.txt AC 71 ms 11108 KiB
01_random_20.txt AC 115 ms 22936 KiB
01_random_21.txt AC 108 ms 11248 KiB
01_random_22.txt AC 97 ms 11324 KiB
01_random_23.txt AC 72 ms 11100 KiB
01_random_24.txt AC 112 ms 21872 KiB
01_random_25.txt AC 95 ms 11316 KiB
01_random_26.txt AC 98 ms 11268 KiB
01_random_27.txt AC 71 ms 11064 KiB
01_random_28.txt AC 108 ms 21812 KiB
01_random_29.txt AC 98 ms 11224 KiB
01_random_30.txt AC 103 ms 11248 KiB
01_random_31.txt AC 3 ms 2084 KiB
01_random_32.txt AC 20 ms 6672 KiB
01_random_33.txt AC 53 ms 7316 KiB
01_random_34.txt AC 92 ms 10660 KiB
01_random_35.txt AC 38 ms 7076 KiB
01_random_36.txt AC 93 ms 10432 KiB
01_random_37.txt AC 9 ms 2788 KiB
01_random_38.txt AC 26 ms 5608 KiB
01_random_39.txt AC 10 ms 3744 KiB
01_random_40.txt AC 19 ms 4040 KiB
01_random_41.txt AC 85 ms 9728 KiB
01_random_42.txt AC 23 ms 5176 KiB
01_random_43.txt AC 57 ms 6972 KiB
01_random_44.txt AC 97 ms 10840 KiB
01_random_45.txt AC 11 ms 3364 KiB
01_random_46.txt AC 41 ms 8504 KiB
01_random_47.txt AC 3 ms 2152 KiB
01_random_48.txt AC 98 ms 10516 KiB
01_random_49.txt AC 39 ms 7296 KiB
01_random_50.txt AC 55 ms 7088 KiB
01_random_51.txt AC 38 ms 5712 KiB
01_random_52.txt AC 78 ms 11116 KiB
01_random_53.txt AC 110 ms 22080 KiB
01_random_54.txt AC 100 ms 11244 KiB
01_random_55.txt AC 97 ms 11204 KiB
01_random_56.txt AC 79 ms 11024 KiB
01_random_57.txt AC 114 ms 19592 KiB
01_random_58.txt AC 102 ms 11336 KiB
01_random_59.txt AC 102 ms 11312 KiB
01_random_60.txt AC 78 ms 11132 KiB
01_random_61.txt AC 111 ms 22972 KiB
01_random_62.txt AC 96 ms 11220 KiB
01_random_63.txt AC 100 ms 11316 KiB
02_handmade_64.txt AC 1 ms 1676 KiB
02_handmade_65.txt AC 0 ms 1756 KiB
02_handmade_66.txt AC 82 ms 24368 KiB
02_handmade_67.txt AC 83 ms 24356 KiB
02_handmade_68.txt AC 80 ms 24364 KiB
02_handmade_69.txt AC 83 ms 24364 KiB
02_handmade_70.txt AC 80 ms 24404 KiB
02_handmade_71.txt AC 80 ms 24408 KiB