QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#747777#9631. Median ReplacementyhdddWA 1096ms17744kbC++142.1kb2024-11-14 18:14:092024-11-14 18:14:12

Judging History

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

  • [2024-11-14 18:14:12]
  • 评测
  • 测评结果:WA
  • 用时:1096ms
  • 内存:17744kb
  • [2024-11-14 18:14:09]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define db double
using namespace std;
const int maxn=200010;
const int inf=1e18;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
	return x*f;
}
bool Mbe;

int n,ans;
int l[maxn],r[maxn];
int lsh[maxn],len;
int x[maxn],y[maxn];
int dp[maxn][2][2];
int calc(int v){
	mems(dp,0);dp[0][0][0]=1;
	int mul=1;
	for(int i=1;i<=n;i++){
		int len=r[i]-l[i]+1,l1=max(0ll,min(len,v-l[i])),l2=max(0ll,min(len,r[i]-v+1));
		dp[i][0][0]=(dp[i-1][0][0]+dp[i-1][1][0])*l1%mod;
		dp[i][0][1]=dp[i-1][0][0]*l2%mod;
		dp[i][1][0]=dp[i-1][0][1]*l1%mod;
		mul=mul*len%mod;
	}
	return (mul+3*mod-dp[n][0][0]-dp[n][0][1]-dp[n][1][0])%mod;
}
inline int ksm(int a,int b=mod-2){
	int ans=1;
	while(b){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
int lag(int k,int v){
	int res=0;
	for(int i=1;i<=k;i++){
		int mul1=1,mul2=1;
		for(int j=1;j<=k;j++)if(i!=j){
			mul1=mul1*(v+mod-x[j]);
			mul2=mul2*(x[i]+mod-x[j]);
		}
		(res+=y[i]*mul1%mod*ksm(mul2))%=mod;
	}
	return res;
}
void work(){
	n=read();ans=0;
	for(int i=1;i<=n;i++)l[i]=read();
	for(int i=1;i<=n;i++)r[i]=read();
	lsh[len=1]=1;
	for(int i=1;i<=n;i++)lsh[++len]=l[i],lsh[++len]=r[i]+1;
	sort(lsh+1,lsh+len+1),len=unique(lsh+1,lsh+len+1)-lsh-1;
	for(int i=1;i<len;i++){
		int ll=lsh[i],rr=lsh[i+1]-1;
		int k=min(rr-ll+1,100ll);
		for(int j=ll;j<=ll+k-1;j++){
			x[j-ll+1]=j;
			y[j-ll+1]=calc(j);
		}
		for(int j=1;j<=k;j++)(y[j]+=y[j-1])%=mod;
		if(rr-ll+1==k)ans+=y[rr-ll+1];
		else ans+=lag(k,rr);
	}
	printf("%lld\n",ans);
}


// \
444

bool Med;
int T;
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	
//	cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
	
	T=read();
	while(T--)work();
}

詳細信息

Test #1:

score: 100
Accepted
time: 35ms
memory: 16424kb

input:

10
5
5 1 4 3 2
14 2 5 3 2
5
4 5 1 2 3
13 7 1 2 3
5
5 2 5 3 1
10 2 12 3 2
5
5 5 3 1 5
57 5 3 1 5
5
2 2 3 3 5
4 5 4 4 5
5
4 5 3 5 3
13 7 3 5 3
5
5 1 4 2 3
14 3 4 2 3
5
1 2 5 4 5
2 8 5 7 5
5
1 1 3 5 1
8 2 3 8 1
5
4 4 4 2 3
5 10 5 2 3

output:

180
170
650
265
182
173
120
296
192
131

result:

ok 10 lines

Test #2:

score: 0
Accepted
time: 23ms
memory: 17012kb

input:

10
5
1 2 2 5 3
6 4 2 6 3
5
4 4 1 4 3
6 7 2 5 3
5
5 3 4 2 4
5 7 5 2 6
5
1 5 3 5 2
7 7 3 5 2
5
1 3 3 2 2
10 5 3 2 2
5
4 4 4 5 3
4 11 9 5 3
5
5 3 2 1 3
13 5 2 1 5
5
5 4 1 2 5
10 6 1 2 5
5
3 5 3 4 2
5 9 3 5 2
5
1 1 3 2 1
7 3 3 3 1

output:

120
230
144
110
110
289
324
89
140
122

result:

ok 10 lines

Test #3:

score: 0
Accepted
time: 35ms
memory: 17744kb

input:

10
5
3 1 3 4 4
9 1 3 10 4
5
1 1 3 1 1
9 1 3 3 1
5
5 1 2 3 1
74 1 2 3 1
5
2 5 5 3 4
5 6 8 3 4
5
2 1 3 4 5
2 4 6 4 5
5
2 4 2 1 3
2 11 3 2 3
5
1 5 4 4 2
1 14 6 6 2
5
4 1 3 5 1
9 2 4 5 1
5
4 1 2 4 4
6 1 6 4 4
5
3 2 5 3 5
8 8 5 3 5

output:

196
76
140
172
72
80
486
84
65
224

result:

ok 10 lines

Test #4:

score: -100
Wrong Answer
time: 1096ms
memory: 17688kb

input:

10
5
676437428 903889545 700650370 965758082 146716866
676437431 903889567 700650370 965758082 146716866
5
517457740 64600397 388618400 783268973 388618400
517457797 64600397 388618400 783268973 388618400
5
971452763 106948541 259878781 537741075 9504353
971452780 106948544 259878781 537741075 95043...

output:

1656
116
432
8280
1176
504
576
1386
1232
9118

result:

wrong answer 1st lines differ - expected: '157838571', found: '1656'