比赛 20150422 评测结果 AEAETETTTT
题目名称 马拉松 最终得分 20
用户昵称 wolf. 运行时间 5.560 s
代码语言 C++ 内存使用 0.31 MiB
提交时间 2015-04-22 10:39:11
显示代码纯文本
#include<iostream>
#include<fstream>
#include<bitset>
#include<vector>
#include<deque>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdio>
using namespace std;
#if defined wolf
const string ok="OK";
const string kk="	";
ofstream nnew("marathona.in",ios::app);
ifstream fin("marathona.in");
#define fout cout
#define Endl endl
#else
ifstream fin("marathona.in");
ofstream fout("marathona.out");
#endif
class node{
public:
	int x;
	int y;
	int di;
	node(){
	}
	node(int a,int b){
		x=a;
		y=b;
	}
};
vector<node> TT;
vector<int> ll;
int calc(int x1,int y1,int x2,int y2){
	return abs(x1-x2)+abs(y1-y2);//|x1-x2| + |y1-y2|
}
void build(){
	TT[0].di=0;
	for(int i=1;i!=TT.size()-1;++i){
		TT[i].di=calc(TT[i-1].x,TT[i-1].y,TT[i+1].x,TT[i+1].y)-(ll[i-1]+ll[i]);
	}
	TT[TT.size()-1].di=0;
}
void rebuild(int p,int x,int y){
	if(x!=-2000){
		TT[p].x=x;
		TT[p].y=y;
	}
	if(p>0&&p<ll.size()){
		ll[p]=calc(TT[p].x,TT[p].y,TT[p+1].x,TT[p+1].y);
		ll[p-1]=calc(TT[p].x,TT[p].y,TT[p-1].x,TT[p-1].y);
		TT[p].di=calc(TT[p-1].x,TT[p-1].y,TT[p+1].x,TT[p+1].y)-(ll[p-1]+ll[p]);
		return;
	}
	if(p==0){
		ll[p]=calc(TT[p].x,TT[p].y,TT[p+1].x,TT[p+1].y);
	}else{//p==TT.size()-1
		ll[p-1]=calc(TT[p].x,TT[p].y,TT[p-1].x,TT[p-1].y);
	}
	
}
int core(int a,int b){
	int mmin=99999999;
	int ans=0;
	for(int i=a+1;i!=b;++i){
		ans+=ll[i];
		mmin=min(mmin,TT[i].di);
	}
	ans+=ll[a];
	return min(ans,ans+mmin);
}
int main(){
	int n,q;
	fin>>n>>q;
	int a,b;
	fin>>a>>b;
	TT.push_back(node(a,b));
	for(int i=1;i!=n;++i){
		fin>>a>>b;
		TT.push_back(node(a,b));
		ll.push_back(calc(TT[i].x,TT[i].y,TT[i-1].x,TT[i-1].y));
	}
	build();
	for(int i=0;i!=q;++i){
		char t;
		fin>>t;
		if(t=='U'){
			int a,b,c;
			fin>>a>>b>>c;
			rebuild(a-1,b,c);
			rebuild(a-2,-2000,0);
			rebuild(a,-2000,0);
			/*for(int i=0;i!=ll.size();++i){
				cout<<ll[i]<<"  ";
			}
			cout<<endl;
			for(int i=0;i!=TT.size();++i){
				cout<<TT[i].di<<"  ";
			}
			cout<<endl;*/
		}else{
			int a,b;
			fin>>a>>b;
			//cout<<a<<" "<<b<<endl;
			fout<<core(a-1,b-1)<<endl;;
		}
	}
	//-------------------------*/
	#if defined wolf
	cout<<endl<<(double)clock()/CLOCKS_PER_SEC<<'s'<<endl;
	#endif
	return 0;
}
//Designed by wolf
//Wed Apr 22 2015