Submission #930553

# Submission time Handle Problem Language Result Execution time Memory
930553 2024-02-20T06:29:09 Z Faisal_Saqib Joker (BOI20_joker) C++17
39 / 100
2000 ms 19384 KB
#include <bits/stdc++.h>
using namespace std;
const int M=2e5+1;
int n,m,q;
bool mark[M],vis[M];
int val[M];
vector<pair<int,int>> ma[M],query;
map<int,int> mx_r_for_l;
bool found=0;
void dfs(int x)
{
    vis[x]=1;
    for(auto [y,ind]:ma[x])
    {
        if(mark[ind])
            continue;
        if(!vis[y])
        {
            val[y]=(val[x]+1)%2;
            dfs(y);
        }
        else if((val[y]+1)%2!=val[x])
        {
            found=1;
        }
    }
}
bool check(int l,int r)
{
    // cout<<"Check "<<l<<' '<<r<<endl;
    for(int i=1;i<=n;i++)
        vis[i]=0;
    for(int i=0;i<m;i++)
        mark[i]=(l<=i and i<=r);
    found=0;
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            dfs(i);
        }
    }
    // cout<<"Answer "<<found<<endl;
    return found;
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
 
    cin>>n>>m>>q;
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        // cout<<i+1<<"th edge is "<<a<<' '<<b<<endl;
        ma[a].push_back({b,i});
        ma[b].push_back({a,i});
    }
    vector<int> difl={-1};
    for(int lp=0;lp<q;lp++)
    {
        int l,r;
        cin>>l>>r;
        l--;
        r--;
        query.push_back({l,r});
        difl.push_back(l);
    }
    sort(begin(difl),end(difl));
	  int p=-1;
    for(int i=1;i<difl.size();i++)
    {
        if(difl[i-1]!=difl[i])
        {
            int l=difl[i];
            int sr=max(p,l-1);
            int er=m;
            // cout<<"Solve "<<l<<endl;
            while(sr+1<er)
            {
                int mid=(sr+er)/2;
                if(check(l,mid))
                {
                    //is there is odd cycle then we have to remove more edge 
                    sr=mid;
                }
                else{
                    er=mid;
                }
            }
            // cout<<"mx r"<<sr<<endl;
            mx_r_for_l[l]=sr;
	          p=max(p,sr);
        }
    }
    for(auto [l,r]:query)
    {
        if(mx_r_for_l[l]>=r)
        {
            cout<<"YES"<<'\n';
        }
        else{
            cout<<"NO"<<'\n';
        }
    }
    return 0;
}

Compilation message

Joker.cpp: In function 'int main()':
Joker.cpp:73:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     for(int i=1;i<difl.size();i++)
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4964 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 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 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 3 ms 4956 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 2 ms 4952 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 2 ms 4964 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4960 KB Output is correct
28 Correct 2 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4964 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 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 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 3 ms 4956 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 2 ms 4952 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 2 ms 4964 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4960 KB Output is correct
28 Correct 2 ms 4956 KB Output is correct
29 Correct 131 ms 5468 KB Output is correct
30 Correct 142 ms 5208 KB Output is correct
31 Correct 110 ms 5252 KB Output is correct
32 Correct 47 ms 5212 KB Output is correct
33 Correct 14 ms 5212 KB Output is correct
34 Correct 101 ms 5412 KB Output is correct
35 Correct 180 ms 5208 KB Output is correct
36 Correct 70 ms 5212 KB Output is correct
37 Correct 133 ms 5212 KB Output is correct
38 Correct 250 ms 5300 KB Output is correct
39 Correct 68 ms 5208 KB Output is correct
40 Correct 42 ms 5212 KB Output is correct
41 Correct 35 ms 5288 KB Output is correct
42 Correct 34 ms 5212 KB Output is correct
43 Correct 30 ms 5296 KB Output is correct
44 Correct 53 ms 5208 KB Output is correct
45 Correct 72 ms 5288 KB Output is correct
46 Correct 166 ms 5280 KB Output is correct
47 Correct 62 ms 5284 KB Output is correct
48 Correct 74 ms 5280 KB Output is correct
49 Correct 98 ms 5268 KB Output is correct
50 Correct 122 ms 5212 KB Output is correct
51 Correct 34 ms 5460 KB Output is correct
52 Correct 54 ms 5284 KB Output is correct
53 Correct 87 ms 5208 KB Output is correct
54 Correct 161 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 171 ms 18072 KB Output is correct
4 Correct 201 ms 18612 KB Output is correct
5 Correct 161 ms 17484 KB Output is correct
6 Correct 189 ms 18160 KB Output is correct
7 Correct 180 ms 17844 KB Output is correct
8 Correct 179 ms 17256 KB Output is correct
9 Correct 235 ms 18616 KB Output is correct
10 Correct 279 ms 18104 KB Output is correct
11 Correct 186 ms 17256 KB Output is correct
12 Correct 229 ms 17548 KB Output is correct
13 Correct 128 ms 14948 KB Output is correct
14 Correct 176 ms 17080 KB Output is correct
15 Correct 241 ms 18344 KB Output is correct
16 Correct 269 ms 17852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4964 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 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 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 3 ms 4956 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 2 ms 4952 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 2 ms 4964 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4960 KB Output is correct
28 Correct 2 ms 4956 KB Output is correct
29 Correct 171 ms 18072 KB Output is correct
30 Correct 201 ms 18612 KB Output is correct
31 Correct 161 ms 17484 KB Output is correct
32 Correct 189 ms 18160 KB Output is correct
33 Correct 180 ms 17844 KB Output is correct
34 Correct 179 ms 17256 KB Output is correct
35 Correct 235 ms 18616 KB Output is correct
36 Correct 279 ms 18104 KB Output is correct
37 Correct 186 ms 17256 KB Output is correct
38 Correct 229 ms 17548 KB Output is correct
39 Correct 128 ms 14948 KB Output is correct
40 Correct 176 ms 17080 KB Output is correct
41 Correct 241 ms 18344 KB Output is correct
42 Correct 269 ms 17852 KB Output is correct
43 Execution timed out 2047 ms 19384 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4964 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 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 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 3 ms 4956 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 2 ms 4952 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 2 ms 4964 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4960 KB Output is correct
28 Correct 2 ms 4956 KB Output is correct
29 Correct 131 ms 5468 KB Output is correct
30 Correct 142 ms 5208 KB Output is correct
31 Correct 110 ms 5252 KB Output is correct
32 Correct 47 ms 5212 KB Output is correct
33 Correct 14 ms 5212 KB Output is correct
34 Correct 101 ms 5412 KB Output is correct
35 Correct 180 ms 5208 KB Output is correct
36 Correct 70 ms 5212 KB Output is correct
37 Correct 133 ms 5212 KB Output is correct
38 Correct 250 ms 5300 KB Output is correct
39 Correct 68 ms 5208 KB Output is correct
40 Correct 42 ms 5212 KB Output is correct
41 Correct 35 ms 5288 KB Output is correct
42 Correct 34 ms 5212 KB Output is correct
43 Correct 30 ms 5296 KB Output is correct
44 Correct 53 ms 5208 KB Output is correct
45 Correct 72 ms 5288 KB Output is correct
46 Correct 166 ms 5280 KB Output is correct
47 Correct 62 ms 5284 KB Output is correct
48 Correct 74 ms 5280 KB Output is correct
49 Correct 98 ms 5268 KB Output is correct
50 Correct 122 ms 5212 KB Output is correct
51 Correct 34 ms 5460 KB Output is correct
52 Correct 54 ms 5284 KB Output is correct
53 Correct 87 ms 5208 KB Output is correct
54 Correct 161 ms 5208 KB Output is correct
55 Execution timed out 2029 ms 13904 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4964 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 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 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 3 ms 4956 KB Output is correct
15 Correct 3 ms 4956 KB Output is correct
16 Correct 2 ms 4952 KB Output is correct
17 Correct 2 ms 4952 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4952 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 2 ms 4964 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4960 KB Output is correct
28 Correct 2 ms 4956 KB Output is correct
29 Correct 131 ms 5468 KB Output is correct
30 Correct 142 ms 5208 KB Output is correct
31 Correct 110 ms 5252 KB Output is correct
32 Correct 47 ms 5212 KB Output is correct
33 Correct 14 ms 5212 KB Output is correct
34 Correct 101 ms 5412 KB Output is correct
35 Correct 180 ms 5208 KB Output is correct
36 Correct 70 ms 5212 KB Output is correct
37 Correct 133 ms 5212 KB Output is correct
38 Correct 250 ms 5300 KB Output is correct
39 Correct 68 ms 5208 KB Output is correct
40 Correct 42 ms 5212 KB Output is correct
41 Correct 35 ms 5288 KB Output is correct
42 Correct 34 ms 5212 KB Output is correct
43 Correct 30 ms 5296 KB Output is correct
44 Correct 53 ms 5208 KB Output is correct
45 Correct 72 ms 5288 KB Output is correct
46 Correct 166 ms 5280 KB Output is correct
47 Correct 62 ms 5284 KB Output is correct
48 Correct 74 ms 5280 KB Output is correct
49 Correct 98 ms 5268 KB Output is correct
50 Correct 122 ms 5212 KB Output is correct
51 Correct 34 ms 5460 KB Output is correct
52 Correct 54 ms 5284 KB Output is correct
53 Correct 87 ms 5208 KB Output is correct
54 Correct 161 ms 5208 KB Output is correct
55 Correct 171 ms 18072 KB Output is correct
56 Correct 201 ms 18612 KB Output is correct
57 Correct 161 ms 17484 KB Output is correct
58 Correct 189 ms 18160 KB Output is correct
59 Correct 180 ms 17844 KB Output is correct
60 Correct 179 ms 17256 KB Output is correct
61 Correct 235 ms 18616 KB Output is correct
62 Correct 279 ms 18104 KB Output is correct
63 Correct 186 ms 17256 KB Output is correct
64 Correct 229 ms 17548 KB Output is correct
65 Correct 128 ms 14948 KB Output is correct
66 Correct 176 ms 17080 KB Output is correct
67 Correct 241 ms 18344 KB Output is correct
68 Correct 269 ms 17852 KB Output is correct
69 Execution timed out 2047 ms 19384 KB Time limit exceeded
70 Halted 0 ms 0 KB -