思路:在单调队列不更新列首,因为查询区间大小不确定,所以不能保证下次是否还用到它
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define N 222222 #define ll long long int que[N]; ll m,d; ll a[N]; int cnt; char op[2]; int num; int main(){ scanf("%d%lld",&m,&d); cnt = 0; ll t = 0; int l = 0; int r = -1; while(m--){ scanf("%s%d",op,&num); if(op[0]=='Q'){ int h = l; while(h<=r&&que[h]<=cnt-num) h++; t = a[que[h]]; printf("%lld\n",t); } else{ a[++cnt] = (num%d+t%d)%d; while(l<=r&&a[que[r]]<a[cnt]) --r; que[++r] = cnt; } } }
版权声明:都是兄弟,请随意转载,请注明兄弟是谁
时间: 2024-11-04 04:10:22