QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#143241#7028. Renaissance Past in NancySorting#AC ✓2876ms454176kbC++202.2kb2023-08-20 23:05:292023-08-20 23:05:30

Judging History

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

  • [2023-08-20 23:05:30]
  • 评测
  • 测评结果:AC
  • 用时:2876ms
  • 内存:454176kb
  • [2023-08-20 23:05:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
#define fi first
#define se second
int n,m;
int a[10001],b[10001];
vector<pair<int,int> >pos[10001];
int sz;
int s[140001][1001];
ll w[1001];
const int iu=1000;
void adopt(int id){
	for(int i=b[id]; i<=iu ;i++){
		w[i]+=w[i-b[id]];
		if(w[i]>=mod) w[i]-=mod;
	}
	for(int i=iu; i>=b[id]*(a[id]+1) ;i--){
		w[i]-=w[i-b[id]*(a[id]+1)];
		if(w[i]<0) w[i]+=mod;
	}
}
void solve(int l,int r){
	//cout << "solve " << l << ' ' << r << endl;
	if(l>r) return;
	int mid=(l+r)/2;
	for(int i=0; i<=iu ;i++) w[i]=0;
	w[0]=1;
	for(int i=mid; i>=l ;i--){
		adopt(i);
		pos[i].push_back({mid,++sz});
		for(int j=0; j<=iu ;j++) s[sz][j]=w[j];
	}
	for(int i=0; i<=iu ;i++) w[i]=0;
	w[0]=1;
	for(int i=mid+1; i<=r ;i++){
		adopt(i);
		pos[mid+1].push_back({i,++sz});
		for(int j=0; j<=iu ;j++) s[sz][j]=w[j];
	}
	solve(l,mid-1);
	solve(mid+2,r);
}
int c[1001],d[1001];
void load(int* e,int l,int r){
	int z;
	for(auto c:pos[l]){
		if(c.fi==r) z=c.se;
	}
	//cout << "load " << l << ' ' << r << ' ' << z << endl;
	for(int i=0; i<=iu ;i++) e[i]=s[z][i];
}
ll winter(int l,int r,int ql,int qr,int qc){
	int mid=(l+r)/2;
	if(qr<mid) return winter(l,mid-1,ql,qr,qc);
	if(ql>mid+1) return winter(mid+2,r,ql,qr,qc);
	//cout << "hi " << l << ' ' << r  << ' ' << ql << ' ' << qr << ' ' << mid << endl;
	if(ql!=mid+1) load(c,ql,mid);
	if(qr!=mid) load(d,mid+1,qr);
	if(ql==mid+1){
		for(int i=0; i<=iu ;i++) c[i]=0;
		c[0]=1;
	}
	if(qr==mid){
		for(int i=0; i<=iu ;i++) d[i]=0;
		d[0]=1;
	}
	ll res=0;
	ll sum=0;
	for(int i=0; i<=qc ;i++){
		sum+=c[i];
		if(sum>=mod) sum-=mod;
		res=(res+sum*d[qc-i])%mod;
	}
	return res;
}
void solve(int rr){
	cin >> n >> m;
	sz=0;
	for(int i=1; i<=n ;i++){
		cin >> a[i] >> b[i];
		pos[i].clear();
	}
	solve(1,n);
	ll ans=0;
	cout << "Case #" << rr << ":" << '\n';
	for(int i=1; i<=m ;i++){
		int l,r,c;cin >> l >> r >> c;
		l=(l+ans)%n+1;
		r=(r+ans)%n+1;
		if(l>r) swap(l,r);
		//cout << "FROG " << l << ' ' << r << endl;
		ans=winter(1,n,l,r,c);
		cout << ans << '\n';
	}
	
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	int t;cin >> t;
	for(int i=1; i<=t ;i++) solve(i);
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3816kb

input:

1
3 3
1 1
1 2
1 3
1 3 1
1 3 2
1 3 3

output:

Case #1:
2
3
4

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 2876ms
memory: 454176kb

input:

1000
13 17
24 7
20 6
16 11
3 27
23 7
14 13
18 29
7 9
1 11
4 25
3 25
14 1
31 9
5 7 933
9 9 439
2 9 677
9 12 978
2 6 479
2 4 893
1 9 953
2 7 927
3 4 718
8 12 973
9 12 766
7 8 293
4 8 331
6 11 865
12 13 834
5 12 475
3 8 762
74 47
3 604
3 355
2 738
2 552
2 622
3 198
2 817
14 116
2 659
1 962
1 784
2 669
...

output:

Case #1:
2280
21
1568333
9600
19200
1428
153600
153600
10
22800
320
68
4800
602566225
525
771665
7312668
Case #2:
1926
1085
15085974
134200734
52983637
741561
51
736633
22
414295
3207
109210
7812
18122
20709361
540077
2358
58507
9612
679839907
109366763
294
35
4690542
81375272
135
346774225
224116
2...

result:

ok 173268 lines