比赛 20160421x 评测结果 WWWWWWWWWW
题目名称 魔法传输 最终得分 0
用户昵称 Cydiater 运行时间 1.096 s
代码语言 C++ 内存使用 3.36 MiB
提交时间 2016-04-21 16:21:16
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iomanip>
#include <cstdlib>
#include <queue>
#include <map>
using namespace std;
const long long dydxh=1000000007LL;
long long N,M,x,y,t[4*100005],k;
inline long long read(){
	char ch=getchar();long long x=0,f=1;
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
void pulldown(long long root,long long leftt,long long rightt){
	if(t[root]==0||leftt==rightt)return;
	t[root<<1]+=t[root];t[root<<1|1]+=((leftt+rightt)>>1|1)-leftt+1+t[root];
	t[root<<1]%=dydxh;t[root<<1|1]%=dydxh;
	t[root]=0;
}
void updata(long long leftt,long long rightt,long long root){
	pulldown(root,leftt,rightt);
	if(leftt>y||rightt<x)return;
	if(leftt>=x&&rightt<=y){
		t[root]+=leftt-x+1;
		t[root]=t[root]%dydxh;
		return;
	}
	int mid=(leftt+rightt)>>1;
	updata(leftt,mid,root<<1);
	updata(mid+1,rightt,root<<1|1);
}
int getnum(long long leftt,long long rightt,long long root){
	pulldown(root,leftt,rightt);
	if(leftt>k||rightt<k)	return -dydxh;
	if(leftt==rightt&&rightt==k)
		return t[root];
	long long mid=(leftt+rightt)>>1;
	return max(getnum(leftt,mid,root<<1),getnum(mid+1,rightt,root<<1|1));
}
int main(){
	freopen("magics.in","r",stdin);
	freopen("magics.out","w",stdout);
	N=read();M=read();
	for(int i=1;i<=M;i++){
		char ch;scanf("\n%c",&ch);
		if(ch=='C'){x=read();y=read();updata(1,N,1);}
		else if(ch=='Q'){
			k=read();
			cout<<getnum(1,N,1)<<endl;
		}
	}
	return 0;
}