1015A - Points in Segments - CodeForces Solution


implementation *800

Please click on ads to support us..

Python Code:

n,m = map(int,input().split())
x = []
l1 = []
t1 = []
for i in range(n):
    l, t = map(int, input().split())
    l1.append(l)
    l1.append(t)
    j = l
    while j < t:
        j+=1
        l1.append(j)
for k in range(1, m+1):
    if k not in l1:
        x.append(k)
count = len(x)
print(count)
print(*x)

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define AM17 ios_base::sync_with_stdio(false),cin.tie(NULL);
#define yes cout<<"YES\n";
#define no cout<<"NO\n";

#define lenSorts(s) sort(s.begin(), s.end(), [&] (const string &s, const string &t) { return s.size() < t.size();});
int dx4[4] = { -1, 0, 1, 0 };
int dy4[4] = { 0, 1, 0, -1 };
int dx8[] = {+0, +0, -1, +1, +1, +1, -1, -1};
int dy8[] = {-1, +1, +0, +0, +1, -1, +1, -1};
string Dir = "URDL";
template <class T>
istream & operator>> (istream&is , vector<T> &v )
{
    for (auto &i:v)
        is>> i ;
    return is ;
}
template <class T>
ostream & operator<< (ostream&os ,const vector<T> &v )
{
    for (auto &i:v)
        os << i << " " ;
    os << '\n' ;
    return os ;
}
//ll fastpow(ll a,ll p)
//{
//    if(p==0)
//        return 1ll;
//
//    if(p&1)
//        return ((a%MOD) * fastpow(a,p-1))%MOD;
//    else
//    {
//        ll ret=(fastpow(a,p/2));
//        return ((ret%MOD) * (ret%MOD))%MOD;
//    }
//}
//
////ll w[N];

struct DSU{
//    vector<ll>cost;
    vector<int>parent;
    vector<int>sz;
    ll cost=0;
    DSU(int n)
    {
        sz.resize(n+1);
        parent.resize(n+1);
        for (int i = 0; i <= n ; ++i) {
            parent[i]=i;
            sz[i]=1;
        }
    }
    int find(int node)
    {

        if(parent[node]==node)
            return parent[node];
        return parent[node]= find(parent[node]);
    }
    bool add(int a,int b,int cost)
    {
        a= find(a);
        b= find(b);
        if(a==b)
            return false;
        if(sz[a]<sz[b])
        { swap(a,b);}
        parent[b]=a;
        sz[a]+=sz[b];
//        parent[a]=parent[b];
        this->cost+=cost;
        return true;
    }
    bool all(int n)
    {
        int cnt=0;
        for (int i = 1; i <=n ; ++i) {
            cnt+=(parent[i]==i);
        }
        return cnt==1;
    }
};
const int N=1005,M=1e5+10;
const int Mod=1e9+7;
vector<int>w,c;
int n,m;

int main()
{
    int loop=1;
//    cin>>loop;
    while (loop--)
    {
        int m;
        cin>>n>>m;
        vector<int>v(m+1);
        for (int i = 0; i < n; ++i) {
            int x,y;
            cin>>x>>y;
            for (int j = x; j <=y ; ++j) {
                v[j]=1;

            }
        }
        vector<int>ans;
        for (int i = 1; i <=m ; ++i) {
            if(!v[i])
                ans.push_back(i);
        }
        cout<<ans.size()<<endl<<ans;
    }
}


Comments

Submit
0 Comments
More Questions

1722D - Line
1722C - Word Game
1722G - Even-Odd XOR
552E - Vanya and Brackets
933A - A Twisty Movement
1722F - L-shapes
1196B - Odd Sum Segments
1325D - Ehab the Xorcist
552B - Vanya and Books
1722E - Counting Rectangles
168A - Wizards and Demonstration
168B - Wizards and Minimal Spell
7A - Kalevitch and Chess
912B - New Year's Eve
1537C - Challenging Cliffs
879B - Table Tennis
1674E - Breaking the Wall
1282A - Temporarily unavailable
1366C - Palindromic Paths
336A - Vasily the Bear and Triangle
926A - 2-3-numbers
276D - Little Girl and Maximum XOR
1253C - Sweets Eating
1047A - Little C Loves 3 I
758D - Ability To Convert
733A - Grasshopper And the String
216A - Tiling with Hexagons
1351B - Square
1225A - Forgetting Things
1717A - Madoka and Strange Thoughts