/*
* Consider some path from u to v.
*
* Define the range of some guy u as [u, first before u that has edge cut].
*
* Define the range of v similarly.
*
* Then if there exists a bridge between [l1, r1] and [l2, r2], then u can reach v.
*
* Try to view it as points.
*
* Problem reduces to: add a point, check if rectangle contains point.
* Another constraint: points are always monotoncially increasing
* - binary search for first point with x >= left edge of rect and y >= bottom edge of rect
* - check if x <= right edge of rect and y <= top edge of rect
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define lb lower_bound
#define ub upper_bound
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
const int MX = 200005;
const int MOD = (int) (1e9 + 7);
const ll INF = (ll) 1e18;
namespace output {
void pr(int x) {
cout << x;
}
void pr(long x) {
cout << x;
}
void pr(ll x) {
cout << x;
}
void pr(unsigned x) {
cout << x;
}
void pr(unsigned long x) {
cout << x;
}
void pr(unsigned long long x) {
cout << x;
}
void pr(float x) {
cout << x;
}
void pr(double x) {
cout << x;
}
void pr(long double x) {
cout << x;
}
void pr(char x) {
cout << x;
}
void pr(const char * x) {
cout << x;
}
void pr(const string & x) {
cout << x;
}
void pr(bool x) {
pr(x ? "true" : "false");
}
template < class T1, class T2 > void pr(const pair < T1, T2 > & x);
template < class T > void pr(const T & x);
template < class T, class...Ts > void pr(const T & t,
const Ts & ...ts) {
pr(t);
pr(ts...);
}
template < class T1, class T2 > void pr(const pair < T1, T2 > & x) {
pr("{", x.f, ", ", x.s, "}");
}
template < class T > void pr(const T & x) {
pr("{"); // const iterator needed for vector<bool>
bool fst = 1;
for (const auto & a: x) pr(!fst ? ", " : "", a), fst = 0;
pr("}");
}
void ps() {
pr("\n");
} // print w/ spaces
template < class T, class...Ts > void ps(const T & t,
const Ts & ...ts) {
pr(t);
if (sizeof...(ts)) pr(" ");
ps(ts...);
}
void pc() {
cout << "]" << endl;
} // debug w/ commas
template < class T, class...Ts > void pc(const T & t,
const Ts & ...ts) {
pr(t);
if (sizeof...(ts)) pr(", ");
pc(ts...);
}
//#define dbg(x...) pr("[", #x, "] = ["), pc(x);
}
#ifdef mikey
using namespace output;
#else
using namespace output;
//#define dbg(x...)
#endif
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T> using PeanutButter = tree<T, null_type, less<T>,
rb_tree_tag, tree_order_statistics_node_update>;
#define ook order_of_key
#define fbo find_by_order
PeanutButter<pi> pts;
set<int> bad[2];
set<int> pre[2];
int main(){
#ifdef mikey
freopen("a.in", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
int n, m; cin >> n >> m;
bad[0].insert(n), bad[1].insert(n);
pre[0].insert(1), pre[1].insert(1);
auto has = [&] (pi xs, pi ys) {
int ans = -1;
int lo = 0, hi = sz(pts) - 1;
//dbg(pts);
while (lo <= hi) {
int mid = (lo + hi) / 2;
pi cur = *pts.fbo(mid);
//dbg(mid, cur);
if (cur.f >= xs.f && cur.s >= ys.f) {
hi = mid - 1;
ans = mid;
} else {
lo = mid + 1;
}
}
if (ans == -1) return false;
else {
pi cur = *pts.fbo(ans);
//dbg(cur);
if (cur.f <= xs.s && cur.s <= ys.s) {
return true;
}
return false;
}
};
for (int i = 0; i < m; i++) {
char qt; cin >> qt;
if (qt == 'A') {
int x, y; cin >> x >> y;
if (x > y) swap(x, y);
if (y > n) y -= n;
pts.insert(mp(x, y));
} else if (qt == 'B') {
int x, y; cin >> x >> y;
//dbg("REM", x, y);
bool c = (x > n);
x -= (n * c);
y -= (n * c);
bad[c].insert(min(x, y));
pre[c].insert(max(x, y));
} else {
int x, y; cin >> x >> y;
int c = (x > n), c2 = (y > n);
x -= (n * c);
y -= (n * c2);
//dbg("QUERY", x, y);
if (c == c2) {
int go = *(bad[c].lb(min(x, y)));
if (go >= y) cout << "DA\n";
else cout << "NE\n";
} else {
pi r1 = mp(x, *bad[c].lb(x));
pi r2 = mp(y, *bad[c2].lb(y));
if (c) {
r1 = mp(*(--pre[c].ub(x)), x);
r2 = mp(*(--pre[c2].ub(y)), y);
}
//dbg(r1, r2);
if (has(r1, r2)) cout << "DA\n";
else cout << "NE\n";
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
7 |
Incorrect |
245 ms |
13004 KB |
Output isn't correct |
8 |
Incorrect |
275 ms |
12908 KB |
Output isn't correct |
9 |
Incorrect |
270 ms |
15084 KB |
Output isn't correct |
10 |
Incorrect |
245 ms |
13420 KB |
Output isn't correct |