QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#380863#8049. Equal Sumsucup-team2230#TL 0ms7340kbC++233.0kb2024-04-07 13:52:522024-04-07 13:52:53

Judging History

你现在查看的是最新测评结果

  • [2024-04-07 13:52:53]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:7340kb
  • [2024-04-07 13:52:52]
  • 提交

answer

#ifndef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#endif

#include <bits/stdc++.h>
using namespace std;

using ll=long long;
using uint=unsigned;

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define si(x) int(x.size())
#define a first
#define b second
template<class t>using vc=vector<t>;
template<class t,class u>bool chmax(t&a, u b){ if(a<b){a=b;return 1;}return 0;}
template<class t,class u>bool chmin(t&a,u b){if(a>b){a=b;return 1;}return 0;}

using P=pair<int,int>;

const uint mod=998244353;
struct mint{
	uint v;
	mint(ll vv=0){s(vv%mod+mod);}
	mint& s(uint vv){
		v=vv<mod?vv:vv-mod;
		return *this;
	}
	mint operator-()const{return mint()-*this;}
	mint&operator+=(mint r){return s(v+r.v);}
	mint&operator-=(mint r){return s(v+mod-r.v);}
	mint&operator*=(mint r){v=(unsigned long long)v*r.v%mod; return *this;}
	mint&operator/=(mint r){return *this*=r.inv();}
	mint operator+(mint r)const{return mint(*this)+=r;}
	mint operator-(mint r)const{return mint(*this)-=r;}
	mint operator*(mint r)const{return mint(*this)*=r;}
	mint operator/(mint r)const{return mint(*this)/=r;}
	mint pow(ll n)const{
		if(n<0)return inv(),pow(-n);
		mint res(1),x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}
	mint inv()const{return pow(mod-2);}
};

void solve(){
	int n,m;
	cin>>n>>m;
	vc<P> A(n),C(m);
	for(int i=0;i<n;i++) cin>>A[i].a>>A[i].b;
	for(int i=0;i<m;i++){
		cin>>C[i].b>>C[i].a;
		C[i].a*=-1;
		C[i].b*=-1;
	}
	int M=505;
	int B=2*M*M;
	vc<mint> dp(2*B);
	dp[B]=1;
	vc<vc<mint>> ans(n,vc<mint>(m));
	
	auto add=[&](int l,int r,P p){
		//cerr<<l<<" "<<r<<" "<<p.a<<" "<<p.b<<endl;
		mint sum=0;
		if(p.a<0){
			for(int i=l-p.b;i<=l-p.a;i++) sum+=dp[i];
			for(int i=l;i<r;i++){
				dp[i]=sum;
				sum-=dp[i-p.b];
				sum+=dp[i-p.a+1];
			}
		} else{
			for(int i=r-p.b;i<=r-p.a;i++) sum+=dp[i];
			for(int i=r-1;i>=l;i--){
				sum+=dp[i-p.b];
				sum-=dp[i-p.a+1];
				dp[i]=sum;
			}
		}
		//for(int i=B-5;i<=B+5;i++) cout<<dp[i].v<<" ";cout<<endl;
	};
	auto rec=[&](int a,int b,int c,int d,auto self)->void{
		//cerr<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
		if(a==b||c==d) return;
		int L=(b-a)+(d-c);
		int l=B-L*M,r=B+L*M;
		vc<mint> cur(2*L*M);
		for(int i=l;i<r;i++) cur[i-l]=dp[i];
		if(a+1==b&&c+1==d){
			//for(int i=B-5;i<=B+5;i++) cout<<dp[i].v<<" ";cout<<endl;
			add(l,r,A[a]);
			add(l,r,C[c]);
			ans[a][c]=dp[B];
		} else{
			int ma=(a+b)/2,mc=(c+d)/2;
			self(a,ma,c,mc,self);
			for(int i=a;i<ma;i++) add(l,r,A[i]);
			self(ma,b,c,mc,self);
			for(int i=c;i<mc;i++) add(l,r,C[i]);
			self(ma,b,mc,d,self);
			for(int i=l;i<r;i++) dp[i]=cur[i-l];
			for(int i=c;i<mc;i++) add(l,r,C[i]);
			self(a,ma,mc,d,self);
		}
		for(int i=l;i<r;i++) dp[i]=cur[i-l];
	};
	rec(0,n,0,m,rec);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cout<<ans[i][j].v<<" ";
		}cout<<endl;
	}
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 7340kb

input:

2 3
1 2
2 3
1 4
2 2
1 3

output:

2 0 0 
3 4 4 

result:

ok 6 numbers

Test #2:

score: -100
Time Limit Exceeded

input:

500 500
19 458
1 480
7 485
50 461
12 476
15 461
48 466
40 453
46 467
9 458
27 478
26 472
46 459
29 490
6 500
17 487
48 484
28 472
28 459
25 480
4 491
29 481
36 460
2 491
44 499
22 473
20 458
4 483
27 471
2 496
11 461
43 450
2 478
37 466
15 459
42 482
7 451
19 455
2 453
47 475
48 450
1 474
46 471
9 4...

output:


result: