传送门http://acm.hdu.edu.cn/showproblem.php?pid=5475
题意:
给定一个x,初值为1
有以下两种操作:
1、乘以k
2、除以第k次操作的所乘的值
线段树单点更新问题,查询的时候只需要输出v[1]的值即可。
具体看下代码就好了。
另外,这题xjb暴力可以卡时过掉,亲测。
(其实本来并不想写这个题解,这题真的是An easy problem。但是看到这道题的时候想起了去年多校的尴尬情况 ,随手一写吧= =!具体细节不可描述=。=)
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
typedef long long ll;
const int INF=0x3f3f3f3f;
const int maxn=1e5+10;
int T,n,mod;
ll v[maxn<<2];
void PushUp(int rt){
v[rt]=(v[rt<<1]*v[rt<<1|1])%mod;
}
void build(int rt,int l,int r){
v[rt]=1;
if(l==r) return ;
int mid=(l+r)>>1;
build(lson);
build(rson);
}
void Update(int rt,int l,int r,int pos,int val){
if(l==r){
v[rt]=val;
return ;
}
int mid=(l+r)>>1;
if(pos<=mid) Update(lson,pos,val);
else Update(rson,pos,val);
PushUp(rt);
}
int main(){
#ifndef ONLINE_JUDGE
freopen("test.in","r",stdin);
freopen("test.out","w",stdout);
#endif
scanf("%d",&T);
int cas=1;
while(T--){
scanf("%d%d",&n,&mod);
printf("Case #%d:\n",cas++);
build(1,1,n);
int op,k;
for(int i=1;i<=n;i++){
scanf("%d%d",&op,&k);
if(op==1){
Update(1,1,n,i,k);
}
else{
Update(1,1,n,k,1);
}
printf("%lld\n",v[1]);
}
}
return 0;
}