답안 #1093887

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1093887 2024-09-28T00:41:25 Z duyhoanho Joker (BOI20_joker) C++17
49 / 100
2000 ms 33968 KB
#include<bits/stdc++.h>
#define int long long
#define forinc(i,a,b) for(int i=a;i<=b;i++)
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
using namespace std;
const int N = 2e5+10;
int n,m,q,fre[N],lz[N],p[N],sz[N];
int ans[N];
pii d[N];

vector<int> ad[N];
//sub1
bool qu1(int l,int r)
{
    bool ok = 0;
    forinc(i,1,n) ad[i].clear();
    forinc(i,1,m)
    {
        if(l<=i && i<=r) continue;
        int x,y;
        tie(x,y) = d[i];
        ad[x].pb(y);
        ad[y].pb(x);
    }

    for(int i=1; i<=n; i++) fre[i] = -1;
    for(int i=1; i<=n; i++)
    {
        if(fre[i] == -1)
        {
            queue<int> q;
            q.push(i);
            fre[i] = 0;
            while(q.size())
            {
                int u = q.front();
                q.pop();
                for(int v:ad[u])
                {
                    if(fre[v] == fre[u]) return true;
                    if(fre[v] != -1) continue;
                    fre[v] = 1 - fre[u];
                    q.push(v);
                }

            }
        }
    }
    return false;
}
//sub2,3
struct node
{
  int l,r,id;
}qu[N];
vector<node> v[N];
bool cmp(node a,node b)
{
    if(a.l != b.l) return a.l < b.l;
  return a.r > b.r;
}
int pa(int v,int &c)
{
    c ^= lz[v];
    if(p[v] == v) return v;
    return pa(p[v], c);
}
void join(int a,int b)
{
    int ca = 0;
    int cb = 0;
    a = pa(a,ca);
    b = pa(b,cb);
    if(a != b)
    {
        if(sz[a] < sz[b]) swap(a,b);
        sz[a] += sz[b];
        p[b] = a;
        if(ca == cb) lz[b] = 1;
    }
}
bool check(int a,int b)
{
    int ca = 0;
    int cb = 0;
    a = pa(a,ca);
    b = pa(b,cb);
    if(a == b && ca == cb) return true;
    return false;
}
void sol(int x)
{
    bool ok = 0;
     forinc(i,1,n)
    {
        sz[i] = 1;
        p[i] = i;
        lz[i] = 0;
    }
    for(int i = 1;i<v[x][0].l;i++)
    {
        if(check(d[i].fi , d[i].se)) ok=1;
        join(d[i].fi,d[i].se);
    }
    for(int i = m ; i > v[x][0].r ; i--)
    {
         if(check(d[i].fi , d[i].se)) ok=1;
        join(d[i].fi,d[i].se);
    }
    ans[v[x][0].id] = ok;
    for(int i = 1 ; i < v[x].size() ; i++)
    {
      for(int j = v[x][i-1].r ; j > v[x][i].r;j--)
      {
        if(check(d[j].fi,d[j].se)) ok = 1;
        join(d[j].fi , d[j].se);
      }
      ans[v[x][i].id] = ok;
    }

}
int32_t main()
{
    if(fopen("task.inp","r"))
    {
        freopen("task.inp","r",stdin);
        freopen("task.out","w",stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m>>q;
    forinc(i,1,m)
    {
        int x,y;
        cin>>x>>y;
        d[i] = {x,y};
    }
    if(n<=2000 && m <= 2000 && q <= 2000)
    {
        while(q--)
        {
            int l,r;
            cin>>l>>r;
            cout<< (qu1(l,r) ? "YES\n" : "NO\n");
        }
        return 0;

    }
    forinc(i,1,n)
    {
        sz[i] = 1;
        p[i] = i;
        lz[i] = 0;
    }

    forinc(i,1,q)
    {
        int l,r;
        cin>>l>>r;
        qu[i] = {l,r,i};
    }

    sort(qu + 1 , qu + q + 1,cmp);
    int it = 0;
    int la = 0;
    for(int i=1;i<=q;i++)
    {
        if(qu[i].l != la)
        {
            it++;
            la = qu[i].l;
        }
        v[it].pb(qu[i]);
    }
    for(int i=1;i<=it;i++) sol(i);
    forinc(i,1,q) cout<<(ans[i] ? "YES\n" : "NO\n");
}

Compilation message

Joker.cpp: In function 'bool qu1(long long int, long long int)':
Joker.cpp:18:10: warning: unused variable 'ok' [-Wunused-variable]
   18 |     bool ok = 0;
      |          ^~
Joker.cpp: In function 'void sol(long long int)':
Joker.cpp:114:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |     for(int i = 1 ; i < v[x].size() ; i++)
      |                     ~~^~~~~~~~~~~~~
Joker.cpp: In function 'int32_t main()':
Joker.cpp:129:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  129 |         freopen("task.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:130:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |         freopen("task.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 5 ms 9820 KB Output is correct
7 Correct 6 ms 9820 KB Output is correct
8 Correct 4 ms 9820 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 4 ms 9872 KB Output is correct
11 Correct 5 ms 9820 KB Output is correct
12 Correct 5 ms 9820 KB Output is correct
13 Correct 4 ms 9820 KB Output is correct
14 Correct 5 ms 9820 KB Output is correct
15 Correct 5 ms 9832 KB Output is correct
16 Correct 5 ms 9820 KB Output is correct
17 Correct 4 ms 9820 KB Output is correct
18 Correct 4 ms 9820 KB Output is correct
19 Correct 4 ms 9820 KB Output is correct
20 Correct 4 ms 9816 KB Output is correct
21 Correct 5 ms 9816 KB Output is correct
22 Correct 5 ms 10072 KB Output is correct
23 Correct 4 ms 9820 KB Output is correct
24 Correct 5 ms 9820 KB Output is correct
25 Correct 5 ms 9816 KB Output is correct
26 Correct 5 ms 9820 KB Output is correct
27 Correct 4 ms 9820 KB Output is correct
28 Correct 4 ms 9820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 5 ms 9820 KB Output is correct
7 Correct 6 ms 9820 KB Output is correct
8 Correct 4 ms 9820 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 4 ms 9872 KB Output is correct
11 Correct 5 ms 9820 KB Output is correct
12 Correct 5 ms 9820 KB Output is correct
13 Correct 4 ms 9820 KB Output is correct
14 Correct 5 ms 9820 KB Output is correct
15 Correct 5 ms 9832 KB Output is correct
16 Correct 5 ms 9820 KB Output is correct
17 Correct 4 ms 9820 KB Output is correct
18 Correct 4 ms 9820 KB Output is correct
19 Correct 4 ms 9820 KB Output is correct
20 Correct 4 ms 9816 KB Output is correct
21 Correct 5 ms 9816 KB Output is correct
22 Correct 5 ms 10072 KB Output is correct
23 Correct 4 ms 9820 KB Output is correct
24 Correct 5 ms 9820 KB Output is correct
25 Correct 5 ms 9816 KB Output is correct
26 Correct 5 ms 9820 KB Output is correct
27 Correct 4 ms 9820 KB Output is correct
28 Correct 4 ms 9820 KB Output is correct
29 Correct 98 ms 9956 KB Output is correct
30 Correct 68 ms 9816 KB Output is correct
31 Correct 52 ms 9820 KB Output is correct
32 Correct 31 ms 10016 KB Output is correct
33 Correct 20 ms 9816 KB Output is correct
34 Correct 55 ms 9816 KB Output is correct
35 Correct 73 ms 9816 KB Output is correct
36 Correct 41 ms 9816 KB Output is correct
37 Correct 92 ms 9820 KB Output is correct
38 Correct 79 ms 9820 KB Output is correct
39 Correct 75 ms 9820 KB Output is correct
40 Correct 40 ms 9816 KB Output is correct
41 Correct 39 ms 9820 KB Output is correct
42 Correct 39 ms 9820 KB Output is correct
43 Correct 21 ms 9820 KB Output is correct
44 Correct 24 ms 9816 KB Output is correct
45 Correct 28 ms 9820 KB Output is correct
46 Correct 33 ms 9820 KB Output is correct
47 Correct 41 ms 9820 KB Output is correct
48 Correct 39 ms 9816 KB Output is correct
49 Correct 57 ms 10004 KB Output is correct
50 Correct 72 ms 9816 KB Output is correct
51 Correct 31 ms 10008 KB Output is correct
52 Correct 38 ms 9816 KB Output is correct
53 Correct 61 ms 10032 KB Output is correct
54 Correct 70 ms 10004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 78 ms 30912 KB Output is correct
4 Correct 76 ms 32704 KB Output is correct
5 Correct 79 ms 32960 KB Output is correct
6 Correct 75 ms 31072 KB Output is correct
7 Correct 79 ms 30912 KB Output is correct
8 Correct 74 ms 29372 KB Output is correct
9 Correct 75 ms 30400 KB Output is correct
10 Correct 77 ms 32960 KB Output is correct
11 Correct 78 ms 30916 KB Output is correct
12 Correct 78 ms 33032 KB Output is correct
13 Correct 77 ms 28864 KB Output is correct
14 Correct 81 ms 29888 KB Output is correct
15 Correct 80 ms 31936 KB Output is correct
16 Correct 82 ms 33472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 5 ms 9820 KB Output is correct
7 Correct 6 ms 9820 KB Output is correct
8 Correct 4 ms 9820 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 4 ms 9872 KB Output is correct
11 Correct 5 ms 9820 KB Output is correct
12 Correct 5 ms 9820 KB Output is correct
13 Correct 4 ms 9820 KB Output is correct
14 Correct 5 ms 9820 KB Output is correct
15 Correct 5 ms 9832 KB Output is correct
16 Correct 5 ms 9820 KB Output is correct
17 Correct 4 ms 9820 KB Output is correct
18 Correct 4 ms 9820 KB Output is correct
19 Correct 4 ms 9820 KB Output is correct
20 Correct 4 ms 9816 KB Output is correct
21 Correct 5 ms 9816 KB Output is correct
22 Correct 5 ms 10072 KB Output is correct
23 Correct 4 ms 9820 KB Output is correct
24 Correct 5 ms 9820 KB Output is correct
25 Correct 5 ms 9816 KB Output is correct
26 Correct 5 ms 9820 KB Output is correct
27 Correct 4 ms 9820 KB Output is correct
28 Correct 4 ms 9820 KB Output is correct
29 Correct 78 ms 30912 KB Output is correct
30 Correct 76 ms 32704 KB Output is correct
31 Correct 79 ms 32960 KB Output is correct
32 Correct 75 ms 31072 KB Output is correct
33 Correct 79 ms 30912 KB Output is correct
34 Correct 74 ms 29372 KB Output is correct
35 Correct 75 ms 30400 KB Output is correct
36 Correct 77 ms 32960 KB Output is correct
37 Correct 78 ms 30916 KB Output is correct
38 Correct 78 ms 33032 KB Output is correct
39 Correct 77 ms 28864 KB Output is correct
40 Correct 81 ms 29888 KB Output is correct
41 Correct 80 ms 31936 KB Output is correct
42 Correct 82 ms 33472 KB Output is correct
43 Correct 727 ms 31436 KB Output is correct
44 Correct 1012 ms 33580 KB Output is correct
45 Correct 1037 ms 33876 KB Output is correct
46 Correct 1041 ms 31572 KB Output is correct
47 Correct 1355 ms 31572 KB Output is correct
48 Correct 1519 ms 31240 KB Output is correct
49 Correct 1538 ms 33616 KB Output is correct
50 Correct 1255 ms 30992 KB Output is correct
51 Correct 1144 ms 32340 KB Output is correct
52 Correct 1095 ms 33872 KB Output is correct
53 Correct 1200 ms 29520 KB Output is correct
54 Correct 1472 ms 31056 KB Output is correct
55 Correct 1502 ms 32596 KB Output is correct
56 Correct 1475 ms 33968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 5 ms 9820 KB Output is correct
7 Correct 6 ms 9820 KB Output is correct
8 Correct 4 ms 9820 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 4 ms 9872 KB Output is correct
11 Correct 5 ms 9820 KB Output is correct
12 Correct 5 ms 9820 KB Output is correct
13 Correct 4 ms 9820 KB Output is correct
14 Correct 5 ms 9820 KB Output is correct
15 Correct 5 ms 9832 KB Output is correct
16 Correct 5 ms 9820 KB Output is correct
17 Correct 4 ms 9820 KB Output is correct
18 Correct 4 ms 9820 KB Output is correct
19 Correct 4 ms 9820 KB Output is correct
20 Correct 4 ms 9816 KB Output is correct
21 Correct 5 ms 9816 KB Output is correct
22 Correct 5 ms 10072 KB Output is correct
23 Correct 4 ms 9820 KB Output is correct
24 Correct 5 ms 9820 KB Output is correct
25 Correct 5 ms 9816 KB Output is correct
26 Correct 5 ms 9820 KB Output is correct
27 Correct 4 ms 9820 KB Output is correct
28 Correct 4 ms 9820 KB Output is correct
29 Correct 98 ms 9956 KB Output is correct
30 Correct 68 ms 9816 KB Output is correct
31 Correct 52 ms 9820 KB Output is correct
32 Correct 31 ms 10016 KB Output is correct
33 Correct 20 ms 9816 KB Output is correct
34 Correct 55 ms 9816 KB Output is correct
35 Correct 73 ms 9816 KB Output is correct
36 Correct 41 ms 9816 KB Output is correct
37 Correct 92 ms 9820 KB Output is correct
38 Correct 79 ms 9820 KB Output is correct
39 Correct 75 ms 9820 KB Output is correct
40 Correct 40 ms 9816 KB Output is correct
41 Correct 39 ms 9820 KB Output is correct
42 Correct 39 ms 9820 KB Output is correct
43 Correct 21 ms 9820 KB Output is correct
44 Correct 24 ms 9816 KB Output is correct
45 Correct 28 ms 9820 KB Output is correct
46 Correct 33 ms 9820 KB Output is correct
47 Correct 41 ms 9820 KB Output is correct
48 Correct 39 ms 9816 KB Output is correct
49 Correct 57 ms 10004 KB Output is correct
50 Correct 72 ms 9816 KB Output is correct
51 Correct 31 ms 10008 KB Output is correct
52 Correct 38 ms 9816 KB Output is correct
53 Correct 61 ms 10032 KB Output is correct
54 Correct 70 ms 10004 KB Output is correct
55 Execution timed out 2043 ms 17752 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 5 ms 9820 KB Output is correct
7 Correct 6 ms 9820 KB Output is correct
8 Correct 4 ms 9820 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 4 ms 9872 KB Output is correct
11 Correct 5 ms 9820 KB Output is correct
12 Correct 5 ms 9820 KB Output is correct
13 Correct 4 ms 9820 KB Output is correct
14 Correct 5 ms 9820 KB Output is correct
15 Correct 5 ms 9832 KB Output is correct
16 Correct 5 ms 9820 KB Output is correct
17 Correct 4 ms 9820 KB Output is correct
18 Correct 4 ms 9820 KB Output is correct
19 Correct 4 ms 9820 KB Output is correct
20 Correct 4 ms 9816 KB Output is correct
21 Correct 5 ms 9816 KB Output is correct
22 Correct 5 ms 10072 KB Output is correct
23 Correct 4 ms 9820 KB Output is correct
24 Correct 5 ms 9820 KB Output is correct
25 Correct 5 ms 9816 KB Output is correct
26 Correct 5 ms 9820 KB Output is correct
27 Correct 4 ms 9820 KB Output is correct
28 Correct 4 ms 9820 KB Output is correct
29 Correct 98 ms 9956 KB Output is correct
30 Correct 68 ms 9816 KB Output is correct
31 Correct 52 ms 9820 KB Output is correct
32 Correct 31 ms 10016 KB Output is correct
33 Correct 20 ms 9816 KB Output is correct
34 Correct 55 ms 9816 KB Output is correct
35 Correct 73 ms 9816 KB Output is correct
36 Correct 41 ms 9816 KB Output is correct
37 Correct 92 ms 9820 KB Output is correct
38 Correct 79 ms 9820 KB Output is correct
39 Correct 75 ms 9820 KB Output is correct
40 Correct 40 ms 9816 KB Output is correct
41 Correct 39 ms 9820 KB Output is correct
42 Correct 39 ms 9820 KB Output is correct
43 Correct 21 ms 9820 KB Output is correct
44 Correct 24 ms 9816 KB Output is correct
45 Correct 28 ms 9820 KB Output is correct
46 Correct 33 ms 9820 KB Output is correct
47 Correct 41 ms 9820 KB Output is correct
48 Correct 39 ms 9816 KB Output is correct
49 Correct 57 ms 10004 KB Output is correct
50 Correct 72 ms 9816 KB Output is correct
51 Correct 31 ms 10008 KB Output is correct
52 Correct 38 ms 9816 KB Output is correct
53 Correct 61 ms 10032 KB Output is correct
54 Correct 70 ms 10004 KB Output is correct
55 Correct 78 ms 30912 KB Output is correct
56 Correct 76 ms 32704 KB Output is correct
57 Correct 79 ms 32960 KB Output is correct
58 Correct 75 ms 31072 KB Output is correct
59 Correct 79 ms 30912 KB Output is correct
60 Correct 74 ms 29372 KB Output is correct
61 Correct 75 ms 30400 KB Output is correct
62 Correct 77 ms 32960 KB Output is correct
63 Correct 78 ms 30916 KB Output is correct
64 Correct 78 ms 33032 KB Output is correct
65 Correct 77 ms 28864 KB Output is correct
66 Correct 81 ms 29888 KB Output is correct
67 Correct 80 ms 31936 KB Output is correct
68 Correct 82 ms 33472 KB Output is correct
69 Correct 727 ms 31436 KB Output is correct
70 Correct 1012 ms 33580 KB Output is correct
71 Correct 1037 ms 33876 KB Output is correct
72 Correct 1041 ms 31572 KB Output is correct
73 Correct 1355 ms 31572 KB Output is correct
74 Correct 1519 ms 31240 KB Output is correct
75 Correct 1538 ms 33616 KB Output is correct
76 Correct 1255 ms 30992 KB Output is correct
77 Correct 1144 ms 32340 KB Output is correct
78 Correct 1095 ms 33872 KB Output is correct
79 Correct 1200 ms 29520 KB Output is correct
80 Correct 1472 ms 31056 KB Output is correct
81 Correct 1502 ms 32596 KB Output is correct
82 Correct 1475 ms 33968 KB Output is correct
83 Execution timed out 2043 ms 17752 KB Time limit exceeded
84 Halted 0 ms 0 KB -