zoukankan      html  css  js  c++  java
  • hdu 5063 Operation the Sequence

    http://acm.hdu.edu.cn/showproblem.php?pid=5063

    思路:因为3查询最多50,所以可以在查询的时候逆操作找到原来的位置,然后再求查询的值。

     1 #include <cstdio>
     2 #include <iostream>
     3 #include <cstring>
     4 #include <algorithm>
     5 #define ll long long
     6 using namespace std;
     7 const int mod=1000000007;
     8 
     9 int n,m;
    10 char str[1000];
    11 int a[100010];
    12 
    13 ll pow_mod(ll a,ll p,ll n)
    14 {
    15     if(p==0) return 1;
    16     ll ans=pow_mod(a,p/2,n);
    17     ans=ans*ans%n;
    18     if(p%2==1) ans=ans*a%n;
    19     return ans;
    20 }
    21 
    22 
    23 int main()
    24 {
    25     int t;
    26     scanf("%d",&t);
    27     while(t--)
    28     {
    29         memset(a,0,sizeof(a));
    30         scanf("%d%d",&n,&m);
    31         getchar();
    32         char op;
    33         int cnt=0;
    34         int pos=0;
    35         int mid=(n+1)/2;
    36         int x;
    37         for(int i=1; i<=m; i++)
    38         {
    39             scanf("%c",&op);
    40             if(op=='O')
    41             {
    42                 scanf("%d",&x);
    43                 a[i]=x;
    44             }
    45             else if(op=='Q')
    46             {
    47                 scanf("%d",&x);
    48                 pos=x;
    49                 int c=1;
    50                 for(int j=i-1; j>=1; j--)
    51                 {
    52                     if(a[j]==1)
    53                     {
    54                         if(pos<=mid)
    55                             pos=pos*2-1;
    56                         else
    57                             pos=(pos-mid)*2;
    58                     }
    59                     else if(a[j]==2)
    60                     {
    61                         pos=n-pos+1;
    62                     }
    63                     else if(a[j]==3)
    64                     {
    65                        c=(c+c)%(mod-1);
    66                     }
    67                 }
    68                 printf("%d
    ",pow_mod(pos,c,mod));
    69             }
    70             getchar();
    71         }
    72     }
    73     return 0;
    74 }
    View Code
  • 相关阅读:
    2020年“安洵杯”四川省大学生信息安全技术大赛 Misc WP
    整数划分问题
    二叉树根节点到叶子节点的所有路径和
    java正则表达式
    搜狗笔试
    跟谁学0923笔试
    360 笔试0926
    度小满0920
    TreeMap 常用函数
    达达0920
  • 原文地址:https://www.cnblogs.com/fanminghui/p/4278934.html
Copyright © 2011-2022 走看看