Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <vector>
- #include <map>
- #include <set>
- #include <complex>
- #include <ctime>
- #include <iostream>
- #include <cmath>
- #include <stack>
- #include <sstream>
- #include <stdio.h>
- #include <algorithm>
- #include <queue>
- #include <cstring>
- #include <cassert>
- #include <sstream>
- const long double PI(acosl(-1.0));
- long double eps = 1e-9;
- #define pb push_back
- #define mp(a,b) make_pair(a,b)
- #define all(x) x.begin(), x.end()
- #define sqr(x) ((x)*(x))
- #define F first
- #define S second
- #define inf (int)(1e9+7)
- #define infll (ll)(1e18+3)
- #define sz(x) ((int)x.size())
- #define bits(x) __builtin_popcount(x)
- #define bitsl(x) __builtin_popcountll(x)
- #define rep(i, a, b) for (int (i) = (a); i <= (b); ++(i))
- #define forn(i, n) rep(i, 0, n-1)
- using namespace std;
- typedef unsigned long long ull;
- typedef long long ll;
- typedef long double ld;
- typedef vector <ll > vll;
- typedef vector<int> vi;
- typedef pair < ll, ll > pll;
- typedef pair < int, int > pii;
- typedef vector<vi> vii;
- typedef int huint;
- using namespace std;
- const int N = 500000;
- vector<pii> p;
- map<pii, char> mp;
- int main() {
- std::ios_base::sync_with_stdio(false);
- cin.tie(0); cout.tie(0);
- freopen("library.in", "r", stdin);
- freopen("library.out", "w", stdout);
- int n;
- cin >> n;
- for (int i(0); i < n; i++)
- {
- int x, y, z;
- cin >> x >> y >> z;
- x += z;
- if (x > y)
- {
- cout << "NO";
- return 0;
- }
- p.pb({ y,x });
- }
- sort(all(p));
- for (int i(0); i < n; i++)
- {
- pii a = p[i];
- if (mp.count({ a.S, a.S }) == 1)
- {
- if (a.S == a.F)
- {
- cout << "NO";
- return 0;
- }
- auto x = mp.find({ a.S, a.S });
- x++;
- if (x != mp.end() && x->F.F == a.S + 1)
- {
- if (x->first.S >= a.F)
- {
- cout << "NO";
- return 0;
- }
- int l = x->first.F;
- int r = x->first.S + 1;
- mp.erase(x);
- mp[{l, r}] = 1;
- }
- else
- {
- mp.erase({ a.S, a.S });
- mp[{a.S, a.S + 1}] = 1;
- }
- continue;
- }
- else mp[{a.S, a.S}] = 1;
- auto x = mp.find({ a.S, a.S });
- auto z = mp.find({ a.S, a.S });
- bool fl = false;
- if(x == mp.begin()) fl = 1;
- x++;
- if (x != mp.end())
- {
- if (x->first.F > a.S)
- {
- x--;
- x--;
- }
- else
- fl = 0;
- }
- else
- {
- x--;
- x--;
- }
- while (1 && !fl)
- {
- if (x == mp.end() )
- {
- cout << "b\n";
- break;
- }
- if (x->first.F > a.S)
- break;
- if (x->first.F <= a.S)
- {
- if (x->first.S >= a.F)
- {
- cout << "NO";
- return 0;
- }
- if (x->first.S >= a.S - 1)
- {
- int l = x->first.F;
- int r = x->first.S + 1;
- mp.erase(x);
- mp.erase(z);
- mp[{l, r}] = 1;
- break;
- }
- break;
- }
- }
- }
- cout << "YES";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement