Submission #930550

# Submission time Handle Problem Language Result Execution time Memory
930550 2024-02-20T06:10:02 Z Faisal_Saqib Joker (BOI20_joker) C++17
39 / 100
2000 ms 19132 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));
    for(int i=1;i<difl.size();i++)
    {
        if(difl[i-1]!=difl[i])
        {
            int l=difl[i];
            int sr=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;
        }
    }
    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:72:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |     for(int i=1;i<difl.size();i++)
      |                 ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 1 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 3 ms 4952 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4952 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 4 ms 4960 KB Output is correct
13 Correct 4 ms 4956 KB Output is correct
14 Correct 3 ms 4960 KB Output is correct
15 Correct 3 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 5044 KB Output is correct
25 Correct 3 ms 4952 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 3 ms 5184 KB Output is correct
28 Correct 3 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 1 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 3 ms 4952 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4952 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 4 ms 4960 KB Output is correct
13 Correct 4 ms 4956 KB Output is correct
14 Correct 3 ms 4960 KB Output is correct
15 Correct 3 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 5044 KB Output is correct
25 Correct 3 ms 4952 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 3 ms 5184 KB Output is correct
28 Correct 3 ms 4952 KB Output is correct
29 Correct 131 ms 5240 KB Output is correct
30 Correct 341 ms 5208 KB Output is correct
31 Correct 400 ms 5528 KB Output is correct
32 Correct 333 ms 5316 KB Output is correct
33 Correct 290 ms 5780 KB Output is correct
34 Correct 415 ms 5208 KB Output is correct
35 Correct 429 ms 5460 KB Output is correct
36 Correct 163 ms 5208 KB Output is correct
37 Correct 270 ms 5368 KB Output is correct
38 Correct 247 ms 5208 KB Output is correct
39 Correct 301 ms 5300 KB Output is correct
40 Correct 300 ms 5304 KB Output is correct
41 Correct 320 ms 5464 KB Output is correct
42 Correct 311 ms 5720 KB Output is correct
43 Correct 281 ms 5272 KB Output is correct
44 Correct 377 ms 5540 KB Output is correct
45 Correct 398 ms 5292 KB Output is correct
46 Correct 427 ms 5540 KB Output is correct
47 Correct 252 ms 5212 KB Output is correct
48 Correct 279 ms 5212 KB Output is correct
49 Correct 318 ms 5272 KB Output is correct
50 Correct 340 ms 5212 KB Output is correct
51 Correct 310 ms 5324 KB Output is correct
52 Correct 345 ms 5284 KB Output is correct
53 Correct 385 ms 5456 KB Output is correct
54 Correct 431 ms 5288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 135 ms 17924 KB Output is correct
4 Correct 192 ms 18648 KB Output is correct
5 Correct 173 ms 17612 KB Output is correct
6 Correct 185 ms 18184 KB Output is correct
7 Correct 191 ms 17844 KB Output is correct
8 Correct 167 ms 17080 KB Output is correct
9 Correct 198 ms 18328 KB Output is correct
10 Correct 319 ms 18044 KB Output is correct
11 Correct 182 ms 17256 KB Output is correct
12 Correct 200 ms 17396 KB Output is correct
13 Correct 130 ms 15032 KB Output is correct
14 Correct 209 ms 17028 KB Output is correct
15 Correct 212 ms 18380 KB Output is correct
16 Correct 261 ms 17852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 1 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 3 ms 4952 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4952 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 4 ms 4960 KB Output is correct
13 Correct 4 ms 4956 KB Output is correct
14 Correct 3 ms 4960 KB Output is correct
15 Correct 3 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 5044 KB Output is correct
25 Correct 3 ms 4952 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 3 ms 5184 KB Output is correct
28 Correct 3 ms 4952 KB Output is correct
29 Correct 135 ms 17924 KB Output is correct
30 Correct 192 ms 18648 KB Output is correct
31 Correct 173 ms 17612 KB Output is correct
32 Correct 185 ms 18184 KB Output is correct
33 Correct 191 ms 17844 KB Output is correct
34 Correct 167 ms 17080 KB Output is correct
35 Correct 198 ms 18328 KB Output is correct
36 Correct 319 ms 18044 KB Output is correct
37 Correct 182 ms 17256 KB Output is correct
38 Correct 200 ms 17396 KB Output is correct
39 Correct 130 ms 15032 KB Output is correct
40 Correct 209 ms 17028 KB Output is correct
41 Correct 212 ms 18380 KB Output is correct
42 Correct 261 ms 17852 KB Output is correct
43 Execution timed out 2051 ms 19132 KB Time limit exceeded
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 1 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 3 ms 4952 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4952 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 4 ms 4960 KB Output is correct
13 Correct 4 ms 4956 KB Output is correct
14 Correct 3 ms 4960 KB Output is correct
15 Correct 3 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 5044 KB Output is correct
25 Correct 3 ms 4952 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 3 ms 5184 KB Output is correct
28 Correct 3 ms 4952 KB Output is correct
29 Correct 131 ms 5240 KB Output is correct
30 Correct 341 ms 5208 KB Output is correct
31 Correct 400 ms 5528 KB Output is correct
32 Correct 333 ms 5316 KB Output is correct
33 Correct 290 ms 5780 KB Output is correct
34 Correct 415 ms 5208 KB Output is correct
35 Correct 429 ms 5460 KB Output is correct
36 Correct 163 ms 5208 KB Output is correct
37 Correct 270 ms 5368 KB Output is correct
38 Correct 247 ms 5208 KB Output is correct
39 Correct 301 ms 5300 KB Output is correct
40 Correct 300 ms 5304 KB Output is correct
41 Correct 320 ms 5464 KB Output is correct
42 Correct 311 ms 5720 KB Output is correct
43 Correct 281 ms 5272 KB Output is correct
44 Correct 377 ms 5540 KB Output is correct
45 Correct 398 ms 5292 KB Output is correct
46 Correct 427 ms 5540 KB Output is correct
47 Correct 252 ms 5212 KB Output is correct
48 Correct 279 ms 5212 KB Output is correct
49 Correct 318 ms 5272 KB Output is correct
50 Correct 340 ms 5212 KB Output is correct
51 Correct 310 ms 5324 KB Output is correct
52 Correct 345 ms 5284 KB Output is correct
53 Correct 385 ms 5456 KB Output is correct
54 Correct 431 ms 5288 KB Output is correct
55 Execution timed out 2051 ms 13908 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 1 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 3 ms 4952 KB Output is correct
9 Correct 3 ms 4956 KB Output is correct
10 Correct 3 ms 4952 KB Output is correct
11 Correct 3 ms 4956 KB Output is correct
12 Correct 4 ms 4960 KB Output is correct
13 Correct 4 ms 4956 KB Output is correct
14 Correct 3 ms 4960 KB Output is correct
15 Correct 3 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 5044 KB Output is correct
25 Correct 3 ms 4952 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 3 ms 5184 KB Output is correct
28 Correct 3 ms 4952 KB Output is correct
29 Correct 131 ms 5240 KB Output is correct
30 Correct 341 ms 5208 KB Output is correct
31 Correct 400 ms 5528 KB Output is correct
32 Correct 333 ms 5316 KB Output is correct
33 Correct 290 ms 5780 KB Output is correct
34 Correct 415 ms 5208 KB Output is correct
35 Correct 429 ms 5460 KB Output is correct
36 Correct 163 ms 5208 KB Output is correct
37 Correct 270 ms 5368 KB Output is correct
38 Correct 247 ms 5208 KB Output is correct
39 Correct 301 ms 5300 KB Output is correct
40 Correct 300 ms 5304 KB Output is correct
41 Correct 320 ms 5464 KB Output is correct
42 Correct 311 ms 5720 KB Output is correct
43 Correct 281 ms 5272 KB Output is correct
44 Correct 377 ms 5540 KB Output is correct
45 Correct 398 ms 5292 KB Output is correct
46 Correct 427 ms 5540 KB Output is correct
47 Correct 252 ms 5212 KB Output is correct
48 Correct 279 ms 5212 KB Output is correct
49 Correct 318 ms 5272 KB Output is correct
50 Correct 340 ms 5212 KB Output is correct
51 Correct 310 ms 5324 KB Output is correct
52 Correct 345 ms 5284 KB Output is correct
53 Correct 385 ms 5456 KB Output is correct
54 Correct 431 ms 5288 KB Output is correct
55 Correct 135 ms 17924 KB Output is correct
56 Correct 192 ms 18648 KB Output is correct
57 Correct 173 ms 17612 KB Output is correct
58 Correct 185 ms 18184 KB Output is correct
59 Correct 191 ms 17844 KB Output is correct
60 Correct 167 ms 17080 KB Output is correct
61 Correct 198 ms 18328 KB Output is correct
62 Correct 319 ms 18044 KB Output is correct
63 Correct 182 ms 17256 KB Output is correct
64 Correct 200 ms 17396 KB Output is correct
65 Correct 130 ms 15032 KB Output is correct
66 Correct 209 ms 17028 KB Output is correct
67 Correct 212 ms 18380 KB Output is correct
68 Correct 261 ms 17852 KB Output is correct
69 Execution timed out 2051 ms 19132 KB Time limit exceeded
70 Halted 0 ms 0 KB -