HDU 5475(2015 ICPC上海站网络赛)--- An easy…
2018-06-17 23:39:11来源:未知 阅读 ()
题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=5475
1. multiply X with a number.
2. divide X with a number which was multiplied before.
After each operation, please output the number X modulo M.
For each test case, the first line are two integers Q and M. Q is the number of operations and M is described above. (1≤Q≤105,1≤M≤109)
The next Q lines, each line starts with an integer x indicating the type of operation.
if x is 1, an integer y is given, indicating the number to multiply. (0<y≤109)
if x is 2, an integer n is given. The calculator will divide the number which is multiplied in the nth operation. (the nth operation must be a type 1 operation.)
It's guaranteed that in type 2 operation, there won't be two same n.
Then Q lines follow, each line please output an answer showed by the calculator.
#include <iostream> #include <algorithm> #include <stdio.h> #include <cstring> #include <cmath> #include <map> #include <bitset> using namespace std; typedef long long LL; LL mod; LL tr[4*100005]; int p; LL add; void build(int l,int r,int i) { if(l==r) { tr[i]=1; return ; } int mid=(l+r)>>1; build(l,mid,i<<1); build(mid+1,r,i<<1|1); tr[i]=1; } void update(int l,int r,int i) { if(l==r) { tr[i]=add; return ; } int mid=(l+r)>>1; if(p<=mid) update(l,mid,i<<1); else update(mid+1,r,i<<1|1); tr[i]=(tr[i<<1]*tr[i<<1|1])%mod; } int main() { int T,Q,Case=1; cin>>T; while(T--) { scanf("%d%lld",&Q,&mod); printf("Case #%d:\n",Case++); build(1,Q,1); for(int i=1;i<=Q;i++) { int x; LL y; scanf("%d%lld",&x,&y); if(x==1) { p=i; add=y; } else { p=y; add=1; } update(1,Q,1); printf("%lld\n",tr[1]); } } return 0; }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- bzoj4036 [HAOI2015]按位或 2020-04-26
- HDU-2955-Robberies(0-1背包) 2020-03-30
- hdu1455 拼木棍(经典dfs) 2020-02-29
- anniversary party_hdu1520 2020-02-16
- hdu1062 text reverse 2020-01-27
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash