Submission #552691

#TimeUsernameProblemLanguageResultExecution timeMemory
552691tht2005Jail (JOI22_jail)C++17
5 / 100
69 ms4960 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 120005;
int n, m, cnt[N], s[N], t[N], idx[N];

int main() {
    int q;
    scanf("%d", &q);
    while(q--) {
        scanf("%d", &n);
        for(int i = 1; i < n; ++i) {
            int a, b;
            scanf("%d %d", &a, &b);
            assert(a == i && b == i + 1);
        }
        memset(cnt, 0, (n + 1) * sizeof *cnt);
        scanf("%d", &m);
        for(int i = 1; i <= m; ++i) {
            scanf("%d %d", s + i, t + i);
            if(s[i] < t[i]) {
                ++cnt[s[i]];
                --cnt[t[i] + 1];
            }
        }
        for(int i = 1; i <= n; ++i) {
            cnt[i] += cnt[i - 1];
        }
        for(int i = 1; i <= m; ++i) {
            if(s[i] > t[i]) {
                swap(s[i], t[i]);
                if(cnt[s[i]] || cnt[t[i]]) {
                    puts("No");
                    goto nextQuery;
                }
            }
            idx[i] = i;
        }
        sort(idx + 1, idx + 1 + m, [&](int i, int j) {
            return s[i] < s[j];
        });
        for(int x = 1, r = 0; x <= m; ++x) {
            int i = idx[x];
            if(r > t[i]) {
                puts("No");
                goto nextQuery;
            }
            r = t[i];
        }
        puts("Yes");
nextQuery:;
    }
    return 0;
}

Compilation message (stderr)

jail.cpp: In function 'int main()':
jail.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d", &q);
      |     ~~~~~^~~~~~~~~~
jail.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
jail.cpp:15:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |             scanf("%d %d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~~
jail.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         scanf("%d", &m);
      |         ~~~~~^~~~~~~~~~
jail.cpp:21:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |             scanf("%d %d", s + i, t + 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...