Submission #1095116

# Submission time Handle Problem Language Result Execution time Memory
1095116 2024-10-01T10:04:37 Z simona1230 Joker (BOI20_joker) C++17
49 / 100
1288 ms 17888 KB
#include <bits/stdc++.h>
 
using namespace std;
struct query
{
    int l,r,i;
    query(){}
    query(int _l,int _r,int _i)
    {
        l=_l;
        r=_r;
        i=_i;
    }
};
 
struct edge
{
    int x,y;
    edge(){}
    edge(int _x,int _y)
    {
        x=_x;
        y=_y;
    }
};
 
int n,m,k;
query a[200001];
pair<int,int> e[200001],q[200001];
 
void read()
{
    cin>>n>>m>>k;
    for(int i=1;i<=m;i++)
    {
        int x,y;
        cin>>x>>y;
        e[i]={x,y};
    }
 
    for(int i=1;i<=k;i++)
    {
        int l,r;
        cin>>l>>r;
        q[i]={l,r};
        a[i]={l,r,i};
    }
}
 
int used[200001];
vector<int> v[200001];
bool pos;
 
void dfs(int i)
{
    for(int j=0;j<v[i].size();j++)
    {
        int nb=v[i][j];
        if(!used[nb])
        {
            used[nb]=1;
            if(used[i]==1)used[nb]=2;
 
            dfs(nb);
        }
        else if(used[i]==used[nb])pos=0;
    }
}
 
