您的位置:首页 > 其它

Codeforces Round #310 (Div. 1) C Case of Chocolate

2015-06-28 16:04 337 查看
思路:对于每个点而言、只与它相邻的两个点有关系、所以可以用stl或者线段树来找到它的相邻点、

代码:187ms(开挂之后貌似是最快的- -)

#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;

const int N = 200000 + 1;

int x
, y
, t
;

//适用于正负整数
template <class T>
inline bool scan_d(T &ret) {
char c; int sgn;
if(c = getchar(),c == EOF) return 0; //EOF
while(c != '-' && (c < '0' || c > '9')) c = getchar();
sgn = (c == '-') ? -1 : 1;
ret = (c == '-') ? 0 : (c - '0');
while(c = getchar(),c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
ret *= sgn;
return 1;
}

inline void out(int x) {
if(x > 9) out(x / 10);
putchar(x % 10 + '0');
}

int main() {
int n, q;
scanf("%d%d", &n, &q);
x[q] = y[q] = 0;
map <int, int> mp;
mp[0] = q;
mp[n + 1] = q;
for (int i = 0; i < q; ++ i) {
char buffer[2];
scan_d(x[i]);
scan_d(y[i]);
scanf("%s",buffer);
t[i] = *buffer == 'U';
map <int, int>::iterator iterator;
iterator = mp.lower_bound(x[i]);
if (x[i] == iterator->first) {
puts("0"); continue;
}
if (!t[i]) iterator --;
int j = iterator->second;
mp[x[i]] = i;
if (t[i]) {
out(y[i] - y[j]);
putchar('\n');
y[i] = y[j];
} else {
out(x[i] - x[j]);
putchar('\n');
x[i] = x[j];
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: