Submission details
Task:Ryhmät
Sender:sharph2
Submission time:2025-09-27 00:03:40 +0300
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3details
#2ACCEPTED0.01 s1, 2, 3details
#3ACCEPTED0.01 s1, 2, 3details
#40.00 s1, 2, 3details
#5ACCEPTED0.01 s1, 2, 3details
#6ACCEPTED0.31 s2details
#7ACCEPTED0.35 s2details
#8ACCEPTED0.27 s2details
#90.00 s2, 3details
#100.03 s3details
#110.02 s3details
#120.02 s3details
#130.02 s3details
#140.18 s3details
#150.02 s3details
#160.04 s3details

Code

#include <algorithm>
#include <iostream>
#include <set>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

constexpr int N = 1 << 5;

template <typename F>
void hajotelma_(int a, int b, const F& f, int v, int s) {
    if(b <= 0 || a >= s) {
        return;
    }
    if(a <= 0 && b >= s) {
        f(v);
        return;
    }
    int h = s >> 1;
    hajotelma_(a, b, f, 2 * v, h);
    hajotelma_(a - h, b - h, f, 2 * v + 1, h);
}

template <typename F>
void hajotelma(int a, int b, const F& f) {
    hajotelma_(a, b + 1, f, 1, N);
}

template <typename F>
void peitto(int i, const F& f) {
    i += N;
    while(i > 0) {
        f(i);
        i >>= 1;
    }
}

int main() {
    cin.sync_with_stdio(false);
    cin.tie(nullptr);

    int n, t;
    cin >> n >> t;

    vector<multiset<pair<int, int>>> toivepuu(2 * N);
    for(int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        hajotelma(a, b, [&](int v) {
            toivepuu[v].insert({b, a});
        });
    }

    vector<int> koot;
    stack<pair<int, int>> valitut;
    for(int ti = 0; ti < t; ++ti) {
        int m;
        cin >> m;

        koot.resize(m);
        for(int i = 0; i < m; ++i) {
            cin >> koot[i];
        }
        sort(koot.begin(), koot.end());

        bool ok = true;
        for(int koko : koot) {
            for(int i = 0; i < koko; ++i) {
                int paras = N;
                int parasV = -1;
                peitto(koko, [&](int v) {
                    if(!toivepuu[v].empty() && toivepuu[v].begin()->first < paras) {
                        paras = toivepuu[v].begin()->first;
                        parasV = v;
                    }
                });
                if(parasV == -1) {
                    ok = false;
                    goto ohi;
                }
                auto [b, a] = *toivepuu[parasV].begin();
                hajotelma(a, b, [&](int v) {
                    auto it = toivepuu[v].find({b, a});
                    if(it == toivepuu[v].end()) {
                        throw 5;
                    }
                    toivepuu[v].erase(it);
                });
                valitut.push({a, b});
            }
        }
        ohi: {}

        if(ok) {
            cout << "YES\n";
        } else {
            cout << "NO\n";
        }

        while(!valitut.empty()) {
            auto [a, b] = valitut.top();
            valitut.pop();
            hajotelma(a, b, [&](int v) {
                toivepuu[v].insert({b, a});
            });
        }
    }

    return 0;
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
100 100
10 10
10 10
6 9
6 8
...

correct output
YES
YES
YES
NO
YES
...

user output
YES
YES
YES
NO
YES
...

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
100 100
9 9
6 10
8 10
8 8
...

correct output
NO
YES
NO
YES
NO
...

user output
NO
YES
NO
YES
NO
...

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
100 100
1 1
1 1
1 1
1 1
...

correct output
YES
YES
YES
YES
YES
...

user output
YES
YES
YES
YES
YES
...

Test 4

Group: 1, 2, 3

Verdict:

input
100 100
100 100
100 100
100 100
100 100
...

correct output
YES
YES
YES
YES
YES
...

user output
NO
NO
NO
NO
NO
...

Test 5

Group: 1, 2, 3

Verdict: ACCEPTED

input
100 100
4 9
3 8
7 9
7 9
...

correct output
NO
NO
NO
NO
NO
...

user output
NO
NO
NO
NO
NO
...

Test 6

Group: 2

Verdict: ACCEPTED

input
1000 1000
9 10
2 5
10 10
5 5
...

correct output
YES
YES
YES
YES
NO
...

user output
YES
YES
YES
YES
NO
...

Test 7

Group: 2

Verdict: ACCEPTED

input
1000 1000
5 7
9 9
3 7
8 10
...

correct output
YES
NO
NO
YES
YES
...

user output
YES
NO
NO
YES
YES
...

Test 8

Group: 2

Verdict: ACCEPTED

input
1000 1000
1 1
1 1
1 1
1 1
...

correct output
YES
YES
YES
YES
YES
...

user output
YES
YES
YES
YES
YES
...

Test 9

Group: 2, 3

Verdict:

input
1000 1000
1000 1000
1000 1000
1000 1000
1000 1000
...

correct output
YES
YES
YES
YES
YES
...

user output
(empty)

Test 10

Group: 3

Verdict:

input
100000 1000
774 778
363 852
309 668
261 459
...

correct output
YES
YES
YES
YES
YES
...

user output
(empty)

Error:
terminate called after throwing an instance of 'int'

Test 11

Group: 3

Verdict:

input
100000 1000
1233 1914
901 3963
1277 4293
1083 1599
...

correct output
NO
NO
YES
NO
NO
...

user output
(empty)

Error:
terminate called after throwing an instance of 'int'

Test 12

Group: 3

Verdict:

input
100000 1000
1970 8631
4606 5797
6317 8162
8204 8789
...

correct output
NO
NO
NO
NO
NO
...

user output
(empty)

Error:
terminate called after throwing an instance of 'int'

Test 13

Group: 3

Verdict:

input
100000 1000
1000 1000
1000 1000
1000 1000
1000 1000
...

correct output
YES
YES
YES
YES
YES
...

user output
(empty)

Test 14

Group: 3

Verdict:

input
100000 100000
1 100000
1 100000
1 100000
1 100000
...

correct output
YES
YES
YES
YES
YES
...

user output
NO
NO
NO
NO
NO
...

Test 15

Group: 3

Verdict:

input
100000 100000
80971 98445
93046 96043
74840 94035
95931 96609
...

correct output
NO
NO
NO
NO
NO
...

user output
(empty)

Test 16

Group: 3

Verdict:

input
100000 10000
6481 14350
69129 87600
6217 16462
4387 16625
...

correct output
YES
YES
YES
YES
YES
...

user output
NO
NO
NO
NO
NO
...