记录编号 315857 评测结果 AAAAAAAAAA
题目名称 魔法传输 最终得分 100
用户昵称 Gravatarsxysxy 是否通过 通过
代码语言 C++ 运行时间 0.294 s
提交时间 2016-10-05 22:16:13 内存使用 1.44 MiB
显示代码纯文本
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define MAXN 100002
#define MOD 1000000007
#define BT __attribute__((optimize("O3")))
int magic;
int lazy[MAXN];
int d[MAXN];
int moni[MAXN];
BT
inline int fast_read()
{
    int r;
    char ch;
    while(ch = getchar())
    {
        if(ch >= '0' && ch <= '9')
        {
            r = ch^0x30;
            break;
        }
    }
    while(isdigit(ch = getchar()))
        r = (r<<3)+(r<<1)+(ch^0x30);
    return r;
}

BT
inline void add(int l, int r)
{
    int k = 1;
    for(int i = l; i <= r;)
    {
        if(i % magic == 0 && i + magic <= r)
        {
            lazy[i/magic] += k;
            d[i/magic]++;
            k += magic;
            i += magic;
        }else
        {
            moni[i] += (k++);
            i++;
        }
    }
}
BT
inline int query(int p)
{
    int m = p/magic;
    return (lazy[m]%MOD + (p-m*magic)*d[m]%MOD + moni[p]%MOD) % MOD;
}

BT
int main()
{
    freopen("magics.in", "r", stdin);
    freopen("magics.out", "w", stdout);
    int n, m;
    n = fast_read();
    m = fast_read();
    magic = (int)sqrt(n);
    
    while(m--)
    {
        char c;
        while(c = getchar())if(isalpha(c))break;
        if(c == 'C')
        {
            int a, b;
            a = fast_read();
            b = fast_read();
            add(a, b);
        }else
        {
            int x;
            x = fast_read();
            printf("%d\n", query(x));
        }
    }
    return 0;
}