记录编号 253100 评测结果 AAAAAAAAAA
题目名称 魔法传输 最终得分 100
用户昵称 Gravatar咸鱼二号 是否通过 通过
代码语言 C++ 运行时间 0.428 s
提交时间 2016-04-21 19:03:29 内存使用 12.52 MiB
显示代码纯文本
  1. #include<iostream>
  2. #include<cstring>
  3. #include<cstdio>
  4. #include<string>
  5. #include<algorithm>
  6. #include<cmath>
  7. #include<utility>
  8. #include<cstdlib>
  9. #include<iomanip> //cout<<setiosflags(ios::fixed)<<setprecision(2);
  10. #include<ctime> //double a=(double)clock(); cout<<a<<endl;
  11. #include<vector>
  12. #include<queue>
  13. using namespace std;
  14. const int maxn=100010;
  15. inline int read(){
  16. int x=0,ff=1;char ch=getchar();
  17. while(ch>'9'||ch<'0'){if(ch=='-')ff=-1; ch=getchar();}
  18. while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();}
  19. return ff*x;
  20. }
  21. char ch;
  22. int N,M,t1,t2;
  23. struct seg{
  24. long long k,b,tagk,tagb;
  25. }T[maxn<<2];
  26. inline void push_down(int root){
  27. if(T[root].tagk){
  28. T[root<<1].k+=T[root].tagk;
  29. T[root<<1].tagk+=T[root].tagk;
  30. T[root<<1|1].k+=T[root].tagk;
  31. T[root<<1|1].tagk+=T[root].tagk;
  32. T[root].tagk=0;
  33. }
  34. if(T[root].tagb){
  35. T[root<<1].b+=T[root].tagb;
  36. T[root<<1].tagb+=T[root].tagb;
  37. T[root<<1|1].b+=T[root].tagb;
  38. T[root<<1|1].tagb+=T[root].tagb;
  39. T[root].tagb=0;
  40. }
  41. }
  42. void update(int L,int R,int root,int l,int r){
  43. if(l<=L&&r>=R){
  44. T[root].k++;
  45. T[root].tagk++;
  46. T[root].b+=-l+1;
  47. T[root].tagb+=-l+1;
  48. return;
  49. }
  50. push_down(root);
  51. int mid=(L+R)>>1;
  52. if(l<=mid)
  53. update(L,mid,root<<1,l,r);
  54. if(r>mid)
  55. update(mid+1,R,root<<1|1,l,r);
  56. }
  57. long long ansk,ansb;
  58. void query(int L,int R,int root,int point){
  59. if(L==R){
  60. ansk=T[root].k;
  61. ansb=T[root].b;
  62. return;
  63. }
  64. push_down(root);
  65. int mid=(L+R)>>1;
  66. if(point<=mid)
  67. query(L,mid,root<<1,point);
  68. else
  69. query(mid+1,R,root<<1|1,point);
  70. }
  71. int main(){
  72. freopen("magics.in","r",stdin);
  73. freopen("magics.out","w",stdout);
  74. N=read(),M=read();
  75. while(M--){
  76. ch=getchar();
  77. while(ch!='C'&&ch!='Q')
  78. ch=getchar();
  79. if(ch=='C'){
  80. t1=read(),t2=read();
  81. update(1,N,1,t1,t2);
  82. }
  83. else{
  84. t1=read();
  85. query(1,N,1,t1);
  86. printf("%lld\n",(ansk*t1+ansb)%1000000007);
  87. }
  88. }
  89. return 0;
  90. }