Submission #252064

# Submission time Handle Problem Language Result Execution time Memory
252064 2020-07-24T05:39:33 Z jeqcho Strange Device (APIO19_strange_device) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpi;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define pb push_back
#define rsz resize
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define f first
#define s second

// solved subtask 4 and 5

ll A,B;

ll gcd(ll a, ll b)
{
    // O((log n)^2)
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n>>A>>B;
    ll l,r;
    ll q = A / gcd(A,B+1);
    ll maxlen = q*B;
    vector<pair<ll,ll>> segments;
    F0R(i,n)
    {
        cin>>l>>r;
        if(r-l+1 >= maxlen)
        {
            FOR(j,i+1,n)cin>>l>>r;
            cout<<maxlen<<endl;
            return 0;
        }
        l %= maxlen;
        r %= maxlen;
        if(r<l)
        {
            segments.pb({(0,r});
            segments.pb({l,maxlen-(ll)1});
        }
        else segments.pb({l,r});
    }
    sort(all(segments));
    bool init=0;
    ll ldex,rdex;
    ll ans=0;
    pair<ll,ll> seg;
    F0R(i,sz(segments)+1)
    {
        if(i==sz(segments))
        {
            ans += rdex-ldex+(ll)1;
            break;
        }
        seg = segments[i];
        if(!init)
        {
            ldex=seg.f;
            rdex=seg.s;
            init=1;
        }
        else if(seg.f==ldex)
        {
            rdex = seg.s;
        }
        else
        {
            // seg.f > ldex
            if(seg.f <= rdex)
            {
                rdex = max(rdex,seg.s);
            }
            else
            {
                ans += rdex-ldex+(ll)1;
                ldex=seg.f;
                rdex=seg.s;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:56:29: warning: left operand of comma operator has no effect [-Wunused-value]
             segments.pb({(0,r});
                             ^
strange_device.cpp:56:30: error: expected ')' before '}' token
             segments.pb({(0,r});
                              ^
strange_device.cpp:56:31: error: no matching function for call to 'std::vector<std::pair<long long int, long long int> >::push_back(<brace-enclosed initializer list>)'
             segments.pb({(0,r});
                               ^
In file included from /usr/include/c++/7/vector:64:0,
                 from /usr/include/c++/7/functional:61,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from strange_device.cpp:1:
/usr/include/c++/7/bits/stl_vector.h:939:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<long long int, long long int>]
       push_back(const value_type& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:939:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type& {aka const std::pair<long long int, long long int>&}'
/usr/include/c++/7/bits/stl_vector.h:953:7: note: candidate: void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<long long int, long long int>; _Alloc = std::allocator<std::pair<long long int, long long int> >; std::vector<_Tp, _Alloc>::value_type = std::pair<long long int, long long int>]
       push_back(value_type&& __x)
       ^~~~~~~~~
/usr/include/c++/7/bits/stl_vector.h:953:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<long long int, long long int> >::value_type&& {aka std::pair<long long int, long long int>&&}'