D. Array Repetition
1.C. Insert and Equalize2.C. Removal of Unattractive Pairs3.D. Jumping Through Segments4.E. Good Triples5.F. Shift and Reverse6.D. Yet Another Monster Fight7.A. Constructive Problems8.C. Game with Multiset9.A. Rating Increase10.B. Swap and Delete11.A. Problemsolving Log12.B. Preparing for the Contest13.C. Quests14.D. Three Activities15.E2. Game with Marbles (Hard Version)16.cf刷题有感17.A. Anonymous Informant18.A. Forked!19.B. Make Almost Equal With Mod20.C. Heavy Intervals21.D. Split Plus K22.A. 202323.B. Two Divisors24.C. Training Before the Olympiad25.D. Mathematical Problem26.F. Greetings27.C. Partitioning the Array28.G. Bicycles29.E. Eat the Chip30.G. Lights
31.D. Array Repetition
32.D. Berserk Monsters33.E. Increasing Subsequences34.D. Very Different Array35.G. Mischievous Shooter36.B. Plus-Minus Split37.B. A Balanced Problemset38.C. Did We Get Everything Covered39.D. Find the Different Ones!40.C. Grouping Increases41.D. Good Trip42.C. Physical Education Lesson43.E. Final Countdown44.D. Divisible Pairs45.G. Vlad and Trouble at MIT46.A. Brick Wall47.B. Minimize Inversions48.C. XOR-distance49.A. Moving Chips50.B. Monsters Attack!51.C. Find B52.D. Slimes53.C. Turtle Fingers: Count the Values of k54.D. Turtle Tenacity: Continual Mods55.D. Vlad and Division56.C. LR-remainders57.D. Lonely Mountain Dungeons分析
1.如果某次操作之后,数组的长度大于等于k,我们把这样的操作叫最后操作,且最后操作之后的操作都不用考虑,因为不会影响前面的数组,我们把这样
2.最后操作只有两种,一种是加法,一种是乘法
如果是加法,那么k一定等于此时数组的长度,对应的值一定是这次加法加上去的值,也就是末尾值
如果是乘法,那么分为两种一种是数组的长度恰好等于k,那么这次k对应的值也一定是这次操作过后的末尾值
如果k小于数组的长度,那么递归?分治?dp?反正k的值和上一次操作过后的数组的第
构建
记录每次操作后的数组长度和末尾值,循环找出数组长度大于等于k的操作,直到长度等于k,答案就是此时的末尾值
code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll last[1000005]={0};
ll len[100005]={0};
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t;
cin>>t;
while(t--)
{
ll n,q;
cin>>n>>q;
for(ll i=1;i<=n;i++)
{
ll op,x;
cin>>op>>x;
if(op==1)
{
last[i]=x;
len[i]=min(len[i-1]+1,(ll)2e18);
}
else
{
last[i]=last[i-1];
if((ll)2e18/(x+1)<len[i-1]) len[i]=2e18;//防止溢出
else len[i]=len[i-1]*(x+1);
}
}
while(q--)
{
ll k;
cin>>k;
ll times=lower_bound(len+1,len+n+1,k)-len;//如果k点是在某次加法后诞生的,那么一步到位
while(k!=len[times])
{
k=(k-1)%len[times-1]+1;//说明它在乘法之间,回溯等价于在上一步乘法的模数位置
times=lower_bound(len+1,len+n+1,k)-len;//有点像dp?递归?
}
cout<<last[times]<<" ";
}
cout<<endl;
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~