Task: | Ryhmät |
Sender: | sharph2 |
Submission time: | 2025-09-27 14:10:03 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 10 |
#2 | ACCEPTED | 15 |
#3 | ACCEPTED | 75 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#2 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#3 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#4 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#5 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#6 | ACCEPTED | 0.08 s | 2 | details |
#7 | ACCEPTED | 0.08 s | 2 | details |
#8 | ACCEPTED | 0.10 s | 2 | details |
#9 | ACCEPTED | 0.03 s | 2, 3 | details |
#10 | ACCEPTED | 0.46 s | 3 | details |
#11 | ACCEPTED | 0.33 s | 3 | details |
#12 | ACCEPTED | 0.21 s | 3 | details |
#13 | ACCEPTED | 0.36 s | 3 | details |
#14 | ACCEPTED | 0.11 s | 3 | details |
#15 | ACCEPTED | 0.34 s | 3 | details |
#16 | ACCEPTED | 0.85 s | 3 | details |
Code
#include <algorithm> #include <iostream> #include <limits> #include <optional> #include <set> #include <stack> #include <queue> #include <vector> using namespace std; constexpr int N = 1 << 17; pair<int, int> toiveet[N]; vector<int> toivelistat[2 * N]; struct Kulma { int x; int y; int s; }; Kulma pino[N]; int summa_(int x1, int x2, int y, int v, int s) { if(x2 <= 0 || x1 >= s) { return 0; } if(x1 <= 0 && x2 >= s) { vector<int>& l = toivelistat[v]; return (int)(lower_bound(l.begin(), l.end(), y) - l.begin()); } int h = s >> 1; return summa_(x1, x2, y, 2 * v, h) + summa_(x1 - h, x2 - h, y, 2 * v + 1, h); } // [x1, x2[ x ]-oo, y[ int summa(int x1, int x2, int y) { return summa_(x1, x2, y, 1, N); } optional<int> kaannaSumma(int x1, int x2, int s) { if(summa(x1, x2, N) < s) { return nullopt; } int a = 0; int b = N; while(a < b) { int c = (a + b) / 2; int s2 = summa(x1, x2, c); if(s2 == s) { return c; } if(s2 < s) { a = c + 1; } else { b = c - 1; } } return a; } int main() { cin.sync_with_stdio(false); cin.tie(nullptr); int n, t; cin >> n >> t; for(int i = 0; i < n; ++i) { cin >> toiveet[i].first >> toiveet[i].second; } vector<vector<int>> koot(t); int maxM = 0; for(int ti = 0; ti < t; ++ti) { int m; cin >> m; maxM = max(maxM, m); koot[ti].resize(m); for(int& koko : koot[ti]) { cin >> koko; } sort(koot[ti].begin(), koot[ti].end()); } // eispä epäeleganssi if(n <= 1000 && t <= 1000 && maxM <= 1000) { sort(toiveet, toiveet + n); priority_queue<int, vector<int>, greater<int>> loput; for(vector<int>& testiKoot : koot) { int p = 0; bool ok = true; for(int koko : testiKoot) { while(p < n && toiveet[p].first <= koko) { loput.push(toiveet[p].second); ++p; } while(!loput.empty() && loput.top() < koko) { loput.pop(); } while(koko > 0) { if(loput.empty()) { ok = false; goto ohi2; } loput.pop(); --koko; } } ohi2: {} if(ok) { cout << "YES\n"; } else { cout << "NO\n"; } while(!loput.empty()) { loput.pop(); } } return 0; } sort(toiveet, toiveet + n, [&](pair<int, int> a, pair<int, int> b) { return a.second < b.second; }); for(int i = 0; i < n; ++i) { auto [a, b] = toiveet[i]; int v = N + a; while(v > 0) { toivelistat[v].push_back(i); v >>= 1; } } for(vector<int>& testiKoot : koot) { int p = 0; pino[p++] = {-2, N + 2, 0}; pino[p++] = {-1, N + 1, 0}; int edellinenKoko = -1; bool onnistui = true; for(int koko : testiKoot) { // if(p == 0) throw 5; // if(pino[0].x != -2) throw 5; // for(int i = 1; i < p; ++i) { // if(pino[i].s != summa(pino[i - 1].x + 1, pino[i].x + 1, pino[i].y)) throw 5; // } if(koko != edellinenKoko) { int y = lower_bound(toiveet, toiveet + n, make_pair(0, koko), [&](pair<int, int> a, pair<int, int> b) { return a.second < b.second; }) - toiveet; while(pino[p - 1].y <= y) { --p; } pino[p] = {koko, y, summa(pino[p - 1].x + 1, koko + 1, y)}; ++p; } edellinenKoko = koko; int jalj = koko; while(jalj) { int pala = summa(pino[p - 2].x + 1, pino[p - 1].x + 1, pino[p - 2].y) - pino[p - 1].s; if(jalj >= pala) { if(p <= 2) { onnistui = false; goto ohi; } pino[p - 2].x = pino[p - 1].x; pino[p - 2].s += pino[p - 1].s + pala; --p; jalj -= pala; } else { optional<int> aOpt = kaannaSumma(pino[p - 2].x + 1, pino[p - 1].x + 1, pino[p - 1].s + jalj); if(!aOpt.has_value()) { onnistui = false; goto ohi; } int a = aOpt.value(); // if(a > pino[p - 2].y - 1) throw 5; // if(a > b) throw 5; // if(summa(pino[p - 2].x + 1, pino[p - 1].x + 1, a) - pino[p - 1].s != jalj) throw 5; pino[p - 1].y = a; pino[p - 1].s += jalj; jalj = 0; // if(pino[p - 1].s != summa(pino[p - 2].x + 1, pino[p - 1].x + 1, pino[p - 1].y)) throw 5; // if(pino[p - 2].y <= pino[p - 1].y) throw 5; } } } ohi: {} if(onnistui) { cout << "YES\n"; } else { cout << "NO\n"; } } 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: ACCEPTED
input |
---|
100 100 100 100 100 100 100 100 100 100 ... |
correct output |
---|
YES YES YES YES YES ... |
user output |
---|
YES YES YES YES YES ... |
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: ACCEPTED
input |
---|
1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 ... |
correct output |
---|
YES YES YES YES YES ... |
user output |
---|
YES YES YES YES YES ... |
Test 10
Group: 3
Verdict: ACCEPTED
input |
---|
100000 1000 774 778 363 852 309 668 261 459 ... |
correct output |
---|
YES YES YES YES YES ... |
user output |
---|
YES YES YES YES YES ... |
Test 11
Group: 3
Verdict: ACCEPTED
input |
---|
100000 1000 1233 1914 901 3963 1277 4293 1083 1599 ... |
correct output |
---|
NO NO YES NO NO ... |
user output |
---|
NO NO YES NO NO ... |
Test 12
Group: 3
Verdict: ACCEPTED
input |
---|
100000 1000 1970 8631 4606 5797 6317 8162 8204 8789 ... |
correct output |
---|
NO NO NO NO NO ... |
user output |
---|
NO NO NO NO NO ... |
Test 13
Group: 3
Verdict: ACCEPTED
input |
---|
100000 1000 1000 1000 1000 1000 1000 1000 1000 1000 ... |
correct output |
---|
YES YES YES YES YES ... |
user output |
---|
YES YES YES YES YES ... |
Test 14
Group: 3
Verdict: ACCEPTED
input |
---|
100000 100000 1 100000 1 100000 1 100000 1 100000 ... |
correct output |
---|
YES YES YES YES YES ... |
user output |
---|
YES YES YES YES YES ... |
Test 15
Group: 3
Verdict: ACCEPTED
input |
---|
100000 100000 80971 98445 93046 96043 74840 94035 95931 96609 ... |
correct output |
---|
NO NO NO NO NO ... |
user output |
---|
NO NO NO NO NO ... |
Test 16
Group: 3
Verdict: ACCEPTED
input |
---|
100000 10000 6481 14350 69129 87600 6217 16462 4387 16625 ... |
correct output |
---|
YES YES YES YES YES ... |
user output |
---|
YES YES YES YES YES ... |