记录编号 |
253061 |
评测结果 |
AAAAAAAAAA |
题目名称 |
魔法传输 |
最终得分 |
100 |
用户昵称 |
KZNS |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
1.002 s |
提交时间 |
2016-04-21 17:08:06 |
内存使用 |
4.89 MiB |
显示代码纯文本
//KZNS
#include <fstream>
using namespace std;
typedef long long LL;
const int MD = 1000000007;
class poi {
public:
int l, r, ad, sm;
} tr[300000];
int N, M;
inline void Ddata(int x);
inline void Udata(int x);
void msgt(int x, int l, int r) {
poi &u = tr[x];
u.l = l;
u.r = r;
u.ad = 0;
u.sm = 0;
if (l < r) {
msgt(x<<1, l, l+r>>1);
msgt(x<<1^1, (l+r>>1)+1, r);
}
}
void ADin(int x, int l, int r, int c) {
poi &u = tr[x];
if (l <= u.l && u.r <= r) {
u.ad = (u.ad+c)%MD;
u.ad = (u.ad+MD)%MD;
u.sm = (u.sm + (LL)(u.r - u.l + 1) * c) % MD;
while (u.sm<0)
u.sm = (u.sm + MD)%MD;
}
else {
Ddata(x);
if (l <= tr[x<<1].r)
ADin(x<<1, l, r, c);
if (tr[x<<1^1].l <= r)
ADin(x<<1^1, l, r, c);
Udata(x);
}
}
int Qin(int x, int l, int r) {
poi &u = tr[x];
if (l <= u.l && u.r <= r) {
return u.sm;
}
else {
int sm = 0;
Ddata(x);
if (l <= tr[x<<1].r)
sm = (sm + Qin(x<<1, l, r)) % MD;
if (tr[x<<1^1].l <= r)
sm = (sm + Qin(x<<1^1, l, r)) % MD;
return sm;
}
}
//
int main() {
ifstream fin ("magics.in");
ofstream fout ("magics.out");
fin >> N >> M;
msgt(1, 1, N);
char c;
int a, b;
for (int i = 0; i < M; i++) {
fin >> c;
if (c == 'C') {
fin >> a >> b;
ADin(1, a, b, 1);
if (b < N)
ADin(1, b+1, b+1, -(b-a+1));
}
else {
fin >> a;
fout << Qin(1, 1, a) << endl;
}
}
return 0;
}
//
inline void Ddata(int x) {
if (tr[x].ad) {
ADin(x<<1, tr[x].l, tr[x].r, tr[x].ad);
ADin(x<<1^1, tr[x].l, tr[x].r, tr[x].ad);
tr[x].ad = 0;
}
}
inline void Udata(int x) {
poi &u = tr[x], &lc = tr[x<<1], &rc = tr[x<<1^1];
u.sm = (lc.sm + rc.sm) % MD;
u.sm = (u.sm + MD) % MD;
}
//UBWH