比赛 20150422 评测结果 AAAAAAAAAA
题目名称 马拉松 最终得分 100
用户昵称 JSX 运行时间 0.574 s
代码语言 C++ 内存使用 3.69 MiB
提交时间 2015-04-22 11:58:23
显示代码纯文本
#include <cmath>
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
template<class T>inline void Read(T& x) {
	x = 0; bool flag = 0; char ch = getchar();
	while(ch<'0'||ch>'9') { if(ch == '-') flag = 1; ch = getchar(); }
	while('0'<=ch&&ch<='9') { x=x*10+ch-'0'; ch = getchar(); }
	if(flag) x=-x;
}
#define maxn 100010
#define INF  0x7f7f7f7f
#define L(o) (o << 1)
#define R(o) (o << 1 | 1)
int n = 0,q = 0,cnt = 0;
int x[maxn],y[maxn];
int m1 = 1,T1[maxn << 2],T2[maxn << 2];
inline int abs(int x) { if(x < 0) return -x; else return x; }
inline int query_sum(int s,int t) {
	int ans = 0;
	for(s += m1-1,t += m1+1;s^t^1;s >>= 1,t >>= 1) {
		if(!(s&1)) ans += T1[s^1];
		if( (t&1)) ans += T1[t^1];
	}
	return ans;
}
inline int dis(int i,int j) {
	return abs(x[i]-x[j])+abs(y[i]-y[j]);
}
inline int query_max(int s,int t) {
	if(s > t) return 0;
	int ans = -INF;
	for(s += m1-1,t += m1+1;s^t^1;s >>= 1,t >>= 1) {
		if(!(s&1)) ans = max(ans,T2[s^1]);
		if( (t&1)) ans = max(ans,T2[t^1]);
	}
	return ans;
}
void change(int o){
	int i = 0;
	T1[o+m1-1]=dis(o-1,o),T1[o+m1]=dis(o,o+1);
	for(i=(o+m1-1)>>1;i;i>>=1) T1[i]=T1[i<<1]+T1[i<<1|1];
	T2[o+m1]=T1[o+m1-1]+T1[o+m1]-dis(o-1,o+1);
	for(i=(o+m1)>>1;i;i>>=1) T2[i]=max(T2[i<<1],T2[i<<1|1]),T1[i]=T1[i<<1]+T1[i<<1|1];
	if(o>2){
		T2[o+m1-1]=T1[o+m1-2]+T1[o+m1-1]-dis(o-2,o);
		for(i=(o+m1-1)>>1;i;i>>=1) T2[i]=max(T2[i<<1],T2[i<<1|1]);
	}
	if(o<n-1){
		T2[o+m1+1]=T1[o+m1]+T1[o+m1+1]-dis(o,o+2);
		for(i=(o+m1+1)>>1;i;i>>=1) T2[i]=max(T2[i<<1],T2[i<<1|1]);
	}
}
/*inline void change(int p) {
	T1[p+m1-1]=dis(p-1,p); T1[p+m1]=dis(p,p+1);
	int i = (m1+p-1) >> 1;
	for(;i;i >>= 1) T1[i] = T1[L(i)] + T1[R(i)];
	T2[p+m1]=T1[p+m1-1]+T1[p+m1]-dis(p-1,p+1);
	i = (m1+p) >> 1;
	for(;i;i >>= 1) T1[i] = T1[L(i)] + T1[R(i)],T2[i] = max(T2[L(i)],T2[R(i)]);
	if(p > 2) {
		T2[p+m1-1] = T1[p+m1-2]+T1[p+m1-1]-dis(p-2,p);
		i = (m1+p-1) >> 1;
		for(;i;i >>= 1) T2[i] = max(T2[L(i)],T2[R(i)]);
	}
	if(p < n-1) {
		T2[p+m1+1] = T1[p+m1]+T1[p+m1+1]-dis(p,p+2);
		i = (m1+p+1) >> 1;
		for(;i;i >>= 1) T2[i] = max(T2[L(i)],T2[R(i)]);
	}
}*/
/*
inline void change(int p) {
	if(p == 1) {
		w[1] = abs(x[2]-x[1]) + abs(y[2]-y[1]);
		T1[1 + m1] = w[1]; T2[1 + m1] = 0;
		int i = (m1 + 1) >> 1;
		for(;i;i >>= 1) { 
			T1[i] = T1[L(i)] + T1[R(i)];
			T2[i] = max(T2[L(i)],T2[R(i)]);
		}
		return ;	
	} else 
	if(p == n) {
		w[cnt] = abs(x[n]-x[n-1]) + abs(y[n]-y[n-1]);
		T1[cnt + m1] = w[cnt]; T2[cnt + m1]= 0;
		int i = (m1 + cnt) >> 1;
		for(;i;i >>= 1) { 
			T1[i] = T1[L(i)] + T1[R(i)];
			T2[i] = max(T2[L(i)],T2[R(i)]);
		}
		return ;
	} else {
		w[p-1] = abs(x[p]-x[p-1]) + abs(y[p]-y[p-1]);
		w[p  ] = abs(x[p+1]-x[p]) + abs(y[p+1]-y[p]);
		T1[p+m1-1] = w[p-1]; T2[p+m1-1] = abs(x[p]-x[p-2]) + abs(y[p]-y[p-2]);
		T1[p + m1] = w[p];   T2[p+m1] = abs(x[p+1]-x[p-1]) + abs(y[p+1]-y[p-1]);
		T2[p+m1+1] = abs(x[p+2]-x[p]) + abs(y[p+2]-y[p]);
		T2[p+m1-1] = w[p-1]+w[p]-T2[p+m1-1];
		T2[p+m1] = w[p]+w[p+1]-T2[p+m1];
		T2[p+m1+1] = w[p+1]+w[p+2]-T2[p+m1+1];
		int i = (m1 + p-1) >> 1;
		for(;i;i >>= 1) { 
			T1[i] = T1[L(i)] + T1[R(i)];
			T2[i] = max(T2[L(i)],T2[R(i)]);
		}
		i = (m1 + p) >> 1;
		for(;i;i >>= 1) { 
			T1[i] = T1[L(i)] + T1[R(i)];
			T2[i] = max(T2[L(i)],T2[R(i)]);
		}
		i = (m1 + p + 1) >> 1;
		for(;i;i >>= 1) { 
			T1[i] = T1[L(i)] + T1[R(i)];
			T2[i] = max(T2[L(i)],T2[R(i)]);
		}
		return;
	}
}
*/
inline char GETCHAR() {
	char ch = getchar(); 
	while(ch != 'U' && ch != 'Q') ch = getchar();
	return ch;
}
int main() {
	freopen("marathona.in","r",stdin);
	freopen("marathona.out","w",stdout);
	Read(n); Read(q);
	for(int i = 1; i <= n;++ i)
		Read(x[i]),Read(y[i]);
	for(m1 = 1;m1 < n+2;m1 <<= 1);
	//T1[1+m1] = abs(x[2]-x[1]) + abs(y[2]-y[1]);
	/*T1[1+m1] = dis(1,2);
	for(int i = 2;i < n;++ i) {
		T1[i+m1] = dis(i,i+1);
		T2[i+m1] = T1[i+m1-1]+T1[i+m1]-dis(i-1,i+1);
	}
	for(int i = m1-1;i;-- i) {
		T1[i] = T1[L(i)] + T1[R(i)]; 
		T2[i] = max(T2[L(i)],T2[R(i)]);
	}*/
	T1[m1+1]=dis(1,2);
	for(int i=2;i<n;i++)
		T1[i+m1]=dis(i,i+1),T2[i+m1]=T1[i+m1-1]+T1[i+m1]-dis(i-1,i+1);
	for(int i=m1-1;i;i--)
		T2[i]=max(T2[i<<1],T2[i<<1|1]),T1[i]=T1[i<<1]+T1[i<<1|1];
	int op = 0,pos = 0,s = 0,t = 0;
	while(q --) {
		op = GETCHAR();
		if(op == 'U') {
			Read(pos); Read(x[pos]); Read(y[pos]);
			change(pos);
		} else {
			Read(s); Read(t);
			printf("%d\n",query_sum(s,t-1)-query_max(s+1,t-1));
		}
	}
	//fclose(stdin);
	//fclose(stdout);
	return 0;
}