在模拟的过程中走着走着死掉了。。。。。
题目链接:https://codeforces.com/contest/1236/problem/D
ac代码:
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <set>
#include <iterator>
using namespace std;
typedef long long ll;
const int mx = 1e5+100;
const ll mod = 1e9+7;
set<ll>r[mx], c[mx];
ll dr[4];
int main()
{
ll n, m, k;
scanf("%lld%lld%lld", &n, &m, &k);
for (int i = 0; i < k; ++i) {
ll a, b;
scanf("%lld%lld", &a, &b);
r[a].insert(b);
c[b].insert(a);
}
for (int i = 1; i <= n; ++i) r[i].insert(m+1), r[i].insert(0);
for (int i = 1; i <= m; ++i) c[i].insert(n+1), c[i].insert(0);
int f = 0;
ll s1 = 0, a = 1, b = 1, st = 1, di = 0;
dr[0] = m, dr[1] = n, dr[2] = 1, dr[3] = 1;
while (f<2) {
set<ll>::iterator x;
ll xs;
if (di == 0) {
x = r[a].upper_bound(b);
xs = min(*x-1, dr[0]);
dr[3] = a+1;
st = st+xs-b;
b = xs;
}
if (di == 1) {
x = c[b].upper_bound(a);
xs = min(*x-1, dr[1]);
dr[0] = b-1;
st = st+xs-a;
a = xs;
}
if (di == 2) {
x = r[a].upper_bound(b);
x--;
xs = max(*x+1, dr[2]);
dr[1] = a-1;
st = st+b-xs;
b = xs;
}
if (di == 3) {
x = c[b].upper_bound(a);
x--;
xs = max(*x+1, dr[3]);
// if (!f)C
dr[2] = b+1;
st = st+a-xs;
a = xs;
}
// printf("%d %d %d %d %d\n", a, b, xs, di, st);
di = (di+1)%4;
if(s1 == st) break;
s1 = st;
}
if (n*m-k == st) puts("Yes");
else puts("No");
return 0;
}