Submission #714668

# Submission time Handle Problem Language Result Execution time Memory
714668 2023-03-25T07:35:22 Z aykhn Plahte (COCI17_plahte) C++14
0 / 160
2000 ms 250448 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define OPT ios_base::sync_with_stdio(0); \
            cin.tie(0); \
            cout.tie(0)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define endl "\n"
#define all(v) v.begin(), v.end()
#define mpr make_pair
#define pb push_back
#define ts to_string
#define fi first
#define se second
#define inf 0x3F3F3F3F
#define bpc __builtin_popcount
#define print(v) for(int i = 0; i < v.size(); i++) \
                    cout << v[i] << " "; \
                    cout<<endl;

/*
int ternarySearch(int l, int r, int key, int ar[])
{
    if (r >= l)
    {
        int mid1 = l + (r - l) / 3;
        int mid2 = r - (r - l) / 3;

        if (ar[mid1] == key) {
            return mid1;
        }
        if (ar[mid2] == key) {
            return mid2;
        }
        if (key < ar[mid1]) {
            return ternarySearch(l, mid1 - 1, key, ar);
        }
        else if (key > ar[mid2]) {
            return ternarySearch(mid2 + 1, r, key, ar);
        }
        else {
            return ternarySearch(mid1 + 1, mid2 - 1, key, ar);
        }
    }
    return -1;
}
*/

struct DSU {
	vector<int> e;

	void init(int n)
	{
	    e.assign(n, -1);
	}

	int get(int x)
	{
	    if (e[x] < 0)
            return x;
        return e[x] = get(e[x]);
	}

	bool together(int a, int b)
	{
	    return get(a) == get(b);
    }

	int s(int x)
	{
	    return -e[get(x)];
    }

	bool unite(int x, int y)
	{
		x = get(x);
        y = get(y);

		if (x == y) return false;

		if (e[x] > e[y]) swap(x, y);

		e[x] += e[y];
		e[y] = x;

		return true;
	}
};

struct cor
{
    int lx, ly, rx, ry, id;
};

struct shot
{
    int x, y, col, id;
};

bool cmp1(cor &a, cor &b)
{
    if (a.lx == b.lx) return a.rx <= b.rx;
    return a.lx <= b.lx;
}
bool cmp2(shot &a, shot &b)
{
    if (a.x == b.x) return a.y <= b.y;
    return a.x <= b.x;
}
int main()
{
    int n, m;
    cin >> n >> m;
    vector<cor> a(n + 1);
    vector<shot> b(m + 1);
    set<int> tim;

    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].lx >> a[i].ly >> a[i].rx >> a[i].ry;
        a[i].id = i;
        tim.insert(a[i].lx);
        tim.insert(a[i].rx);
    }
    sort(a.begin() + 1, a.end(), cmp1);

    for (int i = 1; i <= m; i++)
    {
        cin >> b[i].x >> b[i].y >> b[i].col;
        b[i].id = i;
        tim.insert(b[i].x);
        tim.insert(b[i].y);
    }

    sort(b.begin() + 1, b.end(), cmp2);

    int i = 1;
    int j = 1;

    unordered_set<int> onc;

    vector<unordered_set<int>> ans(n + 1);

    for (int t : tim)
    {
        for (auto it = onc.begin(); it != onc.end();)
        {
            if (a[*it].ry < t)
            {
                onc.erase(it);
            }
            else it++;
        }

        while (i <= n && t == a[i].lx)
        {
            onc.insert(i);
            i++;
        }

        while (j <= m && t == b[j].x)
        {
            for (int x : onc)
            {
                if (b[j].y >= a[x].ly && b[j].y <= a[x].ry)
                {
                    ans[a[x].id].insert(b[j].id);
                }
            }
            j++;
        }
    }

    for (int i = 1; i <= n; i++)
    {
        cout << ans[i].size() << endl;
    }
}
# Verdict Execution time Memory Grader output
1 Runtime error 352 ms 86164 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2060 ms 250448 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2070 ms 186848 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2043 ms 183244 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2065 ms 172144 KB Time limit exceeded
2 Halted 0 ms 0 KB -