比赛 |
20150422 |
评测结果 |
AAAAAAAAAA |
题目名称 |
马拉松 |
最终得分 |
100 |
用户昵称 |
Asm.Def |
运行时间 |
4.017 s |
代码语言 |
C++ |
内存使用 |
1.07 MiB |
提交时间 |
2015-04-22 09:01:01 |
显示代码纯文本
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <algorithm>
#include <cmath>
using namespace std;
//#define USEFREAD
#ifdef USEFREAD
#define InputLen 5000000
char *ptr=(char *)malloc(InputLen);
#define getc() (*(ptr++))
#else
#define getc() (getchar())
#endif
#define SetFile(x) (freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout))
template<class T>inline void getd(T &x){
int ch = getc();bool neg = false;
while(!isdigit(ch) && ch != '-')ch = getc();
if(ch == '-')ch = getc(), neg = true;
x = ch - '0';
while(isdigit(ch = getc()))
x = x * 10 - '0' + ch;
if(neg)x = -x;
}
/***********************************************************************/
const int maxn = 100005;
#include <cmath>
struct Point{int x, y;}P[maxn];
inline int dist(int i, int j){return abs(P[i].x - P[j].x) + abs(P[i].y - P[j].y);}
struct Data{
int L, R, mid, dis, Mindis;
inline void init(){dis = Mindis = dist(L, R);return;}
inline void init(const Data &a, const Data &b){
dis = a.dis + b.dis;
L = a.L, R = b.R, mid = a.R;
Mindis = min(a.Mindis + b.dis, a.dis + b.Mindis);
int l = mid-1, r = mid+1;
int tmp = dist(l, r) - dist(l, mid) - dist(mid, r);
Mindis = min(Mindis, dis + tmp);
}
};
struct SegT{
int L, R, mid;
Data data;
SegT *ls, *rs;
SegT(int l, int r):L(l), R(r), mid((l + r) >> 1){
data = (Data){l, r, (l+r)>>1};
if(r - l == 1){data.init();return;}
ls = new SegT(l, mid);rs = new SegT(mid, r);
data.init(ls->data, rs->data);
}
void Modify(int i){
if(R - L == 1){data.init();return;}
if(data.R < i)ls->Modify(i);
else if(data.L > i)rs->Modify(i);
else ls->Modify(i), rs->Modify(i);
data.init(ls->data, rs->data);
}
Data Query(int l, int r){
if(l == data.L && r == data.R)return data;
if(l >= mid)return rs->Query(l, r);
if(r <= mid)return ls->Query(l, r);
Data ans;ans.init(ls->Query(l, mid), rs->Query(mid, r));
return ans;
}
}*Root;
int main(){
#ifdef DEBUG
freopen("test.txt", "r", stdin);
#else
SetFile(marathona);
#endif
#ifdef USEFREAD
fread(ptr,1,InputLen,stdin);
#endif
int N, Q, opt, i, j, x, y;
getd(N);getd(Q);
for(i = 1;i <= N;++i)getd(P[i].x), getd(P[i].y);
Root = new SegT(1, N);
while(Q--){
while(!isalpha(opt = getc()));
if(opt == 'Q'){
getd(i), getd(j);
printf("%d\n", Root->Query(i, j).Mindis);
}
else{
getd(i), getd(x), getd(y);
P[i] = (Point){x, y};
Root->Modify(i);
}
}
#ifdef DEBUG
printf("\n%.3lf sec \n", (double)clock() / CLOCKS_PER_SEC);
#endif
return 0;
}