void slow()
{
    for(int i=1;i<=k;i++)
    {
        pos=1;
        for(int j=1;j<=n;j++)
        {
            used[j]=0;
            v[j].clear();
        }
 
        for(int j=1;j<q[i].first;j++)
        {
            v[e[j].first].push_back(e[j].second);
            v[e[j].second].push_back(e[j].first);
        }
 
        for(int j=q[i].second+1;j<=m;j++)
        {
            v[e[j].first].push_back(e[j].second);
            v[e[j].second].push_back(e[j].first);
        }
 
        for(int j=1;j<=n;j++)
        {
            if(!used[j])
            {
                used[j]=1;
                dfs(j);
            }
        }
 
        if(pos)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
}
 
 
int minr[200001];
int sz[200001];
pair<int,int> p[200001];
 
void init()
{
    pos=1;
    for(int i=1;i<=n;i++)
        p[i]={i,0},sz[i]=1;
}
 
pair<int,int> parent(int x)
{
    if(x==p[x].first)return p[x];
    int curr=p[x].second;
 
    p[x]=parent(p[x].first);
    p[x].second+=curr;
    return p[x];
}
 
void unite(int x,int y)
{
    pair<int,int> pxx=parent(x);
    pair<int,int> pyy=parent(y);
 
    int px=pxx.first;
    int py=pyy.first;
 
    if(px!=py)
    {
        if(sz[px]>sz[py])swap(px,py);
 
        p[px]={py,pxx.second+1+pyy.second};
        sz[py]+=sz[px];
    }
    else
    {
        //cout<<x<<" "<<y<<" "<<pxx.second<<" "<<pyy.second<<endl;
        if(pxx.second%2==pyy.second%2)
            pos=0;
    }
}
 
void subt()
{
    for(int i=1;i<=min(200,m);i++)
    {
        //cout<<i<<endl;
        init();
        for(int j=1;j<i;j++)
        {
            unite(e[j].first,e[j].second);
            if(pos==0)
            {
                //cout<<"in"<<" "<<i<<" "<<j<<endl;
                minr[i]=m+1;
                break;
            }
        }
        for(int j=m;j>i;j--)
        {
            unite(e[j].first,e[j].second);
            if(pos==0)
            {
                //cout<<"in"<<" "<<i<<" "<<j<<endl;
                minr[i]=max(minr[i],j);
                break;
            }
        }
    }
 
    for(int i=1;i<=k;i++)
    {
        if(minr[q[i].first]>q[i].second)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	read();
	if(n<=2000)slow();
	else subt();
	return 0;
}

Compilation message

Joker.cpp: In function 'void dfs(int)':
Joker.cpp:56:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     for(int j=0;j<v[i].size();j++)
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 3 ms 4956 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 3 ms 5136 KB Output is correct
15 Correct 4 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 ms 4956 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 3 ms 4956 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 3 ms 4956 KB Output is correct
23 Correct 3 ms 4956 KB Output is correct
24 Correct 3 ms 4956 KB Output is correct
25 Correct 3 ms 5040 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 5 ms 4956 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 3 ms 4956 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 3 ms 5136 KB Output is correct
15 Correct 4 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 ms 4956 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 3 ms 4956 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 3 ms 4956 KB Output is correct
23 Correct 3 ms 4956 KB Output is correct
24 Correct 3 ms 4956 KB Output is correct
25 Correct 3 ms 5040 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 5 ms 4956 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 44 ms 5212 KB Output is correct
30 Correct 84 ms 5208 KB Output is correct
31 Correct 90 ms 5208 KB Output is correct
32 Correct 72 ms 5212 KB Output is correct
33 Correct 60 ms 5212 KB Output is correct
34 Correct 89 ms 5212 KB Output is correct
35 Correct 93 ms 5212 KB Output is correct
36 Correct 41 ms 5212 KB Output is correct
37 Correct 65 ms 5212 KB Output is correct
38 Correct 57 ms 5208 KB Output is correct
39 Correct 64 ms 5208 KB Output is correct
40 Correct 68 ms 5208 KB Output is correct
41 Correct 68 ms 5208 KB Output is correct
42 Correct 66 ms 5212 KB Output is correct
43 Correct 59 ms 5208 KB Output is correct
44 Correct 74 ms 5208 KB Output is correct
45 Correct 78 ms 5212 KB Output is correct
46 Correct 80 ms 5212 KB Output is correct
47 Correct 62 ms 5212 KB Output is correct
48 Correct 69 ms 5208 KB Output is correct
49 Correct 76 ms 5208 KB Output is correct
50 Correct 85 ms 5212 KB Output is correct
51 Correct 63 ms 5344 KB Output is correct
52 Correct 73 ms 5328 KB Output is correct
53 Correct 80 ms 5212 KB Output is correct
54 Correct 93 ms 5212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 701 ms 15652 KB Output is correct
4 Correct 1281 ms 16464 KB Output is correct
5 Correct 329 ms 17488 KB Output is correct
6 Correct 306 ms 16344 KB Output is correct
7 Correct 306 ms 16420 KB Output is correct
8 Correct 453 ms 15324 KB Output is correct
9 Correct 485 ms 15868 KB Output is correct
10 Correct 779 ms 17236 KB Output is correct
11 Correct 719 ms 16312 KB Output is correct
12 Correct 723 ms 17488 KB Output is correct
13 Correct 588 ms 15276 KB Output is correct
14 Correct 464 ms 15912 KB Output is correct
15 Correct 659 ms 16816 KB Output is correct
16 Correct 763 ms 17488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 3 ms 4956 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 3 ms 5136 KB Output is correct
15 Correct 4 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 ms 4956 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 3 ms 4956 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 3 ms 4956 KB Output is correct
23 Correct 3 ms 4956 KB Output is correct
24 Correct 3 ms 4956 KB Output is correct
25 Correct 3 ms 5040 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 5 ms 4956 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 701 ms 15652 KB Output is correct
30 Correct 1281 ms 16464 KB Output is correct
31 Correct 329 ms 17488 KB Output is correct
32 Correct 306 ms 16344 KB Output is correct
33 Correct 306 ms 16420 KB Output is correct
34 Correct 453 ms 15324 KB Output is correct
35 Correct 485 ms 15868 KB Output is correct
36 Correct 779 ms 17236 KB Output is correct
37 Correct 719 ms 16312 KB Output is correct
38 Correct 723 ms 17488 KB Output is correct
39 Correct 588 ms 15276 KB Output is correct
40 Correct 464 ms 15912 KB Output is correct
41 Correct 659 ms 16816 KB Output is correct
42 Correct 763 ms 17488 KB Output is correct
43 Correct 680 ms 16548 KB Output is correct
44 Correct 1288 ms 17488 KB Output is correct
45 Correct 1172 ms 17888 KB Output is correct
46 Correct 296 ms 16688 KB Output is correct
47 Correct 284 ms 16720 KB Output is correct
48 Correct 538 ms 16208 KB Output is correct
49 Correct 782 ms 17792 KB Output is correct
50 Correct 789 ms 16360 KB Output is correct
51 Correct 748 ms 17232 KB Output is correct
52 Correct 704 ms 17744 KB Output is correct
53 Correct 504 ms 15440 KB Output is correct
54 Correct 508 ms 16464 KB Output is correct
55 Correct 652 ms 17352 KB Output is correct
56 Correct 772 ms 17884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 3 ms 4956 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 3 ms 5136 KB Output is correct
15 Correct 4 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 ms 4956 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 3 ms 4956 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 3 ms 4956 KB Output is correct
23 Correct 3 ms 4956 KB Output is correct
24 Correct 3 ms 4956 KB Output is correct
25 Correct 3 ms 5040 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 5 ms 4956 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 44 ms 5212 KB Output is correct
30 Correct 84 ms 5208 KB Output is correct
31 Correct 90 ms 5208 KB Output is correct
32 Correct 72 ms 5212 KB Output is correct
33 Correct 60 ms 5212 KB Output is correct
34 Correct 89 ms 5212 KB Output is correct
35 Correct 93 ms 5212 KB Output is correct
36 Correct 41 ms 5212 KB Output is correct
37 Correct 65 ms 5212 KB Output is correct
38 Correct 57 ms 5208 KB Output is correct
39 Correct 64 ms 5208 KB Output is correct
40 Correct 68 ms 5208 KB Output is correct
41 Correct 68 ms 5208 KB Output is correct
42 Correct 66 ms 5212 KB Output is correct
43 Correct 59 ms 5208 KB Output is correct
44 Correct 74 ms 5208 KB Output is correct
45 Correct 78 ms 5212 KB Output is correct
46 Correct 80 ms 5212 KB Output is correct
47 Correct 62 ms 5212 KB Output is correct
48 Correct 69 ms 5208 KB Output is correct
49 Correct 76 ms 5208 KB Output is correct
50 Correct 85 ms 5212 KB Output is correct
51 Correct 63 ms 5344 KB Output is correct
52 Correct 73 ms 5328 KB Output is correct
53 Correct 80 ms 5212 KB Output is correct
54 Correct 93 ms 5212 KB Output is correct
55 Incorrect 467 ms 10252 KB Output isn't correct
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 4956 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4956 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 3 ms 4956 KB Output is correct
13 Correct 3 ms 4956 KB Output is correct
14 Correct 3 ms 5136 KB Output is correct
15 Correct 4 ms 4956 KB Output is correct
16 Correct 3 ms 4956 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 3 ms 4956 KB Output is correct
19 Correct 3 ms 4956 KB Output is correct
20 Correct 3 ms 4956 KB Output is correct
21 Correct 3 ms 4956 KB Output is correct
22 Correct 3 ms 4956 KB Output is correct
23 Correct 3 ms 4956 KB Output is correct
24 Correct 3 ms 4956 KB Output is correct
25 Correct 3 ms 5040 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 5 ms 4956 KB Output is correct
28 Correct 3 ms 4956 KB Output is correct
29 Correct 44 ms 5212 KB Output is correct
30 Correct 84 ms 5208 KB Output is correct
31 Correct 90 ms 5208 KB Output is correct
32 Correct 72 ms 5212 KB Output is correct
33 Correct 60 ms 5212 KB Output is correct
34 Correct 89 ms 5212 KB Output is correct
35 Correct 93 ms 5212 KB Output is correct
36 Correct 41 ms 5212 KB Output is correct
37 Correct 65 ms 5212 KB Output is correct
38 Correct 57 ms 5208 KB Output is correct
39 Correct 64 ms 5208 KB Output is correct
40 Correct 68 ms 5208 KB Output is correct
41 Correct 68 ms 5208 KB Output is correct
42 Correct 66 ms 5212 KB Output is correct
43 Correct 59 ms 5208 KB Output is correct
44 Correct 74 ms 5208 KB Output is correct
45 Correct 78 ms 5212 KB Output is correct
46 Correct 80 ms 5212 KB Output is correct
47 Correct 62 ms 5212 KB Output is correct
48 Correct 69 ms 5208 KB Output is correct
49 Correct 76 ms 5208 KB Output is correct
50 Correct 85 ms 5212 KB Output is correct
51 Correct 63 ms 5344 KB Output is correct
52 Correct 73 ms 5328 KB Output is correct
53 Correct 80 ms 5212 KB Output is correct
54 Correct 93 ms 5212 KB Output is correct
55 Correct 701 ms 15652 KB Output is correct
56 Correct 1281 ms 16464 KB Output is correct
57 Correct 329 ms 17488 KB Output is correct
58 Correct 306 ms 16344 KB Output is correct
59 Correct 306 ms 16420 KB Output is correct
60 Correct 453 ms 15324 KB Output is correct
61 Correct 485 ms 15868 KB Output is correct
62 Correct 779 ms 17236 KB Output is correct
63 Correct 719 ms 16312 KB Output is correct
64 Correct 723 ms 17488 KB Output is correct
65 Correct 588 ms 15276 KB Output is correct
66 Correct 464 ms 15912 KB Output is correct
67 Correct 659 ms 16816 KB Output is correct
68 Correct 763 ms 17488 KB Output is correct
69 Correct 680 ms 16548 KB Output is correct
70 Correct 1288 ms 17488 KB Output is correct
71 Correct 1172 ms 17888 KB Output is correct
72 Correct 296 ms 16688 KB Output is correct
73 Correct 284 ms 16720 KB Output is correct
74 Correct 538 ms 16208 KB Output is correct
75 Correct 782 ms 17792 KB Output is correct
76 Correct 789 ms 16360 KB Output is correct
77 Correct 748 ms 17232 KB Output is correct
78 Correct 704 ms 17744 KB Output is correct
79 Correct 504 ms 15440 KB Output is correct
80 Correct 508 ms 16464 KB Output is correct
81 Correct 652 ms 17352 KB Output is correct
82 Correct 772 ms 17884 KB Output is correct
83 Incorrect 467 ms 10252 KB Output isn't correct
84 Halted 0 ms 0 KB -