提出 #74302172


ソースコード 拡げる

#include<bits/stdc++.h>
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
bool st;
using namespace std;
/*Ctrl+Alt+G F*/
namespace AC{
namespace Fread{const int SIZE=1<<16;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return *S++;}}namespace Fwrite{const int SIZE=1<<16;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
#define Setprecision 15
#define between ' '
template<typename T>struct is_char{static constexpr bool value=(std::is_same<T,char>::value||std::is_same<T,signed char>::value||std::is_same<T,unsigned char>::value);};template<typename T>struct is_integral_ex{static constexpr bool value=(std::is_integral<T>::value||std::is_same<T,__int128>::value)&&!is_char<T>::value;};template<typename T>struct is_floating_point_ex{static constexpr bool value=std::is_floating_point<T>::value||std::is_same<T,__float128>::value;};namespace Fastio{struct Reader{template<typename T>typename std::enable_if_t<std::is_class<T>::value,Reader&>operator>>(T&x){for(auto &y:x)*this>>y;return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1,s=0;x=0;T t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Reader&>operator>>(T&c){c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';struct Writer{typedef __int128 mxdouble;template<typename T>typename std::enable_if_t<std::is_class<T>::value,Writer&>operator<<(T x){for(auto &y:x)*this<<y<<between;*this<<'\n';return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Writer&>operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Writer&>operator<<(T x){if(x<0)putchar('-'),x=-x;x+=pow(10,-Setprecision)/2;mxdouble _=x;x-=(T)_;static int sta[45];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;putchar('.');for(int i=0;i<Setprecision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<Setprecision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Writer&>operator<<(T c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}Writer&operator<<(std::string str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}void flush(){Fwrite::flush();}}cout;}
#undef Setprecision
using Fastio::cin;
using Fastio::cout;
using Fastio::endl;
using istream=Fastio::Reader;
using ostream=Fastio::Writer;

const int mod=998244353;
const int inv=499122177;
#define lc p<<1
#define rc p<<1|1
#define mid ((l+r)>>1)
#define lson lc,l,mid
#define rson rc,mid+1,r
struct Node{
	int sum,mul;
}tr[4*200010];
void pushdown(int p,int l,int r){
	if(tr[p].mul!=1){
		tr[lc].sum=(tr[lc].sum*tr[p].mul)%mod;
		tr[lc].mul=(tr[lc].mul*tr[p].mul)%mod;
		tr[rc].sum=(tr[rc].sum*tr[p].mul)%mod;
		tr[rc].mul=(tr[rc].mul*tr[p].mul)%mod;
		tr[p].mul=1;
	}
}
void build(int p,int l,int r){
	tr[p].sum=0;
	tr[p].mul=1;
	if(l==r)return;
	build(lson);
	build(rson);
}
void update1(int p,int l,int r,int ul,int ur,int val){
	if(ur<l||ul>r)return;
	if(ul<=l&&r<=ur){
		tr[p].sum=(tr[p].sum*val)%mod;
		tr[p].mul=(tr[p].mul*val)%mod;
		return;
	}
	pushdown(p,l,r);
	update1(lson,ul,ur,val);
	update1(rson,ul,ur,val);
	tr[p].sum=(tr[lc].sum+tr[rc].sum)%mod;
}
void update2(int p,int l,int r,int pos,int val){
	if(l==r){
		tr[p].sum=val%mod;
		tr[p].mul=1;
		return;
	}
	pushdown(p,l,r);
	if(pos<=mid)update2(lson,pos,val);
	else update2(rson,pos,val);
	tr[p].sum=(tr[lc].sum+tr[rc].sum)%mod;
}
int query(int p,int l,int r,int ql,int qr){
	if(qr<l||ql>r)return 0;
	if(ql<=l&&r<=qr)return tr[p].sum;
	pushdown(p,l,r);
	return(query(lson,ql,qr)+query(rson,ql,qr))%mod;
}
vector<int>g[200010];
int d[200010];
void solve(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;++i){
		int X,Y;
		cin>>X>>Y;
		g[Y].push_back(X);
		d[X]++;
		d[Y]--;
	}
	vector<int>b(n+1,0);
	for(int k=1;k<=n;++k)b[k]=b[k-1]+d[k];
	vector<int>pw2(m+1);
	pw2[0]=1;
	for(int i=1;i<=m;++i)pw2[i]=(pw2[i-1]*2)%mod;
	build(1,1,n);
	int ans=0,pre=0,now=g[1].size();
	int val=(1-query(1,1,n,1,0)+mod)%mod;
	update2(1,1,n,1,val);
	if(1<=n-1){
		int tmp=m-b[1];
		int cnt=val*pw2[tmp]%mod;
		ans=(ans+cnt)%mod;
	}
	pre=now;
	for(int k=2;k<=n;++k){
		now=pre+g[k].size();
		for(int x:g[k])update1(1,1,n,x,n,inv);
		val=(1-query(1,1,n,1,k-1)+mod)%mod;
		update2(1,1,n,k,val);
		if(k<=n-1){
			int tmp=m-b[k];
			int cnt=val*pw2[tmp]%mod;
			ans=(ans+cnt)%mod;
		}
		pre=now;
	}
	cout<<(pw2[m]-ans+mod)%mod<<endl;
}

}
bool ed;
signed main(){
#ifdef debug
	cerr<<"----------------------------------- START -----------------------------------\n";
#endif
	int t=1;
	//cin>>t;
	while(t--)AC::solve();
#ifdef debug
	cerr<<"\n--------------------------------- INPUT END ---------------------------------\n";
	AC::cout.flush();
	cerr<<"\n------------------------------------ END ------------------------------------\n";
	cerr<<setprecision(3)<<fixed<<"Total Memory : "<<left<<setw(10)<<(&ed-&st)/1048576.0<<" \tMB\n"<<"               "<<left<<setw(10)<<(&ed-&st)/1024.0<<" \tKB\n"<<"               "<<left<<setw(10)<<(&ed-&st)<<" \tByte\n";
#endif
}

提出情報

提出日時
問題 F - Strongly Connected 2
ユーザ nut321
言語 C++23 (GCC 15.2.0)
得点 525
コード長 6789 Byte
結果 AC
実行時間 162 ms
メモリ 27212 KiB

コンパイルエラー

./Main.cpp: In function 'void AC::pushdown(long long int, long long int, long long int)':
./Main.cpp:33:25: warning: unused parameter 'l' [-Wunused-parameter]
   33 | void pushdown(int p,int l,int r){
      |                         ^
./Main.cpp:33:31: warning: unused parameter 'r' [-Wunused-parameter]
   33 | void pushdown(int p,int l,int r){
      |                               ^

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 525 / 525
結果
AC × 2
AC × 24
セット名 テストケース
Sample sample_01.txt, sample_02.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, sample_01.txt, sample_02.txt
ケース名 結果 実行時間 メモリ
min.txt AC 2 ms 3416 KiB
random_01.txt AC 162 ms 24712 KiB
random_02.txt AC 35 ms 11344 KiB
random_03.txt AC 162 ms 24908 KiB
random_04.txt AC 23 ms 7684 KiB
random_05.txt AC 161 ms 24724 KiB
random_06.txt AC 13 ms 5016 KiB
random_07.txt AC 161 ms 24784 KiB
random_08.txt AC 73 ms 19668 KiB
random_09.txt AC 162 ms 24724 KiB
random_10.txt AC 62 ms 10840 KiB
random_11.txt AC 161 ms 24916 KiB
random_12.txt AC 62 ms 18140 KiB
random_13.txt AC 161 ms 24784 KiB
random_14.txt AC 60 ms 9736 KiB
random_15.txt AC 161 ms 24708 KiB
random_16.txt AC 54 ms 17412 KiB
random_17.txt AC 67 ms 13892 KiB
random_18.txt AC 42 ms 8260 KiB
random_19.txt AC 63 ms 18252 KiB
random_20.txt AC 136 ms 27212 KiB
random_21.txt AC 60 ms 13028 KiB
sample_01.txt AC 2 ms 3588 KiB
sample_02.txt AC 2 ms 3480 KiB