結果

問題 No.2588 Increasing Record
ユーザー lgswdnlgswdn
提出日時 2024-01-16 17:47:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,779 bytes
コンパイル時間 3,901 ms
コンパイル使用メモリ 209,668 KB
実行使用メモリ 52,064 KB
最終ジャッジ日時 2024-01-16 17:47:36
合計ジャッジ時間 10,488 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
20,712 KB
testcase_01 AC 7 ms
20,712 KB
testcase_02 AC 7 ms
20,716 KB
testcase_03 AC 7 ms
20,712 KB
testcase_04 AC 7 ms
20,712 KB
testcase_05 AC 8 ms
20,712 KB
testcase_06 AC 7 ms
20,712 KB
testcase_07 AC 7 ms
20,712 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 7 ms
20,716 KB
testcase_12 AC 33 ms
23,224 KB
testcase_13 AC 34 ms
23,260 KB
testcase_14 AC 34 ms
23,256 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 237 ms
35,764 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 185 ms
51,932 KB
testcase_35 AC 204 ms
51,936 KB
testcase_36 AC 184 ms
52,064 KB
testcase_37 AC 228 ms
35,332 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

//vanitas vanitatum et omnia vanitas
#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();} 
  return x*w;
}

const int N=2e5+5,mod=998244353;
int n,f[N],id[N],m,dfn[N],sz[N],son[N],top[N],tick,fa[N],d[N],ans,s[N];
vi e[N],t[N];

int find(int i) {return i==id[i]?i:id[i]=find(id[i]);}
int lb(int x) {return x&-x;}
void add(int x,int y=0) {for(;x<=n;x+=lb(x)) s[x]=(s[x]+y)%mod;}
int qry(int x,int y=0) {for(;x;x-=lb(x)) y=(y+s[x])%mod; return y;}
int sum(int u,int v) {return (qry(dfn[u])+mod-qry(dfn[v]))%mod;}

void dfs1(int u) {
  for(int v:t[u]) {
    d[v]=d[u]+1; dfs1(v);
    if(sz[v]>sz[son[u]]) son[u]=v;
    sz[u]+=sz[v];
  } sz[u]++;
}
void dfs2(int u,int tp) {
  top[u]=tp; dfn[u]=++tick;
  if(son[u]) dfs2(son[u],tp);
  for(int v:t[u]) if(v!=son[u]) dfs2(v,v);
}
int lca(int u,int v) {
  for(;top[u]!=top[v];u=fa[top[u]])
    if(d[top[u]]<d[top[v]]) swap(u,v);
  return d[u]<d[v]?u:v;
}
bool cmp(const int &x,const int &y) {
  return dfn[x]<dfn[y];
}

signed main() {
  n=read(), m=read();
  rep(i,1,m) {
    int u=read(), v=read();
    if(u>v) swap(u,v);
    e[v].eb(u);
  }
  rep(i,1,n) id[i]=i;
  rep(i,1,n) {
    for(int j:e[i]) {
      j=find(j); if(j==i) continue;
      t[i].eb(j); id[j]=i; fa[j]=i;
    }
  }
  dfs1(n), dfs2(n,n);
  rep(i,1,n) {
    sort(e[i].begin(),e[i].end());
    if(e[i].size()) {
      f[i]=sum(e[i][0],i); int k=e[i].size(); 
      rep(j,1,k-1) f[i]=(f[i]+sum(e[i][j],lca(e[i][j],e[i][j-1])))%mod;
    } f[i]=(f[i]+1)%mod;
    add(dfn[i],f[i]), add(dfn[i]+sz[i],mod-f[i]);
  }
  rep(i,1,n) ans=(ans+f[i])%mod;
  printf("%lld\n",ans);
  return 0;
}
0