Submission #914600

#TimeUsernameProblemLanguageResultExecution timeMemory
914600davitmargTowers (NOI22_towers)C++17
11 / 100
975 ms113920 KiB
/*
DavitMarg
In a honky-tonk,
Down in Mexico
*/
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <random>
#include <chrono>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair    
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

const int N = 1000006;

#define X first.first
#define Y first.second
#define I second
#define pt pair<pair<int,int>, int>

int n;
int ans[N];
pt p[N];
vector<pt> x[N], y[N];
int used[N];

void lesgo(pt a)
{
    ans[a.I] = 1;
    used[a.I] = 1;
    if (!y[a.Y].empty() && y[a.Y][0] == a)
    {
        pt last = a;
        bool f = 0;
        for (int i = 1; i < y[a.Y].size(); i++)
        {
            pt b = y[a.Y][i];
            if (ans[b.I])
            {
                f = 1;
				break;
            }
            if(!x[b.X].empty() && !used[b.I] && (x[b.X][0] == b || x[b.X].back() == b))
				last = b;
            used[b.I] = 1;
        }

        y[a.Y].clear();
        if (!f)
        {
            ans[last.I] = 1;
            if (last != a)
                lesgo(last);
        }
    }
    else if (!y[a.Y].empty() && y[a.Y].back() == a)
    {
        pt last = a;
        bool f = 0;
        for (int i = (int)y[a.Y].size() - 2; i >= 0; i--)
        {
            pt b = y[a.Y][i];
               
            if (ans[b.I])
            {
				f = 1;
				break;
			}

			if (!x[b.X].empty() && !used[b.I] && (x[b.X][0] == b || x[b.X].back() == b))
                last = b;
            used[b.I] = 1;
        }

        y[a.Y].clear();

        if (!f)
        {
            ans[last.I] = 1;
            if (last != a)
                lesgo(last);
        }
    }


    if (!x[a.X].empty() && x[a.X][0] == a)
    {
		pt last = a;
        bool f = 0;
        for (int i = 1; i < x[a.X].size(); i++)
        {
			pt b = x[a.X][i];
            if (ans[b.I])
            {
				f = 1;
				break;
			}
			if (!y[b.Y].empty() && !used[b.I] && (y[b.Y][0] == b || y[b.Y].back() == b))
				last = b;
			used[b.I] = 1;
		}

        ans[last.I] = 1;

        if (!f)
        {
            x[a.X].clear();

            if (last != a)
                lesgo(last);
        }
	}
    else if (!x[a.X].empty() && x[a.X].back() == a)
    {
		pt last = a;
        bool f = 0;
        for (int i = (int)x[a.X].size() - 2; i >= 0; i--)
        {
			pt b = x[a.X][i];

            if (ans[b.I])
            {
                f = 1;
                break;
            }

            if (!y[b.Y].empty() && !used[b.I] && (y[b.Y][0] == b || y[b.Y].back() == b))
				last = b;
			used[b.I] = 1;
		}

        x[a.X].clear();

        if (!f)
        {
            ans[last.I] = 1;

            if (last != a)
                lesgo(last);
        }
    }   
}

void solve()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> p[i].X >> p[i].Y;
        p[i].I = i;
    }

    for (int i = 1; i <= n; i++)
    {
        x[p[i].X].push_back(p[i]);
        y[p[i].Y].push_back(p[i]);
    }

    for (int i = 0; i < N; i++)
    {
        sort(all(x[i]), [](pt a, pt b) {return a.Y < b.Y; });
        sort(all(y[i]), [](pt a, pt b) {return a.X < b.X; });
    }

    sort(p + 1, p + 1 + n, [](pt a, pt b) {
        if(a.Y == b.Y)
            return a.X < b.X;
        return a.Y < b.Y; 
    });

    for (int i = 1; i <= n; i++)
    {
        if(used[p[i].I])
            continue;
        lesgo(p[i]);
    }

    for (int i = 1; i <= n; i++)
        cout << ans[i];
    cout << endl;

}




int main()
{
    fastIO;
    int T = 1;
    //cin >> T;
    while (T--)
    {
        solve();
    }

    return 0;
}

/*

8
1 1
2 1
3 1
1 2
2 2
3 2
2 3
3 3


*/

Compilation message (stderr)

Main.cpp: In function 'void lesgo(std::pair<std::pair<int, int>, int>)':
Main.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         for (int i = 1; i < y[a.Y].size(); i++)
      |                         ~~^~~~~~~~~~~~~~~
Main.cpp:109:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |         for (int i = 1; i < x[a.X].size(); i++)
      |                         ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...