QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#114271 | #5976. Fairland | zwh2008 | 12 ✓ | 5945ms | 42688kb | C++14 | 1.3kb | 2023-06-21 19:54:51 | 2023-06-21 19:54:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5;
int n,D,now,cnt,Case,fa[N],h[N],S[N];
bool ok[N],vis[N];
struct node{int x,d;}a[N];
struct edge{int n,t;}e[N];
void add(int x,int y){e[++cnt]={h[x],y},h[x]=cnt;}
void dfs1(int x){ok[x]=1,now++;for(int i=h[x];i;i=e[i].n)if(vis[e[i].t])dfs1(e[i].t);}
void dfs2(int x){ok[x]=0,now--;for(int i=h[x];i;i=e[i].n)if(ok[e[i].t])dfs2(e[i].t);}
void Add(int x){vis[x]=1;if(x==1||ok[fa[x]])dfs1(x);}
void Del(int x){vis[x]=0;if(ok[x])dfs2(x);}
//int find(int x,int k) {
// if(S[x]<k||S[x]>k+D)return 0;
// int res=1;
// for(int i=h[x];i;i=e[i].n)res+=find(e[i].t,k);
// return res;
//}
void solve() {
int as,cs,rs,am,cm,rm;a[1].x=1,now=cnt=0,memset(h,0,sizeof(h));
scanf("%d%d%d%d%d%d%d%d%d%d",&n,&D,&a[1].d,&as,&cs,&rs,fa+1,&am,&cm,&rm),S[1]=a[1].d;
for(int i=2;i<=n;i++)a[i]={i,(int)(1ll*a[i-1].d*as+cs)%rs},fa[i]=(1ll*fa[i-1]*am+cm)%rm,S[i]=a[i].d;
for(int i=2;i<=n;i++)fa[i]=fa[i]%(i-1)+1,add(fa[i],i);fa[1]=0;
sort(a+1,a+n+1,[](const node &x,const node &y){return x.d<y.d;});
int j=0,ans=0;
for(int i=1;i<=n;i++) {
while(j<n&&a[j+1].d<=a[i].d+D)Add(a[++j].x);
ans=max(ans,now),Del(a[i].x);
}
printf("Case #%d: %d\n",++Case,ans);
}
int main() {
int tt;scanf("%d",&tt);
while(tt--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 20ms
memory: 15928kb
input:
100 863 737 147 1 1 826 830 1 1 831 186 768 267 527 792527137 526 81 13 460856586 342 848 696 135 1 1 787 813 1 1 814 987 668 157 1 1 892 255 326 108399179 710 728 169 323 210 682026321 585 750 85 977096686 799 915 725 167 1 1 866 813 1 1 814 816 381 670 1 1 744 429 1 1 430 688 569 579 848 252088721...
output:
Case #1: 710 Case #2: 186 Case #3: 685 Case #4: 757 Case #5: 2 Case #6: 775 Case #7: 143 Case #8: 20 Case #9: 824 Case #10: 14 Case #11: 2 Case #12: 7 Case #13: 917 Case #14: 3 Case #15: 184 Case #16: 831 Case #17: 1 Case #18: 28 Case #19: 840 Case #20: 855 Case #21: 54 Case #22: 751 Case #23: 959 C...
result:
ok 100 lines
Subtask #2:
score: 9
Accepted
Test #2:
score: 9
Accepted
time: 5945ms
memory: 42688kb
input:
100 1000 700 1 1 1 1000 999 1 1 1000 868238 873094 175212 1 946155217 409436 809287 1 1 809288 854112 678623 130672 1 1 789040 845767 1 1 845768 814744 420144 420003 1 1 803202 800344 1 1 800345 864316 383539 632857 1 1 703161 615175 55 522100274 984097 877988 440499 469030 1 1 839327 469558 1 1 469...
output:
Case #1: 701 Case #2: 868238 Case #3: 666711 Case #4: 397597 Case #5: 149304 Case #6: 441030 Case #7: 1 Case #8: 275 Case #9: 180781 Case #10: 1000000 Case #11: 28 Case #12: 841641 Case #13: 816914 Case #14: 149415 Case #15: 190850 Case #16: 973999 Case #17: 729036 Case #18: 688880 Case #19: 813175 ...
result:
ok 100 lines
Extra Test:
score: 0
Extra Test Passed