QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#143240 | #7028. Renaissance Past in Nancy | Sorting# | RE | 1ms | 3752kb | C++20 | 2.2kb | 2023-08-20 22:53:47 | 2023-08-20 22:53:51 |
Judging History
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(r<mid) return winter(l,mid-1,ql,qr,qc);
if(l>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);
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3752kb
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: -100
Runtime Error
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 ...