Submission #712901

# Submission time Handle Problem Language Result Execution time Memory
712901 2023-03-20T12:22:44 Z lam Jail (JOI22_jail) C++14
5 / 100
73 ms 13120 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 2e4 + 10;
typedef pair<int,int> ii;
#define ff first
#define ss second
int n,m;
vector <int> adj[maxn];
ii a[maxn];
vector <ii> d;
int f[maxn];
void update(int x, int val)
{
    while (x>0)
    {
        f[x]+=val;
        x-=(x&-x);
    }
}
int get(int x)
{
    int temp = 0;
    while (x<=n)
    {
        temp+=f[x];
        x+=(x&-x);
    }
    return temp;
}
bool cmp(ii x, ii y)
{
    if (x.ff!=y.ff) return x.ff<y.ff;
    return x.ss>y.ss;
}
void xuly()
{
    cin>>n;
    for (int i=1; i<=n; i++) adj[i].clear();
    for (int i=1; i<n; i++)
    {
        int u,v; cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    cin>>m;
    d.clear();
    for (int i=1; i<=m; i++)
    {
        int l,r; cin>>l>>r;
        a[i]={l,r};
        if (l<=r)
        {
            d.push_back({l,1});
            d.push_back({r,-1});
        }
        else
        {
            d.push_back({l,-2});
            d.push_back({r,2});
        }
    }
    int num1,num2;
    num1=num2=0;
    bool check = 1;
    sort(d.begin(),d.end());
    for (ii i:d)
    {
        if (i.ss==1) num1++;
        else if (i.ss==-1) num1--;
        else if (i.ss==2) num2++;
        else num2--;
        if (num1>0&&num2>0)
        {
            cout<<"No\n";
            return;
        }
    }
    d.clear();
    for (int i=1; i<=m; i++)
    {
        if (a[i].ff<a[i].ss)
        {
            d.push_back({a[i].ff,a[i].ss});
            d.push_back({a[i].ss,-1});
        }
        else
        {
            d.push_back({a[i].ss,a[i].ff});
            d.push_back({a[i].ff,-1});
        }
    }
    sort(d.begin(),d.end(),cmp);
    fill_n(f,n+1,0);
    for (ii i:d)
    {
        if (i.ss==-1) update(i.ff,-1);
        else
        {
            if (get(i.ss+1)>0)
            {
                cout<<"No\n";
                return;
            }
            update(i.ss,1);
        }
    }
    cout<<"Yes\n";

}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int tt; cin>>tt;
    while (tt--) xuly();
}

Compilation message

jail.cpp: In function 'void xuly()':
jail.cpp:64:10: warning: unused variable 'check' [-Wunused-variable]
   64 |     bool check = 1;
      |          ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 8 ms 3284 KB Output is correct
5 Correct 17 ms 3788 KB Output is correct
6 Correct 2 ms 3156 KB Output is correct
7 Correct 3 ms 3168 KB Output is correct
8 Correct 4 ms 3216 KB Output is correct
9 Correct 21 ms 4516 KB Output is correct
10 Correct 31 ms 8804 KB Output is correct
11 Correct 6 ms 3284 KB Output is correct
12 Correct 23 ms 4028 KB Output is correct
13 Correct 51 ms 10588 KB Output is correct
14 Correct 41 ms 10280 KB Output is correct
15 Correct 46 ms 10308 KB Output is correct
16 Correct 73 ms 12608 KB Output is correct
17 Correct 55 ms 10996 KB Output is correct
18 Correct 73 ms 13120 KB Output is correct
19 Correct 55 ms 11068 KB Output is correct
20 Correct 46 ms 10524 KB Output is correct
21 Correct 47 ms 10464 KB Output is correct
22 Correct 46 ms 10944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3156 KB Output is correct
4 Incorrect 2 ms 3156 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3156 KB Output is correct
4 Incorrect 2 ms 3156 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3156 KB Output is correct
4 Incorrect 2 ms 3156 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3156 KB Output is correct
4 Incorrect 2 ms 3156 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3036 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 2 ms 3028 KB Output is correct
5 Correct 6 ms 3156 KB Output is correct
6 Incorrect 3 ms 3156 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3028 KB Output is correct
2 Correct 2 ms 3028 KB Output is correct
3 Correct 2 ms 3028 KB Output is correct
4 Correct 8 ms 3284 KB Output is correct
5 Correct 17 ms 3788 KB Output is correct
6 Correct 2 ms 3156 KB Output is correct
7 Correct 3 ms 3168 KB Output is correct
8 Correct 4 ms 3216 KB Output is correct
9 Correct 21 ms 4516 KB Output is correct
10 Correct 31 ms 8804 KB Output is correct
11 Correct 6 ms 3284 KB Output is correct
12 Correct 23 ms 4028 KB Output is correct
13 Correct 51 ms 10588 KB Output is correct
14 Correct 41 ms 10280 KB Output is correct
15 Correct 46 ms 10308 KB Output is correct
16 Correct 73 ms 12608 KB Output is correct
17 Correct 55 ms 10996 KB Output is correct
18 Correct 73 ms 13120 KB Output is correct
19 Correct 55 ms 11068 KB Output is correct
20 Correct 46 ms 10524 KB Output is correct
21 Correct 47 ms 10464 KB Output is correct
22 Correct 46 ms 10944 KB Output is correct
23 Correct 2 ms 3028 KB Output is correct
24 Correct 2 ms 3028 KB Output is correct
25 Correct 2 ms 3156 KB Output is correct
26 Incorrect 2 ms 3156 KB Output isn't correct
27 Halted 0 ms 0 KB -